Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set maximum height for table-cell?

Tags:

html

css

I got a table-cell with fixed width and height and if text is too large, cell size should remain the same and text should be hidden by overflow:hidden.

div {    display: table-cell    height: 100px;    width: 100px;    overflow: hidden;    vertical-align: middle; } 

Table-cell, however, expands beyond 100px if too much text is added. Any tricks to prevent it from expanding?

Text should be several lines in length, so "white-space:nowrap" solution is not applicable

like image 351
skyisred Avatar asked Dec 02 '12 09:12

skyisred


People also ask

How do you change the cell height of a table in CSS?

To specify Table width and height, use CSS width, height properties. Here the table width as 30% and height of the td set to 40px.

How do you set the height of a TD table?

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.

How can I make my table height responsive?

Using the width option instead of the height to set a fixed limit to your illustration. The absence of height is the reason for the problem. Use of height: 100 mvh only (content values will vary with context).


1 Answers

By CSS 2.1 rules, the height of a table cell is “the minimum height required by the content”. Thus, you need to restrict the height indirectly using inner markup, normally a div element (<td><div>content</div></td>), and set height and overflow properties on the the div element (without setting display: table-cell on it, of course, as that would make its height obey CSS 2.1 table cell rules).

like image 102
Jukka K. Korpela Avatar answered Sep 21 '22 17:09

Jukka K. Korpela