css – 具有三种不同边框颜色的圆圈

我有一个带有一种边框颜色的圆圈的CSS:
.circle {
  border: 6px solid #ffd511;
  border-radius: 30px;
  -moz-border-radius: 30px;
  -webkit-border-radius: 30px;
  -khtml-border-radius: 30px;
  width: 30px;
  height: 18px;
  line-height: 20px;
  padding: 12px 6px;
  text-align: center;
}
<div class="circle">17</div>

它看起来像这样:

我应该如何将CSS更改为具有三种边框颜色 – 如同时钟:

>从0到4颜色#1
> 4至8色#2
>从8到12颜色#3

我确定,它可能,元素< canvas>,但我没有成功做到这一点.

解决方法

您可以使用以下方法一个圆形边框分成3个部分,使用 inline svg

> a circle element
>和stroke-dasharray attribute制作章节

这是一个例子:

svg{width:30%;height:auto;}
<svg viewBox="0 0 10 10">
  <defs>
    <circle id="circle" cx="5" cy="5" r="4" stroke-width="0.5" fill="transparent" />
  </defs>
  <use xlink:href="#circle" stroke="pink" stroke-dasharray="0,2.09,8.38,30" />
  <use xlink:href="#circle" stroke="green" stroke-dasharray="0,10.47,30" />
  <use xlink:href="#circle" stroke="orange" stroke-dasharray="2.09,16.75,6.3" />
</svg>

编辑

要在圆圈内添加文字,您可以使用svg text element

svg{width:30%;height:auto;}
<svg viewBox="0 0 10 10">
  <defs>
    <circle id="circle" cx="5" cy="5" r="4" stroke-width="0.5" fill="transparent" />
  </defs>
  <use xlink:href="#circle" stroke="pink" stroke-dasharray="0,6.3" />
  <text x="5" y="6.5" text-anchor="middle" font-size="5">17</text>
</svg>

相关文章

Css3如何实现鼠标移上变长特效?(图文+视频)
css3怎么实现鼠标悬停图片时缓慢变大效果?(图文+视频)
jquery如何实现点击网页回到顶部效果?(图文+视频)
css3边框阴影效果怎么做?(图文+视频)
css怎么实现圆角边框和圆形效果?(图文+视频教程)
Css3如何实现旋转移动动画特效