Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:效果不错,继续加油
<!DOCTYPE html>
<html lang="zh-CN">
<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>
</head>
<body>
<ul>
<li class="one">item1</li>
<li class="two">item2</li>
</ul>
<div class="box">box</div>
</body>
</html>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
border: 5px solid red;
height: 20em;
}
ul {
border: 5px solid blue;
height: 14em;
width: 20em;
}
ul li {
border: 1px solid black;
list-style: none;
}
ul li:first-child {
background-color: yellow;
}
ul li:first-child + * {
background-color: violet;
}
ul li.one {
position: relative;
top: 10px;
left: 20px;
}
ul li.two {
position: absolute;
height: 200px;
width: 200px;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto auto;
}
.box {
border: 1px solid darkgreen;
background-color: greenyellow;
height: 150px;
width: 150px;
position: fixed;
right: 10px;
bottom: 10px;
}
</style>
relative:在原始位置上稍偏移位置。
absolute:在附近位置发生元素偏移。
rixed:在HTML块内偏移,不受文档限制