Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Fix row height

Tags:

I'm having this markup:

<style>     table     {         border:1px solid black;         width:400px;         height:300px;         border-collapse:collapse;     }     table tbody     {         border:1px solid red;     }     table td     {         background:yellow;         padding:10px;         border-bottom:1px solid green;         height:20px;     } </style>   <table> <tbody>     <tr><td>test</td></tr>     <tr><td>test</td></tr> </tbody> </table> 

What I need is that the rows won't stretch in height. Is there a way to have a fixed row height?

like image 808
Fuxi Avatar asked Nov 27 '09 01:11

Fuxi


People also ask

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

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 the height of a row in a table?

Change row height 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 change row height in CSS?

CSS Table Row height. You can set Row Height through CSS line-height property it set to each tr. When you set this property, each row has heigh of 50 pixel.

How do I fix td height in HTML?

To set the cell width and height, use the CSS style. The height and width attribute of the <td> cell isn't supported in HTML5. Use the CSS property width and height to set the width and height of the cell respectively. Just keep in mind, the usage of style attribute overrides any style set globally.


1 Answers

HTML Table row heights will typically change proportionally to the table height, if the table height is larger than the height of your rows. Since the table is forcing the height of your rows, you can remove the table height to resolve the issue. If this is not acceptable, you can also give the rows explicit height, and add a third row that will auto size to the remaining table height.

Another option in CSS2 is the Max-Height Property, although it may lead to strange behavior in a table.http://www.w3schools.com/cssref/pr_dim_max-height.asp

.

like image 163
PortageMonkey Avatar answered Sep 19 '22 17:09

PortageMonkey