• CSS-15-定位


     1 <!DOCTYPE html>
     2 <html>
     3     <head>
     4         <meta charset="UTF-8">
     5         <title></title>
     6         <style type="text/css">
     7             /*定位:
     8                position:定位属性;
     9             /*relative:生成相对定位元素,元素所占据的文档流的位置不变,元素本身相对文档流的位置进行偏移*/
    10             /*absolute:生成绝对定位元素,元素脱离文档流,不占据文档流的位置,可以理解为漂浮在文档流的上方,相对于上一个设置了相对或者绝对或者固定定位的父级元素来进行定位;*/
    11             /*fixed:生成固定定位元素,元素脱离文档流,不占据文档流的位置,可以理解为漂浮在文档流的上方,相对于浏览窗口进行定位*/
    12             /*static:默认值,没有定位,元素出现在正常的文档流中,相对于取消定位属性或者不设置定位属性*/
    13             body{
    14                 margin: 0;
    15             }
    16             .position1{
    17                 width: 200px;
    18                 height: 200px;
    19                 background-color: yellowgreen;
    20                 text-align:center;
    21                 line-height:200px;
    22                 position: relative;
    23                 /*以元素本身当前位置为参考点*/
    24                 left: 100px;
    25                 top:100px
    26             }
    27             .position2{
    28                 width: 200px;
    29                 height: 200px;
    30                 background-color: yellow;
    31                 text-align:center;
    32                 line-height:200px;
    33                 position:absolute;
    34                 /*以设置了定位的父(爷...)级元素当前位置为参考点*/
    35                 left: 100px;
    36                 top:100px
    37             }
    38             .position3{
    39                 width: 200px;
    40                 height: 200px;
    41                 background-color: gray;
    42                 text-align:center;
    43                 line-height:200px;
    44                 position:fixed;
    45                 /*以浏览窗口为参考点,不会随滚动条的移动而移动*/
    46                 left: 300px;
    47                 top:300px
    48             }
    49             .fix{
    50                 width: 80px;
    51                 height: 20px;
    52                 line-height: 20px;
    53                 text-align: center;
    54                 background-color: gainsboro;
    55                 position: fixed;
    56                 /*以浏览窗口为参考点,不会随滚动条的移动而移动*/
    57                 bottom: 20px;
    58                 left: 50px
    59             }
    60         </style>
    61     </head>
    62     <body style="height: 5000px;">
    63         <div class="position1">
    64             box1
    65             <div class="position2">box2</div>
    66             <div class="position3">box3</div>
    67         </div>
    68         <div class="fix">
    69             返回顶部
    70         </div>
    71     </body>
    72 </html>
  • 相关阅读:
    Redis优化经验
    servlet/filter/listener/interceptor区别与联系
    无状态服务(stateless service)
    http请求中java中的302和sendRedirect的区别
    深入ThreadLocal之三(ThreadLocal可能引起的内存泄露)
    Connection reset原因分析和解决方案
    深入ThreadLocal之一
    ThreadLocal的坑--ThreadLocal跨线程传递问题
    MySQL通配符过滤
    六、Linux/UNIX操作命令积累【kill、netstat、df、du】
  • 原文地址:https://www.cnblogs.com/qinqin-me/p/11255863.html
Copyright © 2020-2023  润新知