1、绝对定位和相对定位的区别:
position: absolute; 脱离原来位置进行定位;定位的参照物是离自己最近的有定位的父级,参照最近的有定位的父级进行定位,如果没有,那么相对文档进行定位
position: relative; 保留原来位置进行定位;定位的参照物是自己原来的位置,相对自己原来的位置进行定位
定位使用小经验:一般用relative来定位参照物,因为可以保留原有的位置,让自己不受影响
div.center的定位是使用固定定位position: fixed;
圆环的定位是用的绝对定位,参照物是父级div.center
left、top的值都是根据展示的样式计算的
z-index的数值决定层级的覆盖
2、圆环:
div + border + border-radius 结合制作圆环
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="./1.css" class="css">
<title>奥运五环</title>
</head>
<body>
<div class="center">
<div class="blue">
</div>
<div class="yellow">
</div>
<div class="black">
</div>
<div class="green">
</div>
<div class="red">
</div>
</div>
<div class="content"></div>
</body>
</html>
css
*{
margin: 0;
padding: 0;
}
div.center{
width: 800px;
height: 400px;
border: 1px solid #000;
position: fixed;
left: 50%;
top: 50%;
margin-left: -400px;
margin-top: -200px;
}
.center>div{
width: 100px;
height: 100px;
border-radius: 50%;
}
.blue{
border: 10px solid blue;
position: absolute;
left: 200px;
top: 150px;
}
.yellow{
border: 10px solid yellow;
position: absolute;
left: 275px;
top: 200px;
z-index: 1;
}
.black{
border: 10px solid black;
position: absolute;
left: 350px;
top: 150px;
}
.green{
border: 10px solid green;
position: absolute;
left: 425px;
top: 200px;
z-index: 1;
}
.red{
border: 10px solid red;
position: absolute;
left: 500px;
top: 150px;
}
/*制作滚动条*/
.content{
height: 10000px;
width: 10000px;
}