標籤:
定位--->固定一個位置 (設定水平和垂直的距離)
一:固定定位
固定定位屬性: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之定位