CSS: display

复制代码
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    div {
      position: absolute;
      width: 100px;
      height: 100px;
    }

    div:nth-of-type(1) {
      background-color: palegreen;
      left: 0;
      top: 0;
      z-index: 1;
    }

    div:nth-child(2) {
      left: 20px;
      top: 20px;
      background-color: peru;
      z-index: 2;
    }

    div:nth-child(3) {
      left: 40px;
      top: 40px;
      background-color: plum;
      z-index: 3;
    }

    div:nth-child(4) {
      left: 60px;
      top: 60px;
      background-color: aqua;
      z-index: 4;
    }

    div:nth-of-type(5) {
      left: 80px;
      top: 80px;
      background-color: rebeccapurple;
      z-index: 5;
    }
  </style>
</head>

<body>
  <div>01</div>
  <div>02</div>
  <div>03</div>
  <div>04</div>
  <div>05</div>
</body>

</html>
复制代码

 

 

z-index

 

 取决于父元素z-index

复制代码
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .b1,
    .b2 {
      width: 100px;
      height: 100px;
      background-color: palegreen;
    }

    .b2 {
      background-color: peru;
    }

    .c1 {
      position: relative;
      z-index: 5;
    }

    .c2 {
      position: relative;
      z-index: 10;
      left: 50px;
      top: 50px;
    }

    .b1 {
      position: absolute;
      z-index: 100;
    }

    .b2 {
      position: absolute;
      z-index: 50;
    }
  </style>
</head>

<body>
  <div class="c1">
    <div class="b1"></div>
  </div>
  <div class="c2">
    <div class="b2"></div>
  </div>
</body>

</html>
复制代码

 

posted @   ascertain  阅读(44)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示