html部分:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>居中五环</title>
<link rel="stylesheet" href="lesson4.css">
</head>
<body>
<!-- 定宽的块元素居中的方式 margin 0 auto -->
<div class="content">
<div class="circle1"></div>
<div class="circle2"></div>
<div class="circle3"></div>
<div class="circle4"></div>
<div class="circle5"></div>
</div>
</body>
</html>
css部分:
.content{
position: absolute;
height: 186px;
width: 380px;
top: 50%;
left: 50%;
margin-top: -93px;
margin-left: -190px;
}
.circle1,.circle2,.circle3,.circle4,.circle5{
width: 100px;
height: 100px;
border: 10px solid black;
border-radius: 50%;
/* float: left; */
position: absolute;
}
.circle1{
border-color: red;
left: 0;
top: 0;
}
.circle2{
border-color: yellow;
left: 130px;
top: 0;
z-index: 3;
}
.circle3{
border-color: blue;
left: 260px;
top: 0;
}
.circle4{
border-color: green;
left: 65px;
top: 70px;
}
.circle5{
border-color: black;
left: 195px;
top: 70px;
}
效果图: