为了使其正常工作,您需要在应用mix-blend-mode
. 因此,在您将应用的背景和文本之间,mix-blend-mode
您需要设置一个包装器isolation
。
这是一个示例,其中背景应用在h2
我们有很多内部和内部span
。我们mix-blend-mode
对它们进行应用,并在我们应用的地方用另一个包装器包装不需要的包装器isolation
:
h2 {
background: red;
}
h2 span {
mix-blend-mode: difference;
color: white;
}
.isolate {
isolation: isolate;
display: inline-block;
}
<h2>
<span>This text should</span>
<div class="isolate"><span>(This one shouldn't)</span></div>
<span> be blended</span>
</h2>
但是如果你mix-blend-mode
在 h2 上申请,你将无法隔离它的任何内容:
.red {
background: red;
}
h2 {
mix-blend-mode: difference;
}
h2 span {
color: white;
}
.isolate {
isolation: isolate;
display: inline-block;
}
<div class="red">
<h2>
<span>This text should</span>
<div class="isolate"><span>(This one shouldn't)</span></div>
<span> be blended</span>
</h2>
</div>