【发布时间】:2019-11-29 14:38:03
【问题描述】:
我在将模糊应用于绝对/固定元素的背景时遇到了问题,因为它似乎不会模糊页面的主要内容,只会模糊绝对元素本身的内容。我目前的警报样式如下:
.alert-wrap {
position: fixed;
z-index: 10;
right: 0;
bottom: 0;
}
.alert-wrap .alert {
display: block;
background-color: rgba(215, 44, 44, 0.5);
margin: 0 15px 15px 0;
position: relative;
}
.alert-wrap .alert:before {
content: "";
position: absolute;
height: 100%;
width: 100%;
top: 0;
bottom: 0;
left: 0;
right: 0;
-webkit-filter: blur(10px);
-moz-filter: blur(10px);
-o-filter: blur(10px);
-ms-filter: blur(10px);
filter: blur(10px);
}
我希望这会模糊警报元素的背景,使其背后的主要内容看起来很模糊(更多地关注元素本身),但即使确认这个问题根本存在,也没有找到任何东西.
HTML文档流程如下:
<html>
<head>
<!-- Header Stuff Deleted -->
</head>
<body>
<div class='alert-wrap'>
<div class='alert'>
<div class='head'>
Notifications
</div>
<div class='body'>
Alert content here
</div>
</div>
</div>
<?php
//constructing navbar
?>
<div class='content'>
Some content here
</div>
<?php
//constructing footer
?>
</body>
</html>
图片示例:
【问题讨论】:
-
你有问题,因为你没有给模糊的元素应用任何背景,所以没有什么可以模糊的。
-
@makshh 正如我在 OP 中所说,我希望模糊绝对元素的背景,以使半透明背景后面的内容模糊,而不是元素本身的任何类型的背景.
-
你的意思是这样的? codepen.io/anon/pen/JYMQBW
-
@makshh 我可能没有很好地解释这一点,我会添加一些图片
-
@makshh 图片示例:img
标签: css