Having a horizontal sticky element I expected that width
must not be auto
for the sticky to work correctly.
So while this snipped works, removing width: 100px;
will result in non-sticky behaviour.
#a {
position: sticky;
left: 0;
background: red;
width: 100px;
}
#b {
/* this is to make a scrollbar */
width: 3000px;
background: blue;
}
<div id="a">a</div>
<div id="b">b</div>
Why is this so? I kind of assume that the browser needs the width to detect when the element leaves the viewport, but why does this not work for the auto calculated width in horizontal but in vertical mode?