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
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.
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.
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).
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With