相对对位:relative
相对于自身原本所在位置,通过上右下左设置偏移值进行移动,原有位置保留。
绝对定位:absolute
相对于最近的一个position不为static的元素定位,通过上右下左偏移,原有位置消失,脱离文档流。
固定定位:fixed
相对于窗口定位,移出文档流,上右下左偏移。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文档标题</title>
</head>
<body>
<div class="div1">
<div class="div1-1"></div>
<div class="div1-2"></div>
</div>
</body>
</html>
.div1{
border:1px solid black;
width:500px;
height:500px;
position:relative;
}
.div1-1{
top:0;bottom:0;left:0;right:80%;
background:blue;
position:absolute;
}
.div1-2{
position:absolute;
top:0;bottom:80%;left:20%;right:0;
background:red;
}
.div2{
border:1px solid black;
width:200px;
height:200px;
}