有这样一个块,带有图片,渐变和“通过”此渐变的窗口(psd中的图层蒙版)+文本和窗口内的按钮:
问题:如何在自适应布局中、使用 SVG 蒙版或以任何其他方式实现这一点?
还没有想法。带着面具,再配合问题的适应性。
编码:
.img {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
-o-object-fit: cover;
object-fit: cover;
}
.slider-right {
width: 300px;
height: 300px;
border: 2px solid #fff;
position: relative;
}
.slider-right .btn {
position: absolute;
left: 0;
bottom: 20px;
right: 0;
margin: 0 auto;
display: block;
max-width: 150px;
}
.slider .container {
position: relative;
z-index: 3;
height: 100%;
}
.slider .container .row {
height: 100%;
}
.slider {
color: #fff;
height: 500px;
}
.slider-inner {
position: relative;
width: 100%;
background: rgba(21,91,50,1);
background: -moz-linear-gradient(left, rgba(21,91,50,1) 0%, rgba(21,91,50,0) 100%);
background: -webkit-gradient(left top, right top, color-stop(0%, rgba(21,91,50,1)), color-stop(100%, rgba(21,91,50,0)));
background: -webkit-linear-gradient(left, rgba(21,91,50,1) 0%, rgba(21,91,50,0) 100%);
background: -o-linear-gradient(left, rgba(21,91,50,1) 0%, rgba(21,91,50,0) 100%);
background: -ms-linear-gradient(left, rgba(21,91,50,1) 0%, rgba(21,91,50,0) 100%);
background: linear-gradient(to right, rgba(21,91,50,1) 0%, rgba(21,91,50,0) 100%);
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"><link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="slider">
<img src="https://images.unsplash.com/photo-1469022563428-aa04fef9f5a2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=600&q=60" alt="" class="img">
<div class="container h-100">
<div class="row align-items-center h-100">
<div class="col-sm-6">
<h1>Lorem ipsum dolor sit amet.</h1>
</div>
<div class="col-sm-6">
<div class="slider-right">
<a href="#" class="btn btn-danger">Button</a>
</div>
</div>
</div>
</div>
</div>

SVG + Mask - 过滤器解决方案
此解决方案不使用 svg 过滤器来装饰背景。您可以将蒙版的 svg 属性用于窗口和背景。请参阅代码以获取注释。
按钮和图像位于 SVG 内部,因此布局是自适应的,不会因任何小工具显示尺寸而中断。
蒙版 + 径向渐变
将渐变添加到蒙版以使背景透明。
任何颜色的不均匀颜色背景
查看代码中的注释:
带有白色阴影的白色方块的 SVG 蒙版正是您正在寻找的。