(编辑:jimmy 日期: 2024/10/30 浏览:2)
实现思路
如图所示:
注意到的属性:
下面代码是绘制 33%的圆
<div class="circle-bar"> <div class="circle-bar-left"></div> <div class="circle-bar-right"></div> <div class="mask"> <span class="percent">33%</span> </div> </div>
.circle-bar { background-image: linear-gradient(#7affaf, #7a88ff); width: 182px; height: 182px; position: relative; } .circle-bar-left { background-color: #e9ecef; width: 182px; height: 182px; clip: rect(0, 91px, auto, 0); } .circle-bar-right { background-color: #e9ecef; width: 182px; height: 182px; clip: rect(0, auto, auto, 91px); transform: rotate(118.8deg); } .mask { width: 140px; height: 140px; background-color: #fff; text-align: center; line-height: 0.2em; color: rgba(0, 0, 0, 0.5); position: absolute; left: 21px; top: 21px; } .mask > span { display: block; font-size: 44px; line-height: 150px; } /*所有的后代都水平垂直居中,这样就是同心圆了*/ .circle-bar * { position: absolute; top: 0; right: 0; bottom: 0; left: 0; margin: auto; } /*自身以及子元素都是圆*/ .circle-bar, .circle-bar > * { border-radius: 50%; }