23、css的定位問題

來源:互聯網
上載者:User

標籤:

1、positon:relative相對定位

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>position:relative定位</title><style type="text/css">    html,body,div{                    margin:0;                       padding:0;                      list-style:none;    }    .center{                margin:30px;                border:#999999 solid 10px;                width:400px;                height:300px;                background:#FFFF00;    }    .div1{            width:200px;            height:150px;            background:#0099FF;            position:relative;/*相對於元素本身在文檔中應該出現的位置來移動這個元素*/            top:-20px;            left:0px;    }    .div2{            width:400px;            height:150px;            font-size:30px;            font-weight:bold;            color:#fff;            background:#FF0000;    }</style></head><body>    <div class="center">        <div class="div1">div1</div>        <div class="div2">div2 position:relative定位測試</div>    </div></body></html>

2、postion:absolute絕對位置

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>position:absolute定位</title><style type="text/css">    html,body,div{                    margin:0;                       padding:0;                      list-style:none;    }    .center{                margin:30px;                border:#999999 solid 10px;                width:400px;                height:300px;    }    .div1{            width:200px;            height:200px;            background:#0099FF;            /*設定TRBL  //設定了absolute之後,會相對於static定位以外的第一個父元素進行定位                1、當設定了left和top時會根據瀏覽器左上方來進行定位,                2、否則會根據其父元素的左上方來進行定位            */            position:absolute;            left:0px;            top:0px;    }    .div2{            width:400px;            height:300px;            font-size:30px;            font-weight:bold;            color:#fff;            background:#FF0000;    }</style></head><body>    <div class="center">        <div class="div1"></div>        <div class="div2">position:absolute定位測試</div>    </div></body></html>

 

23、css的定位問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.