原文地址: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: 0; padding: 0; 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: 0; 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: 1; --color: orangered; } .bows span:nth-child(2) { --n: 2; --color: orange; } .bows span:nth-child(3) { --n: 3; --color: yellow; } .bows span:nth-child(4) { --n: 4; --color: mediumspringgreen; } .bows span:nth-child(5) { --n: 5; --color: deepskyblue; } .bows span:nth-child(6) { --n: 6; --color: mediumpurple; }