我尝试将CSS blur属性只应用于id="home"
的background-image,但它也反映在children类中。我的HTML代码是:
<section id="home">
<div class="home">
<h1>ncats is an innovative</h1>
</div>
</section>
我的CSS代码是:
#home{
display: block;
background:url(../images/2.jpg) no-repeat;
background-size: cover;
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
width: 100%;
height: 1080px;
}
.home{
text-align:center;
}
我试图得到一个输出像在下面的链接:http://codepen.io/akademy/pen/FlkzB
但是我的输出是这样的:http://codepen.io/anon/pen/yyEZOb
6条答案
按热度按时间syqv5f0l1#
对于未来的读者(以及现在的读者,他们并不特别关心跨浏览器支持):有一种CSS机制可以 * 完全 * 做到这一点。
在滤镜效果规范中,滤镜也被定义为 * 函数表示法 *,接受图像+滤镜列表。语法如下所示:
...其中filter函数的第二个参数接受过滤器列表(与
filter
属性相同)。遗憾的是,到目前为止只有Safari实现了它--它在Safari 9中以
-webkit-filter()
的形式发布,但有一些严重的bug,所以他们甚至没有宣布支持它。此后,它在WebKit中得到了修复,并将在下一个版本的Safari(iOS 9.3/Desktop Safari 9.1)中发布。bvpmtnay2#
将图形效果应用于元素
backdrop-filter
底部的区域mspsb9vt3#
我得到了你的Codepen工作与以下CSS:
添加':before'伪元素,指定在选定元素(#home)之前插入内容。
由于我们必须对元素进行一些重新排列,因此将位置设置为绝对值并更改z索引在这里很重要。
更多信息关于:before pseudo-element
https://developer.mozilla.org/en-US/docs/Web/CSS/::before
有关z轴的详细信息:
http://www.w3schools.com/cssref/pr_pos_z-index.asp
kxxlusnw4#
要获得与共享的codepen类似的输出,必须使用相同的技术,并使用
:before
或:after
之类的伪元素。只需按如下所示更改您的CSS:
gywdnpxw5#
也许你可以使用opacity相关属性来代替webkit-filter选项:
ssgvzors6#
实际上你需要理解HTML div的块结构,你应用于父元素或父划分的任何东西也会应用于子元素,所以如果这是你的代码
<div class="parent"> Hi... <div class="child"> i am child </div> </div>
现在,如果你给父类应用css filter:blur属性,它也会影响子类,因为父类/div块包含了子类/div块,所以你给予父类的任何东西都会被子类采用。
但还是有一种方法可以做到:JSFiddle .
说明:有一个div以child作为span,另一个span作为单独的元素,这个div被赋予了blur,所以它的child也会受到影响,但是单独的span不会,因为它不是那个div的child。
超文本标记语言
中央支助组