具有三种不同边框颜色的圆圈
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>
是可能的,但我没有成功。
您可以使用 inline svg 实现 分为 3 个部分 的圆形边框:
- 一个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,8.38,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,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>
尝试使用 css Pseudo-elements 三种不同的边框颜色(相同长度)
* {
box-sizing: border-box
}
body {
margin: 0;
padding-top: 20px;
background: skyblue;
transition: background 0.6s ease
}
body:hover {
background: #CBE0E8
}
div {
box-shadow: inset 0 0 3px 0px #484848, 0 0 6px 0px #484848;
width: 150px;
height: 150px;
margin: 0 auto;
border-radius: 50%;
border-top: 10px solid green;
border-right: 10px solid red;
border-bottom: 10px solid red;
border-left: 10px solid green;
transform: rotate(15deg);
position: relative
}
div:before, div:after {
content: "";
position: absolute;
left: -10px;
top: -10px;
width: 100%;
height: 100%;
border-radius: 50%;
}
div:before {
border-top: 10px solid yellow;
border-right: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid transparent;
transform: rotate(60deg)
}
div:after {
border-top: 10px solid yellow;
border-right: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid transparent;
transform: rotate(30deg)
}
<div></div>
我有这个 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>
是可能的,但我没有成功。
您可以使用 inline svg 实现 分为 3 个部分 的圆形边框:
- 一个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,8.38,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,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>
尝试使用 css Pseudo-elements 三种不同的边框颜色(相同长度)
* {
box-sizing: border-box
}
body {
margin: 0;
padding-top: 20px;
background: skyblue;
transition: background 0.6s ease
}
body:hover {
background: #CBE0E8
}
div {
box-shadow: inset 0 0 3px 0px #484848, 0 0 6px 0px #484848;
width: 150px;
height: 150px;
margin: 0 auto;
border-radius: 50%;
border-top: 10px solid green;
border-right: 10px solid red;
border-bottom: 10px solid red;
border-left: 10px solid green;
transform: rotate(15deg);
position: relative
}
div:before, div:after {
content: "";
position: absolute;
left: -10px;
top: -10px;
width: 100%;
height: 100%;
border-radius: 50%;
}
div:before {
border-top: 10px solid yellow;
border-right: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid transparent;
transform: rotate(60deg)
}
div:after {
border-top: 10px solid yellow;
border-right: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid transparent;
transform: rotate(30deg)
}
<div></div>