tags:

views:

45

answers:

3

Hi,

I want to fixe a height for my html table in the web page and if it pass the height automatically a vertical scrolling bar is shown.

please help.

+1  A: 

you can apply a css to your table as


table style='height:100px;overflow:auto;'

sushil bharwani
+1 - yes, or using an equivalent rule in CSS: `.scrollableTable { height:100px; overflow:auto; }`
ANeves
@sushil this does not work and @ANeves What's up with you commenting in every post without any relevant cause, first try the code and then only vote it up. Because I am writing this comment after checking @sushil's code unlike you
Starx
yes i realized my mistake that the style should have been applied on the covering div; but since i had used it many times i didn't checked the code. Well rest of the answers are perfect.
sushil bharwani
+4  A: 

It's not the table that scrolls, it is the div behind it.

<div height="200px; overflow-y: scroll;">
  <table>
   ....
  </table>
</div>

use overflow-y if you only want a vertical scroll bar and overflow if you want both a vertical and horizontal.

Note: setting an overflow attribute to scroll will always display the scrollbars. If you want the horizontal/vertical scrollbars to only show up when needed, use auto.

Robert Greiner
What's the div for? Why don't you merely scroll the table?
ANeves
+1 for a more complete answer than mine.
Tejs
+2  A: 

You'd want to place the table inside of a div like so:

<div style="height: 400px; overflow: auto;">
    <!-- Html Elements --!>
</div>

Anything inside that div, when it goes over 400px in height, will overflow and a scrollbar will be shown.

Tejs
What's the div for? Why don't you merely scroll the table?
ANeves