I need code similar to this:
.parent{
position: relative;
}
.static-child{
width: 100%;
height: 200px;
background-color: aqua;
}
.absolute-child{
position: absolute;
bottom: 0;
left: 1rem;
right: 1rem;
transform: translateY(50%);
background-color: red;
}
.another-container{
background-color: blue;
}
<div class="parent">
<div class="static-child"></div>
<div class="absolute-child">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
</div>
</div>
<div class="another-container">
<h2>
What is Lorem Ipsum?
</h2>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
My issue is that the parent container’s overflow, caused by an absolutely positioned child ( red container ), doesn’t affect the parent container’s size. As a result, the content of the next div (blue container
) goes under the absolutely positioned child div.
The content inside the absolutely positioned child is dynamic, so I can’t add a fixed margin to the next div or a static child element
I don’t want to use JavaScript for this; it should be done using only CSS. I want to emphasize that the height of the child element is variable.
2
Answers
I didn’t quite understand what you wanted to do. Can you explain with a picture?
Unfortunately, this is how absolute position works. It’s out of, let’s say, the "flow" of nodes. You can try a simple workaround like this: