The primary concern in this situation is the usage of absolute positioning for your inner
element.
An element with absolute positioning is taken out of the normal flow and does not impact its parent container.
To address this issue, you can convert the overlay
into a flex container, remove the position: absolute
from the inner
, utilize auto margins on the inner
, and align it to the right.
Stack snippet
.overlay {
bottom: 0;
display: flex;
height: 48px;
left: 65px;
padding: 0;
position: absolute;
right: 255px;
z-index: 4;
background-color: cyan
}
.overlay-range{
display: flex;
}
.inner {
display: flex;
background-color: red;
padding: 5px;
bottom: 20px;
margin-left: auto;
align-self: flex-start;
}
span {
width: 30px;
}
<div class="overlay">
<div class="overlay-range">
<input type="range"></div>
<div class="inner">
<span> + </span>
<span> - </span>
<span> * </span>
<span> % </span>
<span> / </span>
</div>
</div>
To ensure that the overlay
adjusts its width as well, you should eliminate the right: 255px
property from the overlay
.
After making this adjustment, you can also remove the newly added margin-left: auto
since it will no longer have any effect.
Stack snippet
.overlay {
bottom: 0;
display: flex;
height: 48px;
left: 65px;
padding: 0;
position: absolute;
z-index: 4;
background-color: cyan
}
.overlay-range{
display: flex;
}
.inner {
display: flex;
background-color: red;
padding: 5px;
bottom: 20px;
align-self: flex-start;
}
span {
width: 30px;
}
<div class="overlay">
<div class="overlay-range">
<input type="range"></div>
<div class="inner">
<span> + </span>
<span> - </span>
<span> * </span>
<span> % </span>
<span> / </span>
</div>
</div>
If desired, you could opt to keep display: block
on the overlay
and switch the display: flex
to display: inline-flex
to align them side by side, although the previous version may be preferred.
.overlay {
bottom: 0;
display: block;
height: 48px;
left: 65px;
padding: 0;
position: absolute;
z-index: 4;
background-color: cyan
}
.overlay-range {
display: inline-flex;
}
.inner {
display: inline-flex;
background-color: red;
padding: 5px;
bottom: 20px;
}
span {
width: 30px;
}
<div class="overlay">
<div class="overlay-range">
<input type="range">
</div>
<div class="inner">
<span> + </span>
<span> - </span>
<span> * </span>
<span> % </span>
<span> / </span>
</div>
</div>