<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<title>CSS左图右文混排布局</title>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
<style type="text/css">
* {
margin:0;
padding:0;
}
#container {
width:300px;
height:96px;
margin:0 auto;
margin-top:10px;
padding-right:3px;
border:1px dotted #666;
position:relative;
}
#leftContent {
width:106px;
height:86px;
border:solid 1px black;
position:absolute;
top:4px;
left:4px;
}
</style>
</head>
<body>
<div id="container">
<div id="leftContent"></div>
</div>
</div>
</body>
</html>
如果是运行上面代码的话,结果如下
小方框在大方框里
但是如果删掉position:relative;的话,结果如下
小方框和大方框分离了。我没有搞懂为什么 ,大神赐教。