HTML:
<!DOCTYPE html PUBLIC> <html> <head> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" href="float.css" > <title></title> </head> <body> <div id="header"></div> <div id="mainbody"> <div class="box1">box1</div> <div class="box2">box2</div> <div class="box3">box3</div> </div> <div id="footer"></div> </body> </html>
css:
*{margin:0;padding:0}
li{list-style:none}
img{vertical-align:top;border:none}
#header
{
background-color: red;
height: 100px;
}
#mainbody
{
background-color: blue;
height: 800px;
width: 800px;
margin:0 auto;
}
#footer
{
background-color: black;
width: 800px;
height: 100px;
margin:0 auto;
}
.box1
{
height: 800px;
width: 300px;
float: left;
background-color: #B94FFF;
}
.box2
{
height: 800px;
width: 200px;
float: left;
background-color: #CCEEFF;
}
.box3
{
background-color: #00FFCC;
position: absolute;
top: 20px;
}box3绝对定位,无已定位祖先元素。但只设置了上方偏移量,按理说应该以浏览器为基准定位,可左边是与manbody的左边缘对齐的。如图:

CyanDK
慕的地8582982
Howseeker
滄浪之水
随时随地看视频慕课网APP