我想让图像的边缘变得模糊,或者至少模糊地淡出。我尝试过的任何方法都不起作用,并且我查看了 Stackoverflow 上的所有问题。我使用的是 CSS,而不是 Sass。使问题变得复杂的是,我在页面上有一个背景图像,并用不透明度为 0.8 的白色蒙版覆盖它。请问有人可以帮忙吗?
这是我的 Codepen。
.screen {
position: relative;
width: 100vw;
height: 100vh;
display: inline-block;
overflow: hidden;
margin-top: -6px;
}
.bg {
background-image: url('//newsinteractive.post-gazette.com/.testLaura2/shutterstock_246230623.jpg');
width: 100%;
position: fixed;
top: 0px;
left: 0px;
height: 100%;
filter: blur(3px);
}
.bg-mask {
width: 100%;
background-color: rgba(255, 255, 255, .8);
position: fixed;
top: 0;
left: 0;
height: 100%;
}
#ballerina {
position: absolute;
top: 0px;
left: 0px;
width: 1600px;
height: 1000px;
background-image: url('http://newsinteractive.post-gazette.com/.testLaura2/BalletAudition04xx_2992.jpg');
}
#ballerina:after {
position: absolute;
top: 10px;
left: 0px;
width: 1600px;
height: 1000px;
background: -moz-linear-gradient(top, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 1) 100%);
/* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(50%, rgba(0, 0, 0, 0)), color-stop(100%, rgba(0, 0, 0, 1)));
/* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 1) 100%);
/* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 1) 100%);
/* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 1) 100%);
/* IE10+ */
background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 1) 100%);
/* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00000000', endColorstr='#000000', GradientType=0);
/* IE6-9 */
}
<div class="bg"></div> <div class="bg-mask"></div> <div class="screen height-auto"> <div id="ballerina"></div> </div>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我最终不得不稍微改变一下我的概念。我删除了整个页面的背景图像和蒙版,只是将页面背景设置为白色,没有蒙版。然后我使用了 模糊边缘的解决方案使用 CSS 的图像或背景图像
所以我的代码如下所示:
html:
<div class="img-contain"> <img src="http://newsinteractive.post-gazette.com/.testLaura2/BalletAudition04xx_2992.jpg"> <div class="block"></div> </div>CSS:
.img-contain { margin: auto; width: 100%; margin: auto; position: relative; } .img-contain img { width: 100%; height: auto; } .block { width: 100%; position: absolute; bottom: 0px; top: 0px; box-shadow: inset -0px -0px 20px 20px white; }