为蓝色div分配更高的z-index值,为红色div分配更低的z-index值将导致以下 结果:
.blue { background-color: #8EC4D0; margin-bottom: 15px; width: 120px; height: 120px; color: #FFF; z-index: 30; position: relative; } .red { background-color: #FF4D4D; position: relative; width: 120px; height: 120px; color: #FFF; margin-top: -50px; margin-left: 50px; z-index: 20; position: relative; }
结果: