Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html table fixed height?

Tags:

html

I have a table which shows records from DB dynamically. I just need to fix the height of the table, so that the table gets a scrolling window downwards within the table itself if it has large number of rows. This is so the user wont need to scroll the entire page?

Is this possible...?

Thanks in advance...

like image 396
soorajthomas Avatar asked Sep 15 '10 11:09

soorajthomas


People also ask

How do you set a fixed height table in HTML?

The height of rows 'tr' in a table can be fixed very easily. This can be done by adding the height attribute in the tr tag. If the height is not specified, the height of the row changes according to the content. The height can be specified either in pixels, or percentage.

How do you fix row height in a table?

To set the row height to a specific measurement, click a cell in the row that you want to resize. On the Layout tab, in the Cell Size group, click in the Table Row Height box, and then specify the height you want. To use the ruler, select a cell in the table, and then drag the markers on the ruler.

How do I fix the height of a row in CSS?

Simply add style="line-height:0" to each cell. This works in IE because it sets the line-height of both existant and non-existant text to about 19px and that forces the cells to expand vertically in most versions of IE.

How do you control the width of a table in HTML?

To set the table width in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property width.


1 Answers

One solution to this would be to use a <div>-layer surrounding the <table>, where you use the style-attribute with: overflow: auto; max-height: (whatever height you want here)

As an example:

<div id="mainHolder" style="overflow: auto; max-height: 400px;">
    <table>
    ... Lots of data ...
    </table>
</div>

This would create a table that can grow in height, but it would be restrained in the div-layer, and you would automatically get scrollbars when the content grows larger than 400px.

With jQuery you can also do something like this:

<script type="text/javascript">
window.onresize = doResize;

function doResize() {
    var h = (typeof window.innerHeight != 'undefined' ? window.innerHeight : document.documentElement.clientHeight) - 20;
    $('#mainHolder').css('max-height', h);
    $('#mainHolder').css('height', h);
};

$(document).ready(function () { doResize(); });
</script>
like image 141
NoLifeKing Avatar answered Sep 20 '22 23:09

NoLifeKing