zoukankan      html  css  js  c++  java
  • 535 postition fixed和sticky

    https://www.zhangxinxu.com/wordpress/2020/03/position-sticky-rules/


    我的demo

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
      <style>
        * {
          margin: 0;
          padding: 0;
        }
    
        body {
          height: 2000px;
        }
    
        div:nth-child(1) {
           300px;
          height: 200px;
          background-color: pink;
          margin-bottom: 10px;
        }
    
        div:nth-child(2) {
          position: sticky;
          top: 20px;
           200px;
          height: 150px;
          background-color: yellowgreen;
        }
      </style>
    </head>
    
    <body>
      <div>111</div>
      <div>222</div>
    </body>
    
    </html>
    

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>sticky应用案例1 - 图片堆叠效果</title>
      <style>
        div {
          position: sticky;
          top: 0;
        }
      </style>
    </head>
    
    <body>
      <div>
        <img src="https://picsum.photos/id/10/480/360">
      </div>
      <div>
        <img src="https://picsum.photos/id/11/480/360">
      </div>
      <div>
        <img src="https://picsum.photos/id/12/480/360">
      </div>
      <div>
        <img src="https://picsum.photos/id/13/480/360">
      </div>
      <div>
        <img src="https://picsum.photos/id/14/480/360">
      </div>
    </body>
    
    </html>
    

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>sticky应用案例2 - 图片堆叠效果</title>
      <style>
        table {
          border-collapse: collapse;
        }
    
        th {
          position: sticky;
          top: 0px;
          height: 40px;
          background-color: hotpink;
        }
    
        td {
           200px;
          height: 40px;
          line-height: 40px;
          text-align: center;
        }
      </style>
    </head>
    
    <body>
      <img src="images/mm1.jpg" alt="">
      <img src="images/mm2.jpg" alt="">
      <table border="1">
        <thead>
          <tr>
            <th>Name</th>
            <th>Favorite Color</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
          <tr>
            <td>Bob</td>
            <td>Yellow</td>
          </tr>
          <tr>
            <td>Michelle</td>
            <td>Purple</td>
          </tr>
        </tbody>
      </table>
    </body>
    
    </html>
    
  • 相关阅读:
    《构建之法》阅读报告
    教务管理系统类图及数据库E/R图
    设计模式:抽象工厂
    结对项目:四则运算程序测试
    Leetcode笔记之57和为s的连续正数序列
    Leetcode笔记之1103分糖果 II
    Leetcode笔记之199二叉树的右视图
    每日Scrum(9)
    每日Scrum(7)
    每日Scrum(6)
  • 原文地址:https://www.cnblogs.com/jianjie/p/13776459.html
Copyright © 2011-2022 走看看