相对定位的使用
定位
相对定位
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!--
相对定位
相对于自己原来的位置进行偏移
-->
<style>
div{
margin: 10px;
padding: 5px;
font-size: 12px;
line-height: 25px;
}
#father{
border: 1px solid #666;
padding: 0;
}
#first{
background-color: #ab123a;
border: 1px solid #ff3f2b;
position: relative;
top: -20px;
left: 20px;
}
#second{
background-color: #ffaf21;
border: 1px solid #8552ff;
}
#third{
background-color: #2f8bff;
border: 1px solid #931cff;
position: relative;
bottom: -10px;
right: 20px;
}
</style>
</head>
<body>
<div id="father">
<div id="first">第一个盒子</div>
<div id="second">第二个盒子</div>
<div id="third">第三个盒子</div>
</div>
</body>
</html>
相对定位:position:relative;
相对于原来的位置,进行指定的偏移,相对定位的话,它仍然在我们的标准文档流中,原来的位置会被保留
top: -20px;
left: 20px;
bottom: -10px;
right: 20px;

浙公网安备 33010602011771号