网页前端后台技巧(CSS+HTML)

Day.02.04 绝对定位简单案例

2017-02-04  本文已影响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
上一篇下一篇

猜你喜欢

热点阅读