本文介绍了从子元素中删除混合混合模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在一个元素上设置混合混合模式,但不是它的孩子?将子项设置为默认值 normal
似乎不起作用:
How can I set mix-blend-mode on an element, but not it's children? Setting the children to the default value of normal
does not seem to work:
推荐答案
解决方案如何避免 mix-blend-mode
效果儿童:
The solution how to avoid mix-blend-mode
effects children:
- 使子元素位置相对,赋予其宽度和高度;
- 在绝对位置的子对象内创建一些真实或伪元素,并应用
mix-blend-mode
到它; - 在孩子内为您的内容创建
inner
元素。将它置于绝对位置,并将其放在其他元素之上;
- Make child element position relative, give it width and heigh;
- Create some real or pseudo element inside the child with absolute position, and apply
mix-blend-mode
to it; - Create
inner
element inside the child for your content. Make it's position absolute, and put it on top of other elements;
html
<div class="bkdg">
<div class="blend">
<div class="inner">
<h1>Header</h1>
</div>
</div>
</div>
css
.blend {
position: relative; // Make position relative
width: 100%;
height: 100%;
}
.blend::before { // Apply blend mode to this pseudo element
content: '';
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
z-index: 1;
background-color: green;
mix-blend-mode: multiply;
}
.inner { // This is our content, must have absolute position
position: absolute;
z-index: 2;
}
h1 {
color: white;
}
这篇关于从子元素中删除混合混合模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!