Reputation: 24572
I have the following HTML that I am using with browser as new as IE8 and above:
<div><table class="grid table">
and .css file:
.grid {
clear: both;
border-collapse: collapse;
border-spacing: 0;
width: 100%;
}
This works but when my table is larger than the containing DIV then it goes offscreen.
How can I make it so a scroll bar allows me to scroll my table to the right and left if it is too big for the screen?
Upvotes: 0
Views: 99
Reputation: 2102
The easiest way is to add the overflow attribute to the surrounding div. The documentation is here for that.
Upvotes: 1
Reputation: 99484
Add an overflow: auto;
CSS declaration to the div
element.
CSS:
.box {
height: 150px;
border: 1px solid black; /* Just for demo */
overflow: auto;
}
HTML:
<div class="box">
<table>
<tr>
<td>Cell #1</td>
<td>Cell #2</td>
<td>Cell #3</td>
<td>Cell #4</td>
<td>Cell #5</td>
</tr>
<!-- so on... -->
</table>
</div>
If you need only horizontally scroll, use overflow-x: auto;
instead.
Upvotes: 4
Reputation: 24703
Add overflow-y:auto;
DEMO http://jsfiddle.net/kevinPHPkevin/SHbnM/
div {
overflow-y:auto;
height:100px;
}
Upvotes: 1