Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML CSS formatting: table row inherit content height

How can I format a table row to inherit the height of the content? I wish to have something like enter image description here

I have tried

table{
   table-layout:fixed;
   width:700px;
 }

but that does not work

like image 271
jpo Avatar asked Dec 26 '12 14:12

jpo


People also ask

How do you adjust row height in HTML table?

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 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.

What is table layout in HTML?

The table-layout property defines the algorithm used to lay out table cells, rows, and columns. Tip: The main benefit of table-layout: fixed; is that the table renders much faster. On large tables, users will not see any part of the table until the browser has rendered the whole table.

What is height auto CSS?

If height: auto; the element will automatically adjust its height to allow its content to be displayed correctly. If height is set to a numeric value (like pixels, (r)em, percentages) then if the content does not fit within the specified height, it will overflow.


1 Answers

Tyipcally, a table will inherit the height of the content provided that the columns have a defined width using either percentage of the total table width or absolutel pixel "px" definitions. IN addition, be sure that the table rows do not have a specified height i.e. 'height: 30px'.

Code Solution:

table {
  width: 700px;
}
table tr td {
  width: 350px;
  height: auto;
}
like image 165
ProfileTwist Avatar answered Sep 29 '22 18:09

ProfileTwist