[英]How can i display element over body, when body is blured?
I have a problem, I'm trying to display div over the blurred body, but I can't really make it work. 我有一个问题,我正在尝试在模糊的身体上显示div,但我无法真正使其起作用。 I've tried adding z-index to the div but it doesn't seem to be working.
我尝试将Z-index添加到div中,但似乎无法正常工作。
Heres what I've tried: 这是我尝试过的:
body { padding: 0; margin: 0; overflow: hidden; background: black; color: white; border: none; cursor: default; filter: blur(11px); } #foo { z-index: 10; }
<div id="foo"> Random Text </div>
您始终需要为z-index
ed选择器定义position
Since you have blurred the parent, all descendants will be blurred as well. 由于已经模糊了父级,因此所有后代也将模糊。 To achieve a similar effect you have to:
要获得类似的效果,您必须:
div
, say #bar
, which will be a sibling to #foo
instead. div
,比如说#bar
,这将是#foo
的同级兄弟。 #foo
a higher z-index
than #bar
and ensure it's positioned (not position: static
) . #foo
比#bar
更高的z-index
并确保它的位置(不是position: static
) 。 Example: 例:
/* ----- CSS ----- */ body { padding: 0; margin: 0; } #bar { width: 100%; height: 100%; overflow: hidden; position: absolute; top: 0; bottom: 0; left: 0; right: 0; padding: 0; margin: 0; background: black; color: white; border: none; cursor: default; filter: blur(11px); z-index: 0; } #foo { color: red; position: relative; z-index: 10; }
<!----- HTML -----> <div id="bar"></div> <div id="foo"> Random Text </div>
The Random text is black just like the body background and you should define the body z-index lower than #foo. 随机文本是黑色的,就像主体背景一样,您应将主体z-index定义为低于#foo。 Hopes this helps :)
希望这会有所帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.