CSS定位

参考文章
文章中含有多个例子,试试就能明白。

例子:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  

<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
    <meta http-equiv="content-type" content="text/html; charset=utf-8">  
    <title>position</title>  
    <style type="text/css">  
    <!--  
    body{  
        font-size:12px;  
        margin:0 auto;  
    }  

    div#demo{  
        position:relative;  
        border:1px solid #000;  
        margin:50px;  
        top:-50px;  
        line-height:18px;  
        overflow:hidden;  
        clear:both;  
        height:1%;  
    }  

    div#sub{  
        position:absolute;  
        right:10px;  
        top:10px;  
    }  

    div.relative{  
        position:relative;  
        left:400px;  
        top:-20px;  
    }  

    div.static,div.fixed,div.absolute,div.relative{  
        width:300px;      
    }  

    div.static{  
        background-color:#bbb;  
        position:static;  
    }  

    div.fixed{  
        background-color:#ffc0cb;  
    }  

    div.absolute{  
        background-color:#b0c4de;  
    }  

    div.relative{  
        background-color:#ffe4e1;  
    }  
    -->  
    </style>  
</head>  
<body>  
    <div id="demo">  
        <div class="static">static: 默认值。无特殊定位,对象遵循HTML定位规则 </div>  
        <div id="sub" class="absolute">absolute: 将对象从文档流中拖出,使用left,right,top,bottom 等属性相对于其最接近的一个最有定位设置的父对象进行绝对定位。如果不存在这样的父对象,则依据body对象。而其层叠通过z-index属性定义 </div>  
        <div class="fixed">fixed:未支持。对象定位遵从绝对(absolute)方式。但是要遵守一些规范 </div>  
        <div class="relative">relative:对象不可层叠,但将依据 left,right,top,bottom 等属性在正常文档流中偏移位置 </div>  
    </div>  
</body>  
</html>  
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值