Hi,
I have a table in which the number of columns can vary dynamically. If the the number of columns exceed a particular limit, I want the table to scroll horizontally. I have wrapped this table inside a div having a fixed width and overflow set to auto. But if I increase the number of columns, this div doesn't produce horizontal scroll. Instead the table is confining itself to the div by adjusting its column widths. (For convenience I have used inline styles).
Please check the sample code below.
<div style="width:750px;height:400px;overflow:auto;">
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<th style="width:60px"> </th>
<th style="text-align:center;width:100px;">P1</th>
<th style="text-align:center;width:100px;">P2</th>
<th style="text-align:center;width:100px;">P3</th>
<th style="text-align:center;width:100px;">P4</th>
<th style="text-align:center;width:100px;">P5</th>
<th style="text-align:center;width:100px;">P6</th>
<th style="text-align:center;width:100px;">P7</th>
<th style="text-align:center;width:100px;"> </th>
<th style="text-align:center;width:100px;"> </th>
<th style="text-align:center;width:100px;"> </th>
</tr>
<tr>
<th> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</div>
While checking the code above we can see that the div's width is only 750px, but the table's width is more than 1000px. I expected a horizontal scroll in the div. But it's not happening. Instead this table adjusts itself to the width of the div and no horizontal scroll takes place. Please help








Bookmarks