Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make TBODY scrollable in Webkit browsers

Tags:

html

css

webkit

I'm aware of this question, but none of the answers work in Safari, Chrome, etc.

The accepted strategy (as demonstrated here) is to set the tbody height and overflow properties like so:

<table>     <thead>         <tr><th>This is the header and doesn't scroll</th></tr>     </thead>     <tbody style="height:100px; overflow:auto;">         <tr><td>content that scrolls</td></tr>         <tr><td>content that scrolls</td></tr>         <tr><td>content that scrolls</td></tr>         <tr><td>content that scrolls</td></tr>         <tr><td>content that scrolls</td></tr>         <tr><td>content that scrolls</td></tr>         <tr><td>content that scrolls</td></tr>     </tbody> </table> 

Unfortunately, this does not work in any webkit browsers. There is a bug report about it that doesn't seem to be a high priority (reported June 05).

So my question is: are there alternate strategies that do actually work? I've tried the two-table approach, but it's impossible to guarantee that the header will line up with the content. Do I just have to wait for Webkit to fix it?

like image 479
Andrew Ensley Avatar asked Jun 19 '09 20:06

Andrew Ensley


People also ask

How do I make my Tbody scrollable?

If you want tbody to show a scrollbar, set its display: block; . Set display: table; for the tr so that it keeps the behavior of a table. To evenly spread the cells, use table-layout: fixed; . Anyhow, to set a scrollbar, a display reset is needed to get rid of the table-layout (which will never show scrollbar).

How do I make my table body scrollable in HTML?

We set the height of the table element to 120px to make restrict the height of it so we can make it scrollable. To make it scrollable, we set the overflow CSS property to scroll . Then we set the tr elements in the thead to absolute position so they stay in place.

How do I create a scrollable Web page?

For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.

How do I add a vertical scrollbar to a table?

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 .


1 Answers

Here is a working example:

http://www.imaputz.com/cssStuff/bigFourVersion.html

You have to add the display:block to the thead > tr and tbody

like image 85
Michael Koper Avatar answered Sep 19 '22 06:09

Michael Koper