I have an overlay element in a container which scrolls horizontally.
I want this overlay to be fixed in place horizontally, but if I scroll the window, the overlay should scroll along with the page. https://jsfiddle.net/Lvy9uq0n/1/
.box {
height: 300px;
width: 3000px;
background: white;
border: 1px solid black;
}
.overlay {
position: fixed;
left: 50%;
padding: 10px;
width: 200px;
}
html,
body {
height: 1000px;
}
.container {
overflow-x: scroll;
}
<div class="container">
<div class="box">
<div class="overlay">
Overlay
</div>
</div>
</div>
<div syle="height:1000px">
Test
</div>
TLDR: Element should be fixed inside a container horizontally but not vertically