position:absolute;
left:0px;
right:0px;
top:0px;
bottom:0px;
left:0px;
right:0px;
top:0px;
bottom:0px;
设置布满整个父范围,设置了absolute的元素可以通过以上4个属性来展开面,relative的不行
position:absolute;可以实现面拉伸,定位的效果
position是相对于最外层边界,这个边界不包括是除掉margin与border的部分
width是指内容区域
position:absolute;
left:0px;
right:0px;
width:100%;
<div id="body2">
<div id="main2"></div>
</div>
<div id="main2"></div>
</div>
#main2{
position:absolute;
left:0px;
right:0px;
height:10px;
background:orange;
}
position:absolute;
left:0px;
right:0px;
height:10px;
background:orange;
}
#body2{
padding:5px;
width:800px;
height:40px;
margin:10px auto;
border:10px solid black;
position:relative;
background:red;
padding:5px;
width:800px;
height:40px;
margin:10px auto;
border:10px solid black;
position:relative;
background:red;
}
position:absolute;
width:100%; 浮动了位置会随意
不设置(不浮动)
position:absolute;
left:0px;
right:0px;
left:0px;
right:0px;
设置
position:absolute;
left:0px;
right:0px;
left:0px;
right:0px;