定位属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>position</title>
<style> .pos1{
position: fixed; background-color: yellow; height: 100px; width: 500px; } </style>
</head>
<body>
<div>前端</div>
<span>我是span</span>
<span>我是span</span>
<span>我是span</span>
<span>我是span</span>
<div class="pos1">我是一个定位元素</div>
</body>
</html>
相对定位
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>相对定位</title>
<style> .box1{
width:100px; height: 100px;background-color: aquamarine;} .box2{
width:100px; height: 100px;background-color: red; position: relative; left: 100px;} .box3{
width:100px; height: 100px;background-color: yellow;} </style>
</head>
<body>
<div class="box1">1号</div>
<div class="box2">2号</div>
<div class="box3">3号</div>
</body>
</html>
绝对定位
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>绝对定位</title>
<style> .phone1{
height: 100px; background-color: red; } .phone2{
height: 100px; background-color: rgb(165, 177, 165); position: absolute; z-index: 1; } .phone3{
height: 100px; background-color: blue; position: absolute; } .parent{
height: 300px; background-color: yellow; position: absolute; top: 0px; } .child{
height: 100px; background-color: red; width: 100px; } </style>
</head>
<body>
<div class="phone1">p40</div>
<div class="phone2">mate40</div>
<div class="phone3">p50</div>
<div class="parent">我是父元素
<div class="child">我是子元素</div>
</div>
</body>
</html>