我正在尝试使用混合混合模式创建一个具有倍增效果叠加层的背景,该叠加层还可以显示部分背景。我还需要子内容不受混合模式的影响。像这样:
我尝试将blend-mode设置为unset,我也尝试使用隔离/ isolate,但似乎无法使该选项起作用。我不想使用伪元素或将内容放置在父元素之外,因为设计者的实际布局包含很多内容,我需要它具有响应性。
到目前为止,我能完成的工作: 我可以使背景和覆盖层正常工作,但影响也适用于内容层: https://codepen.io/orlafitz/pen/JVRQpM
.bkg-image {
background-image: url(https://poppyvine.com/wp-content/uploads/2019/04/beach-bw.jpg);
text-align: center;
padding: 100px 0px;
background-size: cover;
background-position: center;
}
.multiply-overlay {
background-color: #323ff0;
mix-blend-mode: multiply;
padding: 50px
}
.bkg-image .content {
color: #fff;
isolation: isolate;
}
<div class="bkg-image">
<div class="multiply-overlay">
<div class="content">
<h1>Margins to show bkg img<br>&<br>Content unaffected by blend mode</h1>
</div><!-- content -->
</div><!-- multiply-overlay-->
</div><!-- bkg img -->
有人知道是否有可能实现这一目标?
答案 0 :(得分:1)
正如我在this previous answer中已经解释的那样,隔离将无法通过这种方式工作,并且在应用mix-blend-mode
之后您将无法隔离内容
关于修复的想法是考虑具有多个背景的background-blend-mode
。这只会影响背景,而不会影响内容,并且代码减少。
.bkg-image {
background:
linear-gradient(#323ff0,#323ff0) center/100% calc(100% - 100px) no-repeat,
url(https://poppyvine.com/wp-content/uploads/2019/04/beach-bw.jpg) center/cover;
text-align: center;
background-blend-mode: multiply;
padding: 100px 0px;
}
.bkg-image .content {
color: #fff;
}
<div class="bkg-image">
<div class="content">
<h1>Margins to show bkg img<br>&<br>Content unaffected by blend mode</h1>
</div>
</div>
另一个相关问题:Isolation with CSS Mix-Blend-Modes: how to prevent elements from blending with parent
的解决方案答案 1 :(得分:1)
.bkg-image {
background-image: url(https://poppyvine.com/wp-content/uploads/2019/04/beach-bw.jpg);
text-align: center;
padding: 100px 0px;
background-size: cover;
background-position: center;
}
.overlay {
position: relative;
padding: 50px
}
.background {
background-color: #323ff0;
mix-blend-mode: multiply;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.content {
position: relative;
}
.bkg-image .content h1 {
color: white;
isolation: isloate;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>Test Blend Modes</title>
</head>
<body>
<h2>Live:</h2>
<div class="bkg-image">
<div class="overlay">
<div class="background"></div>
<div class="content">
<h1>Margins to show bkg img<br>&<br>Content unaffected by blend mode</h1>
</div><!-- content -->
</div><!-- multiply-overlay-->
</div><!-- bkg img -->
<h2>Should look like:</h2>
<img class="screencap" src="https://poppyvine.com/wp-content/uploads/2019/04/beach.jpg">
</body>
</html>
blended元素中的所有内容都会被混合,因此它们必须是兄弟姐妹。