定位:position,當(dāng)值為relative時可以設(shè)置left和right偏移量。
position 屬性值的含義:
static
元素框正常生成。塊級元素生成一個矩形框艇潭,作為文檔流的一部分,行內(nèi)元素則會創(chuàng)建一個或多個行框戏蔑,置于其父元素中蹋凝。
relative
元素框偏移某個距離。元素仍保持其未定位前的形狀总棵,它原本所占的空間仍保留鳍寂。
absolute
元素框從文檔流完全刪除,并相對于其包含塊定位情龄。包含塊可能是文檔中的另一個元素或者是初始包含塊迄汛。元素原先在正常文檔流中所占的空間會關(guān)閉,就好像元素原來不存在一樣骤视。元素定位后生成一個塊級框隔心,而不論原來它在正常流中生成何種類型的框。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>定位</title>
<style type="text/css">
.box1{
width: 100px;
height: 100px;
background-color: gold;
position:relative;
left: 100px;
}
.box2{
width: 100px;
height: 100px;
background-color: yellow;
}
.box3{
width: 100px;
height: 100px;
background-color: green;
position:relative;
left: 100px;
}
.box4{
width: 100px;
height: 100px;
background-color: green;
position:relative;
left: 200px;
}
/*相對定位不會影響文檔流*/
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2">
<div class="box4"></div>
</div>
<div class="box3"></div>
</body>
</html>