If you open this Fiddle https://jsfiddle.net/17uwnsq6/4/ in Safari (12.1.2 but should work for all recent versions) and start scrolling down the white scrollable area, at first the sticky "Header" element will remain sticky, but will later scroll off the screen. In Chrome and Firefox it always remains sticky as expected.
HTML and CSS for reference:
<div class="title">Title</div>
<div class="container">
<div class="header">Header</div>
<div class="content">Content</div>
</div>
html {
height: 100%;
}
body {
display: flex;
flex-direction: column;
height: 100%;
margin: 0;
padding: 0;
}
.container {
flex: 1 1 0;
overflow: auto;
}
.header {
position: -webkit-sticky;
position: sticky;
top: 0;
}
.content {
height: 2500px;
}
.title {
flex: 0 0 auto;
background-color: lightblue;
}
It seems that this bug shows up when the container is sized using flex layout. Does anybody know of a workaround for this issue? The goal is to make the header always sticky, while at the same time to size the container so that it would occupy the part of the viewport left over by the "Title".
CSS position:sticky is Fully Supported on Safari 13, which means that any user who'd be accessing your page through Safari 13 can see it perfectly.
Troubleshooting position sticky Position sticky will most probably not work if overflow is set to hidden, scroll, or auto on any of the parents of the element. Position sticky may not work correctly if any parent element has a set height. Many browsers still do not support sticky positioning.
position: sticky is a new way to position elements and is conceptually similar to position: fixed . The difference is that an element with position: sticky behaves like position: relative within its parent, until a given offset threshold is met in the viewport.
How to Make position: sticky Work With the overflow Property? By specifying a height on the overflowing container, you should be able to make position: sticky work whilst having the container element have the overflow property set.
I think I've figured it out. The trick is to put the entire children of the scrollable container (that is, the header and the content) into a wrapper div - then the bug isn't triggered.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With