2

I am trying to make a table with rows that take up only the space they need vertically. Is there any way to do this with CSS without setting the last cell to a height of 100%?

This question is pretty similar to this question only in the other direction.

Currently looks like this:

 ---------------------------------
|                                 |
|thing 1                          |
|                                 |
 ---------------------------------
|                                 |
|thing 2                          |
|                                 |
 ---------------------------------
|                                 |
|thing 3                          |
|                                 |
 --------bottom of table----------

how do I get it to look like

 ---------------------------------
|thing 1                          |
 ---------------------------------
|thing 2                          |
 ---------------------------------
|thing 3                          |
|                                 |
|                                 |
|                                 |
|                                 |
|                                 |
|                                 |
 --------bottom of table----------

or, alternatively like:

 ---------------------------------
|thing 1                          |
 ---------------------------------
|thing 2                          |
 ---------------------------------
|thing 3                          |
 --------bottom of table----------





-----bottom of containing div------
Community
  • 1
  • 1
Tantelope
  • 597
  • 1
  • 8
  • 24

3 Answers3

1

use this line of CSS selector :

tr:last-child { height:300px; }
eshirvana
  • 23,227
  • 3
  • 22
  • 38
1

You could set the height of the tr to 1px for all rows but the last.

html, body{width:100%;height:100%;margin:0;}
table{
  table-layout:fixed;
  height:100%;
}
table tr{height:1px;}
table tr:last-child{height:auto;}
table td{vertical-align:top;border:1px solid #ccc;}
<table>
  <tr><td>line 1</td></tr>
  <tr><td>line 2</td></tr>
  <tr><td>line 3</td></tr>
  <tr><td>line 4</td></tr>
  <tr><td>line 5</td></tr>
  <tr><td>last line</td></tr>
</table>
Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
0

You can use css :last-child like:

tr:last-child
Litestone
  • 529
  • 7
  • 22
Sven van den Boogaart
  • 11,833
  • 21
  • 86
  • 169