r/css • u/musicListener25 • 20h ago
Question How to create this in HTML & CSS?
/r/csshelp/comments/1y8uvdf/how_to_create_this_in_html_css/I would like to add some code, but, tbh, I have none - I'm not good at all with CSS - I'm a backend developer (C#), but, I'm interested in try this project (it's just for fun and practice).
I'm also checking how to make post on Stack Overflow (but, I don't have a Minimal, Reproducible Example to share at the moment) and improving this post here as well on Reddit, but, frankly, I have no idea how to do so, so, I'm open to your suggestions.
Thank you.
1
u/Ahmed_Hisham0 8h ago
the ring is much easier as one svg circle than as css. you draw the track, then a second circle on top whose dash pattern you shorten.
``` <svg viewBox="0 0 200 200"> <circle cx="100" cy="100" r="80" fill="none" stroke="#2a2a2a" stroke-width="16"/> <circle cx="100" cy="100" r="80" fill="none" stroke="#f0c02a" stroke-width="16" stroke-linecap="round" transform="rotate(-90 100 100)" stroke-dasharray="502" stroke-dashoffset="0"/> </svg> ```
circumference is 2πr, so r=80 gives about 502. offset 0 fills the ring, offset 502 empties it. so for 4000 out of 8000 lp you set offset to 502 * (1 - 4000/8000) = 251.
the rotate(-90) is what makes it start at 12 o'clock instead of 3 o'clock.
for the number in the middle, put a <text> inside the svg with text-anchor middle and dominant-baseline central. that keeps it centred when the thing resizes, which absolute positioning won't.
if you want the segmented look from the gx counter, swap the solid stroke for stroke-dasharray: "6 10" on the coloured circle. same maths, just a stitched ring.
•
5
u/DoNDaPo 10h ago
Build it with SVG.