盒子重叠
一个盒子里面装满两个重叠盒子
通过将
.fa
定位为相对定位,并将.son1
和.son2
定位为绝对定位,您可以确保两个子元素充满.fa
父容器,并根据需要进行调整。请注意,这可能会在一些情况下导致重叠或溢出,要让第二个子盒子.son2
在层叠顺序上显示在第一个子盒子.son1
前面,您可以使用z-index
属性。较高的z-index
值将使元素显示在较低值的元素之前。请注意,z-index
属性仅在定位元素上(具有position
属性的元素)才有效
<style>
.fa{
width: 200px;
position: relative;
height: 200px;
background-color: blue;
}
.son1 ,.son2{
position: absolute;
width: 100%;
height: 100%;
}
.son1{
background-color: yellow;
z-index: 2;
}
.son2{
background-color: antiquewhite;
z-index: 3;
}
</style>
</head>
<body>
<div class="fa">
<div class="son1">1</div>
<div class="son2">2</div>
</div>
</body>
重叠盒子优先显示
利用3D旋转——z轴
语法: transform: translateZ(1px);
利用2D用 z-index属性
语法: z-index: 999;