Disclaimer:
I suppose this is related to this reported bug, and is quite similar to this other question but the fix suggested there does not apply.
If I have a div
that is sticky, ie it has position: fixed; top: 0px;
.
I would expect it to be attached/sticky in the top of the body/screen.
What I notice (only in Firefox) is that applying a filter to its parent will make the position adopt the parent element (the one I added the filter to) as the position: fixed;
reference, not the body.
Example (https://jsfiddle.net/sz6xtfno/):
(notice the div.sticky
changing position, when it should be fixed
in Firefox)
// just for demo purpose:
const sticky = document.querySelector('.sticky');
const container = sticky.parentElement;
setTimeout(() => container.classList.add('add-filter'), 1000);
html,
body {
margin: 0px;
padding: 0px;
height: 100%;
}
.sticky {
display: block;
position: fixed;
top: 0px;
}
.add-filter {
-webkit-filter: sepia(10%) grayscale(60%);
-moz-filter: sepia(10%) grayscale(60%);
filter: sepia(10%) grayscale(60%);
}
div {
background-color: #ddf;
padding: 10px;
margin: 0px;
position: relative;
}
<div>
<p>Previous element</p>
</div>
<div class="container">
<p>This is the container</p>
<div class="sticky">
<p>This is a sticky element</p>
</div>
</div>
Question:
How to correct this? I am looking for a solution without JavaScript since this issue seems to scramble positioning calculations.