css定位:相對定位

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   os   使用   sp   

關於相對定位的結論如下
1. 使用相對定位的盒子,會相對於它原來的位置,通過位移指定的距離,到達新的位置。
2.使用相對定位的盒子仍在標準流中,它對父塊和兄弟盒子沒有任何影響。

<html> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /> <title>無標題文檔</title> <style type=”text/css”>body{ margin:15px; font-family:Arial; font-size:12px; } .father{ background-color:#ffff99; border:1px solid #000000; padding:20px; } .father div{ background-color:#00ff00; padding:10px; border:1px dashed #000000; } #block2{}</style> </head> <body> <div class=”father”> <div>Box-1</div> <div id=”block2″>Box-2</div> <div>Box-3</div> </div> </body> </html>

static(靜態定位)為預設值,即在原本應該在的流布局上,從左至右,從上到下。

relative(相對定位),通過設定position屬性為relative,在設定具體方向的位移量來實現,top   left  right botton
修改代碼如下,即可發現box-2位移了,但對box-3沒影響,
#block2{
 position:relative;
 left:30;
 top:20;
 }

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.