Sta*_*tec 23 html css filter css3
我知道有一堆新的CSS过滤器,我想知道是否有办法将它们应用于图像或背景图像.我读过的所有内容都谈到了用阴影来柔化图像,然而,阴影是一种颜色,我想模糊图像的边缘,这样如果它们彼此相邻,我就可以更加无缝地将它们混合在一起.现在,看起来你只能使用阴影或对整个图像应用模糊(根据我所读到的内容).
我能想出的最接近的是一个半透明的盒子阴影....就像这样
-webkit-box-shadow: 12px 29px 81px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 12px 29px 81px 0px rgba(0,0,0,0.75);
box-shadow: 12px 29px 81px 0px rgba(0,0,0,0.75);
Run Code Online (Sandbox Code Playgroud)
小智 80
如果您正在寻找的只是模糊图像边缘,您可以简单地使用带有插入的框阴影.
工作示例:http: //jsfiddle.net/d9Q5H/1/
HTML:
<div class="image-blurred-edge"></div>
Run Code Online (Sandbox Code Playgroud)
CSS
.image-blurred-edge {
background-image: url('http://lorempixel.com/200/200/city/9');
width: 200px;
height: 200px;
/* you need to match the shadow color to your background or image border for the desired effect*/
box-shadow: 0 0 8px 8px white inset;
}
Run Code Online (Sandbox Code Playgroud)
小智 17
我不完全确定你所追求的视觉效果是什么,但这里有一种模糊图像边缘的简单方法:将图像放在另一个div中的div与模糊图像.
这里的工作示例: http ://jsfiddle.net/ZY5hn/1/
HTML:
<div class="placeholder">
<!-- blurred background image for blurred edge -->
<div class="bg-image-blur"></div>
<!-- same image, no blur -->
<div class="bg-image"></div>
<!-- content -->
<div class="content">Blurred Image Edges</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.placeholder {
margin-right: auto;
margin-left:auto;
margin-top: 20px;
width: 200px;
height: 200px;
position: relative;
/* this is the only relevant part for the example */
}
/* both DIVs have the same image */
.bg-image-blur, .bg-image {
background-image: url('http://lorempixel.com/200/200/city/9');
position:absolute;
top:0;
left:0;
width: 100%;
height:100%;
}
/* blur the background, to make blurred edges that overflow the unblurred image that is on top */
.bg-image-blur {
-webkit-filter: blur(20px);
-moz-filter: blur(20px);
-o-filter: blur(20px);
-ms-filter: blur(20px);
filter: blur(20px);
}
/* I added this DIV in case you need to place content inside */
.content {
position: absolute;
top:0;
left:0;
width: 100%;
height: 100%;
color: #fff;
text-shadow: 0 0 3px #000;
text-align: center;
font-size: 30px;
}
Run Code Online (Sandbox Code Playgroud)
请注意,模糊效果正在使用图像,因此它会随图像颜色而变化.
我希望这有帮助.
如果在 div 中设置图像,则还必须设置高度和宽度。这可能会导致图像失去比例。此外,您必须在 CSS 中而不是 HTML 中设置图像 URL。
相反,您可以使用 IMG 标签设置图像。在容器类中,您只能以百分比或像素为单位设置宽度,高度将自动保持比例。
这对于搜索引擎和阅读引擎的可访问性也更有效,以使用IMG标签定义图像。
.container {
margin: auto;
width: 200px;
position: relative;
}
img {
width: 100%;
}
.block {
width: 100%;
position: absolute;
bottom: 0px;
top: 0px;
box-shadow: inset -10px -10px 10px 20px white;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<img src="https://picsum.photos/200/200">
<!-- http://lorempixel.com/200/200/city -->
<div class="block"></div>
</div>Run Code Online (Sandbox Code Playgroud)