Here is a simple option with SVG
, tried to leave in the most didactic way possible, the idea is to use a "dotted line" on the edge of a circle svg
and how the stroke-dasharray
and the stroke-dashoffset
vc controls the chart fill. It’s nothing too complex, and you can control all properties with JS and CSS. Everything is centralized with flex
in the container
and position:absolute
in children.
Enjoy and includes an option animating the stroke-dashoffset
for you to see how easy it is to animate the chart just using CSS with @keyframes
Segment the image code above.
body {
display: flex;
}
.graph {
text-align: center;
width: 100px;
height: 100px;
line-height: 60px;
text-transform: uppercase;
font-family: sans-serif;
text-decoration: none;
font-size: 14px;
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
svg {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
fill: transparent;
stroke-width: 12px;
stroke: #ddd;
}
.graph svg.cor {
stroke: green;
stroke-dasharray: 255;
stroke-dashoffset: 55;
transform: rotate(-90deg);
transform-origin: center;
}
.graph svg.cor-anim {
stroke: red;
stroke-dashoffset: 255;
animation: anim 5s infinite;
}
@keyframes anim {
45% {
stroke-dashoffset: 55;
}
55% {
stroke-dashoffset: 55;
}
}
<div class="graph">
<svg>
<circle cx="50" cy="50" r="40" />
</svg>
<svg class="cor">
<circle cx="50" cy="50" r="40" />
</svg>
Btn
</div>
<div class="graph">
<svg>
<circle cx="50" cy="50" r="40" />
</svg>
<svg class="cor cor-anim">
<circle cx="50" cy="50" r="40" />
</svg>
Btn
</div>
In this answer you have more details in a similar model only in a rect
in the hover
of link
: Partially paint edge in css
And in this other one there’s something similar only with CSS, and as you can see in the future with conic-gradiente
you will be able to do this only with CSS: How could you make a Pacman by moving your mouth with pure CSS?
But you want it in canvas or CSS? And SVG is an option?
– hugocsl
In fact, I accept suggestions
– adventistaam
It can be in a way that I can color dynamically
– adventistaam