I want to set a minimum height for tbody in CSS, even if no <tr><td></td></tr>
in tbody, here is my code:
tbody{
height: 500px;
min-height:500px;
}
but it doesn't work. so what should I do to achieve this?
CSS Demo: min-heightThis is a box where you can change the minimum height. If there is more content than the minimum the box will grow to the height needed by the content. The element's height is set to the value of min-height whenever min-height is larger than max-height or height .
To fix the HTML table tbody height with scrollable content you have to fix height with overflow auto property. For table thead, tbody tr you have to set display table and table-layout fixed properties.
– What is Min Height 100vh in CSS? Min height 100vh means the element should occupy the web browser viewport height. This is always 100 percent of the web browser's viewport height. If there is more content, the element will stretch more than the viewport's height, which is a code example that will clear things up.
You could consider min-height: 100vh; . This sets the height equal or greater to the size of the screen, vh: vertical height .
Hope this demo will work for you...
Css:
tbody{
height: auto;
min-height:200px;
display:block
}
Fiddle
We needed the min-height on the <tbody>
as we could not inject other HTML elements (user content). I found a fix.
Height works for an empty table, but not if the empty table has an empty tbody in Chrome (59) - it works for Firefox and Egde. Also other cases hidden <tr>
gave issues, see JSFiddle for all cases.
CSS:
.test {
border: 1px solid red;
height: 60px;
}
Html:
Empty table:
<table class=test>
</table>
Empty tbody:
<table class=test>
<tbody></tbody>
</table>
Chrome 59:
Edge (14), IE (11), Firefox (54):
Fixed this with:
tbody:before {
content: ''/* needed for chrome*/
}
See updated JSFiddle
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