看上面的图,五个环是互相穿过,有遮挡的立体图案,不是直接平铺的。
主要思路:每个可见环都是两个环(本身环+伪元素环)重叠显示的,把伪元素环的z-index设置为1,使伪元素环浮在本身环的上面。然后把伪元素环某个方向的border-color设置为透明色transparent,使其透明,另一个可见环的颜色就会显示出来,从而实现被遮挡的效果。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>纯css实现奥运五环</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
.outer {
width: 500px;
margin: 100px auto;
}
.bottom-inner {
margin-top: -36px;
margin-left: 32px;
}
.box {
width: 50px;
height: 50px;
border: 5px solid;
border-radius: 50%;
display: inline-block;
position: relative;
}
.box::after {
content: "";
width: 50px;
height: 50px;
border: 5px solid;
border-radius: 50%;
display: inline-block;
position: absolute;
}
.blue {
border-color: #2196f3;
}
.blue::after {
border-color: #2196f3;
border-bottom-color: transparent; /*利用下边框色为透明,实现该部分被遮挡效果*/
z-index: 1;
top: -5px;
left: -5px;
}
.black {
border-color: black;
}
.black::after {
border-color: black;
border-left-color: transparent;
z-index: 1;
top: -5px;
left: -5px;
}
.red {
border-color: red;
}
.red::after {
border-color: red;
border-left-color: transparent;
z-index: 1;
top: -5px;
left: -5px;
}
.orange {
border-color: orange;
}
.orange::after {
border-color: orange;
top: -5px;
left: -5px;
}
.green {
border-color: green;
}
.green::after {
border-color: green;
border-top-color: transparent;
border-right-color: transparent;
z-index: 1;
top: -5px;
left: -5px;
}
</style>
</head>
<body>
<div class="outer">
<div class="top-inner">
<div class="box blue"></div>
<div class="box black"></div>
<div class="box red"></div>
</div>
<div class="bottom-inner">
<div class="box orange"></div>
<div class="box green"></div>
</div>
</div>
</body>
</html>