Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Set parent's height to 0 but child div still show

Tags:

html

css

angular

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.

like image 497
imrhung Avatar asked Dec 26 '17 11:12

imrhung


People also ask

How do you set height to 100% of a 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.

How do I make div fit to parent div?

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.

How do you set the height in CSS to be depending on the content?

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.

Why does my div have zero height?

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.


1 Answers

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; } 
like image 67
Adeeb basheer Avatar answered Sep 21 '22 16:09

Adeeb basheer