Why parent adapts to the child (CSS)?

There is a parent who is not specified in size but has position: relative, and there is a child who has position: absolute and set the size, why the parent adapts to the child?
<div class="parent">
 <div class="child"> 

.parent {
 position: relative;
 background-color: black;
 padding: 1em;

.child {
 position: absolute;
 background-color: blue;
 width: 50px;
 height: 50px;
April 7th 20 at 10:51
1 answer
April 7th 20 at 10:53
Because the element is positioned as absolute drops out of the flow of the document. Now a parent will behave as if he has no children. We can say that the parent has abandoned your child.
I'd say that a child parents gone). And Yes, a child with absolute position, a new parent will be either the window or its ancestor with the same absolute position - Ezra_Buckridge commented on April 7th 20 at 10:56
There is some output, so what would the child were position: absolute, and the parent adjusts to this child (without js)? - serenity commented on April 7th 20 at 10:59
@serenity, In that the parent must be there's something wrong with position absolute that will ask him the height of the content that is the content some sort of need, whether image or text. Otherwise, the script ask him the size.

@Ezra_Buckridge, nah, he has a parent with position:relative, it is relatively it is positioned so that it does not have left my parents, just parents don't notice it. - theodora_Aufderhar commented on April 7th 20 at 11:02
@serenity, probably need to rethink the approach and try to refuse from position:absolute, you can try to upload a block in the sandbox, and explain what you need in the output. - Melisa.Predovic commented on April 7th 20 at 11:05

Find more questions by tags CSSHTML