盒子重叠
一个盒子里面装满两个重叠盒子
通过将
.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;
本文介绍了使用CSS(如相对和绝对定位,z-index属性)控制HTML中的重叠盒子布局,以及如何通过z-index和3D旋转(translateZ)调整元素的显示顺序。
647

被折叠的 条评论
为什么被折叠?



