定位position
1.将元素移动摆到想要的位置上去
2.可选值:
1.static:默认值,不打开定位
2.relative:相对定位
3.absolute:绝对定位
4.fixed:固定定位
相对定位relative
position:relative;
left: ;right: ;
top: ;bottom: ;
相对定位是相对于原来的位置移动,!给出的值不是移动方向
相对定位开启后没有脱离文档流
相对定位会让元素上升一个层级,移动的元素会盖住原来的元素
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style type="text/css">
.box1{
width: 200px;
height: 200px;
background-color: blueviolet;
}
.box2{
width: 200px;
height: 200px;
background-color:blue;
position: relative;
left: 100px;
bottom: 100px;
opacity: 0.5;/*可以设置透明度*/
}
.box3{
width: 200px;
height: 200px;
background-color: blanchedalmond;
position: relative;
left: 200px;
bottom: 200px;
opacity: 0.5;
}
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
</body>
</html>
效果: