Day.02.04 绝对定位简单案例

作者: 挂树上的骷髅怪 | 来源:发表于2017-02-04 21:33 被阅读13次
    <!DOCTYPE html>
    <html>
     <head>
     <meta  charset="utf-8">
      <title> 绝对定位简单案例 </title>
        <style type="text/css">
            .div2{
                width:500px;
                height:400px;
                border:1px solid red;
                position:absolute;
                left:100px;
            }
            .div1{
                width:100px;
                height:50px;
                background-color:#ADE8C6;
                float:left;
                margin:5px;
    
            }
            .te{
                width:200px;
                height:100px;
                background-color:silver;
                float:left;
                position:absolute;/*绝对定位*/
                left:120px;
                top:300px;
            }
            .te1{
                width:100px;
                height:50px;
                background-color:#ADE8C6;
                position:relative;/*相对定位*/
                left:50px;
                top:50px;
            }
        </style>
     </head>
     <body>
        <div class="div2">
                <div class="div1">烟台</div>
            <div class="div te">
                <div class="te1">聊城</div>
            </div>
                <div class="div1">滕州</div>
                <div class="div1">德州</div>
        </div>
     </body>
    </html>
    
    

    小结:
    1.绝对定位的参考点,是上一级最近的非静态定位的盒子的左上角;
    2.如果他的上一级,没有非静态定位的盒子,则以浏览器的(body)的左上角为原点;
    3.绝对定位后,他的空间会让给其他元素来使用

    绝对定位.png

    相关文章

      网友评论

        本文标题:Day.02.04 绝对定位简单案例

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