isolation
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
尝试一下
该属性与 mix-blend-mode
和 z-index
结合使用时尤其有用。
语法
css
/* 关键字值 */
isolation: auto;
isolation: isolate;
/* 全局值 */
isolation: inherit;
isolation: initial;
isolation: revert;
isolation: revert-layer;
isolation: unset;
isolation
属性指定为下列关键字值之一。
值
形式定义
形式语法
isolation =
<isolation-mode>
<isolation-mode> =
auto |
isolate
示例
强制为元素创建新的层叠上下文
HTML
html
<div class="big-square ">
<div class="isolation-auto">
<div class="small-square">auto</div>
</div>
<div class="isolation-isolate">
<div class="small-square">isolate</div>
</div>
</div>
CSS
css
.isolation-auto {
isolation: auto;
}
.isolation-isolate {
isolation: isolate;
}
.big-square {
background-color: rgb(0, 255, 0);
width: 200px;
height: 210px;
}
.small-square {
background-color: rgb(0, 255, 0);
width: 100px;
height: 100px;
border: 1px solid black;
padding: 2px;
mix-blend-mode: difference;
}
结果
规范
Specification |
---|
Compositing and Blending Level 2 # isolation |
浏览器兼容性
BCD tables only load in the browser