I am trying to apply a simple blur to most of the page while another element sits on top, unblurred
<div class="stufftobeblurred">
<header>
...
</head>
... most of page is here ...
</div>
<div class="stuffontop">
... this isn't blurred ...
</div>
(with CSS such as below)
.stufftobeblurred {
filter: blur(2px);
}
header {
position: absolute;
...
}
This works ok except that the positioned header gets moved while the blur is active. See this fiddle where I've broken it down to the minimum possible replication.
https://jsfiddle.net/8hr72gs3/
Uncomment the blur and observe the blue rectangle moves.
I've tried applying z-index:0;
and transform:translateZ(0)
as suggested by search hits but this appears to have no effect.
The element still moves even if blur radius is 0.
N.B. In the fiddle if I apply margin:0; padding:0
to the body it seems to fix the problem, however in my real-world scenario this doesn't work. I don't know what the semantic difference is between the fiddle and my realword scenario, so if anyone can tell me why this padding/margin should works on the fiddle it may help with further diagnosis.
Also, if the fiddle is modified to have an outer div then the trick no longer works (if applied to the outer div instead of body, with or without a position:relative
added)