4

我正在尝试使用混合混合模式来创建具有多重效果叠加的背景,该叠加也显示了部分背景。我还需要子内容不受混合模式的影响。像这样:

混合模式,子内容不受影响

我尝试将混合模式设置为未设置,我也尝试使用隔离/隔离,但似乎无法使该选项起作用。我不想使用伪元素或将内容放在父元素之外,因为设计师的实际布局有很多内容,我需要它来响应。

到目前为止我已经能够工作: 我可以让背景和覆盖工作,但影响也适用于内容层: 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 -->  

有谁知道是否有可能实现这一目标?

4

2 回答 2

3

.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> 

混合元素内的任何内容都将被混合,因此它们需要是兄弟姐妹。

于 2019-04-08T12:30:24.577 回答
2

正如我在上一个答案中已经解释的那样,隔离不会以这种方式工作,并且您无法在应用后隔离内容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

使用伪元素的解决方案:混合混合模式乘以保持文本不透明?

于 2019-04-08T12:22:13.227 回答