Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define minimum height for tbody in CSS

Tags:

css

css-tables

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?

like image 456
hiway Avatar asked Mar 20 '13 09:03

hiway


People also ask

How do I change the minimum height in CSS?

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 .

How do you fix the height of tbody?

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?

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

What does min height 100% do?

You could consider min-height: 100vh; . This sets the height equal or greater to the size of the screen, vh: vertical height .


2 Answers

Hope this demo will work for you...

Css:

  tbody{
     height: auto;
     min-height:200px;
     display:block
    }

Fiddle

like image 106
Senthil Sivaramakrishnan Avatar answered Sep 21 '22 18:09

Senthil Sivaramakrishnan


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:

Chrome 59

Edge (14), IE (11), Firefox (54):

Fixed this with:

tbody:before {
  content: ''/* needed for chrome*/
}

See updated JSFiddle

like image 44
Julian Avatar answered Sep 19 '22 18:09

Julian