与三种不同边界颜色的圈子 [英] Circle with three different border colors
问题描述
我有一个边框颜色的圆形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个部分。 org / en-US / docs / SVG_In_HTML_Introductionrel =nofollow> inline svg using:
- a 圈子元素
- 和 stroke-dasharray属性来创建部分
下面是一个示例:
svg {width:30%; height:auto;}
; svg viewbox =0 0 10 10> < defs> < circle id =circlecx =5cy =5r =4stroke-width =0.5fill =transparent/& < / defs> < use xlink:href =#circlestroke =pinkstroke-dasharray =0,2.09,8.38,30/> < use xlink:href =#circlestroke =greenstroke-dasharray =0,10.47,8.38,30/> < use xlink:href =#circlestroke =orangestroke-dasharray =2.09,16.75,6.3/>< / svg>
/ div>
编辑
要在圈子中添加文字, a href =https://developer.mozilla.org/en-US/docs/Web/SVG/Element/text =nofollow> svg文本元素:
svg {width:30%; height:auto;}
< svg viewbox =0 0 10 10> < defs> < circle id =circlecx =5cy =5r =4stroke-width =0.5fill =transparent/& < / defs> < use xlink:href =#circlestroke =pinkstroke-dasharray =0,2.09,8.38,30/> < use xlink:href =#circlestroke =greenstroke-dasharray =0,10.47,8.38,30/> < use xlink:href =#circlestroke =orangestroke-dasharray =2.09,16.75,6.3/> < text x =5y =6.5text-anchor =middlefont-size =5> 17< / text>< / svg>
I have this CSS for a circle with one border color:
.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>
It looks like this:
How should I change the CSS to have three border colors - as on the clock:
- from 0 to 4 color #1
- from 4 to 8 color #2
- from 8 to 12 color #3
I am sure, its possible, with element <canvas>
, but I am not successful with doing that.
You can achieve a circle border divided into 3 sections with an inline svg using:
- a circle element
- and the stroke-dasharray attribute to make the sections
Here is an example:
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,8.38,30" />
<use xlink:href="#circle" stroke="orange" stroke-dasharray="2.09,16.75,6.3" />
</svg>
Edit
To add text inside the circle, you can use the 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,2.09,8.38,30" />
<use xlink:href="#circle" stroke="green" stroke-dasharray="0,10.47,8.38,30" />
<use xlink:href="#circle" stroke="orange" stroke-dasharray="2.09,16.75,6.3" />
<text x="5" y="6.5" text-anchor="middle" font-size="5">17</text>
</svg>
这篇关于与三种不同边界颜色的圈子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!