区别:
- z-index: 0 会创建一个新的层叠上下文
z-index: auto 不会去创建 - z-index: 0 会在 z-index: auto 遵守后来者居上层叠
<head>
<style>
.parent{
position: relative;
width: 300px;
height: 300px;
border: 1px solid #4c4c4c;
}
.box1,.box2,.box3 {
position: absolute;
width: 100px;
height: 100px;
}
.box1 {
background-color: hotpink;
}
.box2 {
background-color: khaki;
z-index: 0;
}
.box3 {
background-color: lightcoral;
z-index: auto;
}
</style>
</head>
<body>
<div class="parent">
<div class="box1">1</div>
<div class="box2">2</div>
<div class="box3">3</div>
</div>
</body>
将box2与box3的z-index数值交换,效果依然是box3在上面!