美文网首页
sticky粘性布局

sticky粘性布局

作者: 苍老师的眼泪 | 来源:发表于2022-04-20 03:53 被阅读0次

    相对它的最近滚动祖先和最近块级祖先基于top, right, bottom, 和 left的值进行偏移

    sticky.gif
    <!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>
        .wrapper {
          width: 200px;
          height: 400px;
          border: 1px solid coral;
          overflow: scroll;
        }
    
        .item {
          width: 180px;
          margin: 10px;
          border: 1px dotted cornflowerblue;
          text-align: center;
          line-height: 40px;
          height: 40px;
        }
    
        .item:nth-child(3n + 1) {
          position: sticky; 
          top: 0; 
          background-color: crimson;
        }
      </style>
    </head>
    
    <body>
    
      <div class="wrapper">
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
        <div class="item">4</div>
        <div class="item">5</div>
        <div class="item">6</div>
        <div class="item">7</div>
        <div class="item">8</div>
        <div class="item">9</div>
        <div class="item">10</div>
        <div class="item">11</div>
        <div class="item">12</div>
        <div class="item">13</div>
        <div class="item">14</div>
      </div>
    
    </body>
    
    </html>
    

    相关文章

      网友评论

          本文标题:sticky粘性布局

          本文链接:https://www.haomeiwen.com/subject/rhosertx.html