定位=定位模式+边偏移
值 语义
static 静态定位
relative 相对定位
absolute 绝对定位
fixed 固定定位
相对定位:
相对定位是元素在移动位置的时候,是相对 他原来的位置 来说的
语法:
选择器{
position:relative;
}
相对定位-特点:
1、他是相对于自己原来的位置移动的
2、原来在标准流的位置继续占有,后面的盒子仍然以标准流的方式对待他
举例证明:
定义了二个盒子
<style>
.box1{
/* -----加相对定位了------- */
/* position: relative;
top: 150px;
left: 60px; */
width: 200px;
height: 200px;
background-color: aquamarine;
}
.box2{
width: 200px;
height: 200px;
background-color: plum;
}
</style>
正常运行效果:
加上浮动的效果:
很明显盒子发生了移动