Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make html table vertically scrollable

Tags:

html

jquery

css

see jsbin

I have to make my html table vertically scrollable.
I have used below code on tbody tag but its doesn't work for me

 <tbody style="height: 100px; overflow: auto"> 
like image 309
Nikhil D Avatar asked Jun 22 '12 08:06

Nikhil D


People also ask

How do you make a table vertically scrollable in HTML?

The approach of this article is to create table with 100% width using width property and create vertical scroll inside table body using overflow-y property. Overflow property is used to create scrollbar in table. Use display: block; property to display the block level element.

How do I enable vertical scrolling in 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 .

How do I add a scrollbar to a table in HTML?

Suppose we want to add a scroll bar option in HTML, use an “overflow” option and set it as auto-enabled for adding both horizontal and vertical scroll bars. If we want to add a vertical bar option in Html, add the line “overflow-y” in the files.


2 Answers

Just add the display:block to the thead > tr and tbody. check the below example

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

like image 29
Viralk Avatar answered Sep 21 '22 15:09

Viralk


Why don't you place your table in a div?

<div style="height:100px;overflow:auto;">   ... Your code goes here ...  </div> 
like image 190
sushil Avatar answered Sep 21 '22 15:09

sushil