原文地址:https://segmentfault.com/a/1190000014682999
想到了扇形:正方形 -》border-radius: 50%; -》取四份中的任意一份。
不过如何取任意相关圆心角的扇形呢?
HTML代码:
<div class="circle"></div>
CSS代码:
html, body,.circle { margin: 0; padding: 0; height: 100%; display:flex; justify-content: center; align-items: center; } /* 优化代码 减少代码重复 */ .circle, .circle::before, .circle::after { border-width: 0.4em; border-style: solid; border-radius: 50%; /* 使左右透明 ,只剩上下弧 如何任意该弧所占圆心角呢? */ border-left-color: transparent; border-right-color: transparent; /* 动画名称 周期 节奏 循环次数 是否反向播放 */ animation: animate 4s ease-in-out infinite alternate; } .circle{ width:10em; height: 10em; border-top-color: red; border-bottom-color: blue; font-size: 20px; /* 定位会让其分离 */ position: relative; } .circle::before, .circle::after { content: ''; position: absolute; } .circle::before { width: 70%; height: 70%; border-top-color: orange; border-bottom-color: cyan; animation-duration: 8s; } .circle::after { width: 40%; height: 40%; border-top-color: yellow; border-bottom-color: limegreen; animation-duration: 16s; } @keyframes animate { from { transform: rotate(0deg); } to { transform: rotate(1440deg); } }