css之定位

來源:互聯網
上載者:User

標籤:

定位--->固定一個位置             (設定水平和垂直的距離)

 

一:固定定位
固定定位屬性:position:fixed;
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>

div{
width: 200px;
height: 200px;

}
.one{
background-color: #288dd1;
position: fixed;
width: 200px;
height: 200px;
left: 200px;
top:200px;

}
.two{
background-color:#ff8500;
left: 300px;
top:300px;
}
</style>
</head>
<body>
<span class="one">uyuyu

</span>
<!--<div class="one"></div>-->
<div class="two"></div>

</body>
</html>
特點 1:不佔據原來標準流的位置 2:可以模式轉換 3:定位的基準是以瀏覽器為基準的
二:絕對位置
絕對位置屬性:position:absolute;<!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8">    <title></title>    <style>        div{            height: 200px;            width: 200px;        }        .one{            background-color: #ff8500;            position: absolute;            left: 300px;            top:300px;            height: 200px;            width: 200px;        }        .two{            background-color: #288dd1;            top: 200px;            left: 200px;        }    </style></head><body><span class="one"></span><!--<div class="one"></div>--><div class="two"></div></body></html>特點1:不佔據原來標準流的位置2:可以模式轉換3:如果設定了父元素的定位,絕對位置是相對於父元素而言的,否則就是相對於瀏覽器
三:相對定位
相對定位的屬性:position:relative;<!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8">    <title></title>    <style>        div{            height: 200px;            width: 200px;        }        .one{            background-color: #288dd1;            position: relative;            top: 200px;            left: 200px;        }        .two{            background-color: #ff8500;            top: 300px;            left:300px;                    }    </style></head><body><div class="one"></div><div class="two"></div></body></html>特點1:佔據原來在標準流中的位置2:不能模式轉換3:定位是相對於標準流的位置而言的
四 :靜態定位
靜態定位屬性:position:static;<!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8">    <title></title>    <style>        div{            height: 200px;            width: 200px;        }        .one{            background-color: #ff8500;            top: 200px;            left: 200px;            position: static;        }        .two{            background-color: #288dd1;            top: 200px;            left: 200px;        }    </style></head><body><div class="one"></div><div class="two"></div></body></html>特點1:佔據原來的位置2:不能模式轉換3:定位怎麼設定都沒有效果,靜態定位就是標準流(預設)

 

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.