Reputation: 1
Element with position: absolute
goes down
instead of to be like this:
You can edit the below code on codepen.
.container {
margin: auto;
width: 700px;
height: 300px;
background: lightblue;
overflow-x: auto;
position: relative;
}
.child {
width: 50px;
height: 300px;
position: absolute;
top: 100%;
background: red;
}
<div class="container">
<div class="child"></div>
</div>
Upvotes: 0
Views: 753
Reputation: 67778
The overflow-x: auto
setting on the parent expands its height when an absolutely positioned child element is added that overflows the parent. Erase it to get a result like in your second image.
.container {
margin: auto;
width: 700px;
height: 300px;
background: lightblue;
position: relative;
}
.child {
width: 50px;
height: 300px;
position: absolute;
top: 100%;
background: red;
}
<div class="container">
<div class="child"></div>
</div>
Upvotes: 1
Reputation: 786
Try this:
.child {
width: 50px;
height: 300px;
position: absolute;
bottom: 0;
background: red;
}
I think this is what you need
Upvotes: 0