Html+css a table that can be browsed

Source: Internet
Author: User

Now the table content needs to display the following requirements:

1, the table is large, the interface is not small, you need to put in the Div.

2, in the Div can be viewed with scroll slide.

3, the contents of TD are kept in one line.

4, you can click on the TR, then you can select and understand which line is clicked.

Html:

<div id= "Div1" >

<table id= "Table1" >

<tr></tr>

</table>

<div>

Css:

The div width is smaller than table and there is scroll.
#table1 {border-collapse:collapse;height:100;}
#table1 table, Th, TD {Border:1px solid black;}
#table1 td{
width:230px; /* Width is set as needed, or set to percent/
height:25px;line-height:25px; /* height is also set as required */
White-space:nowrap; /* Text display does not wrap */
/*overflow:hidden;*//* Out-of-section display */
}
#div1 {border:1px solid red;width:460; height:180px;overflow:scroll;}

Js:

Add a onmousedown event handler to the click.
var trs = document.getElementById (' table1 '). getElementsByTagName (' tr ');
var choose;
Window.onload = function () {
for (var i=0; i<trs.length; i++) {
Trs[i].onmousedown = function () {
Tronmousedown (this);
}
}
}
function Tronmousedown (obj) {
for (var o=1; o<trs.length; o++) {
if (trs[o] = = obj) {
Trs[o].style.backgroundcolor = ' lightblue ';
choose = O;
}
else{
Trs[o].style.backgroundcolor = ";
}
}
}

Can communicate with each other.

Html+css a table that can be browsed

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.