I need to control the height of a table row--I have tried setting the height of the cells, but I'm hitting a brick wall. See demo.
tr.fixedRow,
tr.fixedRow td.fixedCell {
height: 50px;
overflow: hidden; }
I know that I could change the display
of some things to block
but doing so generally messes up the table in a bad way--I'm working with a rather complicated table that interacts with other tables nearby and needs to line up pixel-perfectly, so generally, changing the display
and then trying to make it look like a table again with CSS isn't a good solution for me, because it won't match up. I need it to stay a table.
I also want to avoid doing this:
<td><div>
... cell content...
</div></td>
Which seems like terrible form. Surely there is a CSS only solution to something so simple?
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.
The CSS “line-height” attribute can be used to alter the table's row height. When we change the value of this “line-height” property, our table row is resized to that height.
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.
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.
You are trying to achieve this by relying on a css property that does not work the way you expect it to: CSS overflow applies to block-level elements, something a <td>
is not (css: display: table-cell;
).
see CSS Overflow on MDN
For this reason, I believe you won't be able to achieve fixed height unless you set display: block;
on <td>
s - and you said you can't as it would break the table alignment, so the only sensible alternative would be, in my opinion:
<td><span>...</span></td>
with your <span>
set to display: block;
(doesn't really make a difference to have a span set to block instead of a div, apart from the fact that a div
would break the html validation, while a span would not - block elements are not allowed in td
elements)
it's the most elegant and valid way I can think of.
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