CSS小技巧:粘滞定位+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 type="text/css">
      .pink {
        width: 200px;
        height: 200px;
        background-color: pink;
      }
      .lightblue {
        width: 200px;
        height: 100px;
        bottom: 100px;
        z-index: -1;
        position: sticky;
        background-color: lightblue;
      }
    </style>
  </head>
  <body>
    <div class="pink"></div>
    <div class="lightblue"></div>
    <div class="pink"></div>
    <div class="lightblue"></div>
    <div class="pink"></div>
  </body>
</html>
posted @ 2022-05-06 13:52  Theshy-Riven  阅读(78)  评论(0)    收藏  举报