I want to make a simple animation to show and hide a component.
#parent { height: 0px; }
<div id="parent"> <div id="child">This is some content</div> </div>
When I set parent div height to 0, I expect the child div also not visible, but the child still showing. I want to make it disappear when parent height set to 0.
What is the problem here and what I'm I doing wrong? Thank you very much.
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.
Method 1: First method is to simply assign 100% width and 100% height to the child div so that it will take all available space of the parent div. Consider this HTML for demonstration: HTML.
The height property sets the height of an element. The height of an element does not include padding, borders, or margins! If height: auto; the element will automatically adjust its height to allow its content to be displayed correctly.
The reason why the height or the containers is 0 is because you are floating all the content inside them and floated elements don't expand the height (or width) of their parents.
Add overflow hidden property to the parent object. This way overflow is clipped, and the rest of the content will be invisible (in subject case height is 0 so remaining will also be 0).
#parent { height: 0px; overflow: hidden; }
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