以提问的方式,顺便说说我的理解
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>relative样式</title>
<style type="text/css">
#div1{
width:200px;
height:200px;
border:2px blue solid;
position:absolute;
left:110px;
top:60px;
}
#div2{
width:200px;
height:200px;
border:2px red solid;
position:relative;
left:100px;
top:50px;
}
</style>
</head>
<body>
<div id="div1">
<div id="div2"></div>
</div>
</body>
</html>蓝色框是position:absolute;
left:110px;
top:60px;意思是在网页上,绝对的位置,距左边110px距上边60px的位置。
而红色框position:relative;
left:100px;
top:50px;因为红色框div2是在蓝色框div1里面的,也就是1是2的父级,那么相对于div1,div2的位置就是相对蓝框左边100px,相对蓝框上边50px的位置。