I have an element that I am making sticky with position sticky:
#header {
position: sticky;
width: 100vw;
top: 0;
}
<app-header id="header"></app-header>
And that works fine, but I realised that if I use:
body {
overflow-x: hidden;
}
That breaks sticky, and I need to set body overflow-x
to hidden
, how can I fix that, with only CSS solution, no JS solutions?
position: sticky
is an experimental API and should not be used in production, just a heads up (in case you aren't already aware of that) see: developer.mozilla.org/en-US/docs/Web/CSS/position#sticky – Mohammedoverflow-x
with something likeoverflow-x: initial;
. A year later andposition: sticky
is no longer experimental and works cross browser (minus good ol' IE) :) – Historied