27.纯 CSS 创作一个精彩的彩虹 loading 特效

时间:2023-03-09 01:49:40
27.纯 CSS 创作一个精彩的彩虹 loading 特效

原文地址:https://segmentfault.com/a/1190000014939781

感想:正方形-》圆-》旋转一定角度-》动画-》隐藏下一半

HTML代码:

<div class="rainbow">
<div class="bows">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>

CSS代码:

html, body, .bows {
margin:;
padding:;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background: white;
}
.rainbow {
width: 20em;
height: 10em;
overflow: hidden;
}
.bows {
position: relative;
width: 100%;
height: 200%;
/* border: 1px solid blue; */
transform: rotate(225deg);
}
.bows span {
position: absolute;
width: calc(100% - 2em * (var(--n) - 1));
height: calc(100% - 2em * (var(--n) - 1));
padding:;
border: 1em solid var(--color);
box-sizing: border-box;
border-top-color: transparent;
border-left-color: transparent;
border-radius: 50%;
animation: rotating 3s infinite;
animation-delay: calc(0.05s * var(--n));
}
@keyframes rotating {
0%, 20% {
transform: rotate(0deg);
}
80%, 100% {
transform: rotate(360deg);
}
}
.bows span:nth-child(1) {
--n:;
--color: orangered;
}
.bows span:nth-child(2) {
--n:;
--color: orange;
}
.bows span:nth-child(3) {
--n:;
--color: yellow;
}
.bows span:nth-child(4) {
--n:;
--color: mediumspringgreen;
}
.bows span:nth-child(5) {
--n:;
--color: deepskyblue;
}
.bows span:nth-child(6) {
--n:;
--color: mediumpurple;
}