可以用left、right来描述盒子右、左的移动;
可以用top、bottom来描述盒子的下、上的移动。
↘:(右下)
position: relative;
top: 10px;
left: 40px;
↙:(左下)
position: relative;
right: 40px;
top: 10px;
↖:(左上)
position: relative;
right: 40px;
bottom: 10px;
↗:(右上)
position: relative;
right: -40px;
top: -40px;
等价于:
position: relative;
right: -40px;
bottom: 40px;
<style>
*{
margin: 0;
padding: 0;
}
.parent{
width: 600px;
height: 600px;
margin: 0 auto;
margin-top: 30px;
border: 8px solid blue;
}
.son{
width: 260px;
height: 260px;
background-color: orange;
/* 相对定位的定位值 */
position: relative;
/* 右下 */
/* top: 30px;
left: 50px; */
/* 左下 */
/* top: 10px;
right: 40px; */
/* 左上 */
/* right: 40px;
bottom: 10px; */
/* 右上 */
right: -40px;
bottom: 30px;
}
.son2{
width: 260px;
height: 260px;
background-color: pink;
}
</style>
</head>
<body>
<div class="parent">
<div class="son"></div>
<div class="son2"></div>
</div>
</body>
预览