Issue with Making Child Div Inherit Height from Parent <td> without js or absolute positning.

I'm facing a problem with making a child div (.auto-box) inherit the height of its parent <td> in HTML/CSS without having using javascript or position absolute. Here's a simplified version of my code: https://codepen.io/umanga/pen/JjVMNbJ
No description
7 Replies
Mannix
Mannix•2mo ago
I'm not sure if it's correct way to do it but if you add
table,tr,td,.content {
height: 100%;
}
table,tr,td,.content {
height: 100%;
}
it should work
uD
uD•2mo ago
Does not work.
uD
uD•2mo ago
do you know why the it did not just work with .content {height: 100%} ?
Mannix
Mannix•2mo ago
no idea I also thought it should work but it didn't so i went up the DOM tree until it worked 🙂
uD
uD•2mo ago
Thanks bro. that saved my time. @Kevin probably can help us what's happening here?
Kevin Powell
Kevin Powell•2mo ago
height: 100% doesn't work if the parent doesn't have a declared height, because height: auto means the height is defined by content inside that element. So, you're .content div is only as big as the .auto-box inside of it. Now, tables are a little different in that the space of a cell can be influenced by other elements (like your red one), but doesn't change that 100% for height won't work. The only time we can use that is if we use display: grid, because grid items live inside of their cell, and so height as percentages work, because it'll be a percent of the cell that it's inside of.