http://jsfiddle.net/ZAvDd/
As my table row grows in height, I'd like my div inside to automatically match it as well.
For the code above, my div
's height is always 0
.
I understand that the height:inherit
only works when you explicitly state the height of the parent (<td>
) but I don't want to do that because I have no idea what content height will be displayed there.
Is there any css trick to do this or do I have to resort to some JS?
height: 100% will match the height of the element's parent, regardless of the parent's height value. height: inherit will, as the name implies, inherit the value from it's parent. If the parent's value is height: 50% , then the child will also be 50% of the height of it's parent.
container div has two parent elements: the <body> and the <html> element. And we all know that the default value of the height property is auto , so if we also set the height of <body> and <html> elements to 100%, the resulting height of the container div becomes equal the 100% height of the browser window.
height() It returns the current height of the element. It does not include the padding, border or margin. It always returns a unit-less pixel value. Note: The height() will always return the content height, regardless of the value of CSS box-sizing property.
You cannot using a height
rule, but you can still achieve the effect you're after by positioning the div absolutely. Since this changes the layout of the div, you will then have to apply the width to the td
instead:
td.fooed {position:relative; width:30px;}
td.fooed .foo {
position:absolute; top:0px; left:0px; right:0px; bottom:0px;
background:gray;
}
Here's your fiddle: http://jsfiddle.net/ZAvDd/2/
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