On fixed elements and backgrounds

CSS can be delightfully intuitive in one place and bafflingly counterintuitive in the next. Hui Jing explores one of the latter cases: a fixed element behaving anything but fixed once a CSS filter is applied to its nearest ancestor.

Normally, a fixed element stays put while you scroll. But if the ancestor of that fixed element has a filter applied to it, the fixed behavior stops working. The reason, as explained in the original write-up, is that the filter causes the immediate parent to become the containing block in place of the viewport. A CodePen is provided so readers can try the behavior themselves.

The article goes further than this one quirk, covering scrolling, rendering performance, and trickery involving pseudo elements to work around the issue. If this kind of thing is tricky to reason about, it belongs in the same family as Block Formatting Contexts (BFCs) — as the author puts it: A BFC Is A Mini Layout In Your Layout.