Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div parent div not containing children div

Tags:

html

css

I have something like this:

<div id="page">
  <---some content here -->
  <div id="container">
    <div id="child">
    </div>
  </div>
</div>

now, #page does not have any formatting in it. It works correctly for some content, i mean, when content is bigger, the #page has more height also. But, when today i applied #container in it, which is positioned absolute, and within it there is a #child which is positioned relative, it seems like #container is not within #page - that means if #container grows, height of #page is not changing, why?

like image 218
ojek Avatar asked Jan 27 '26 04:01

ojek


2 Answers

Absolutely positioned elements are removed from the normal flow of the document causing them not to increase the height of their parent if their height increases.

Elements that are positioned relatively are still considered to be in the normal flow of elements in the document. In contrast, an element that is positioned absolutely is taken out of the flow and thus takes up no space when placing other elements. Full Text

like image 87
Kevin Bowersox Avatar answered Jan 29 '26 18:01

Kevin Bowersox


Kevin's answer revealed the trick of (why is not possible the) autosizing.

For positioninig instead, note that if #container is absolute, and you want it to refer to #page, then #page should be relative, absolute or fixed , not static (the default).

Otherwise, the positioning would be referred to the HTML element / viewport, the visible area of the window.

like image 43
Andrea Ligios Avatar answered Jan 29 '26 19:01

Andrea Ligios



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!