r/css • u/musicListener25 • 5d 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.
2
Upvotes
6
u/DoNDaPo 5d ago
Build it with SVG.
3
u/equinusocio 5d ago
Divs with gradients and SVG masks.
2
u/Ahmed_Hisham0 5d 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.
2
u/yihuaxiang 4d ago
The SVG ring advice above is the way to go for the circular meter. For the left gauge and the color change at 4000, I'd keep one value in a CSS variable (like --lp: 1300) and derive the bar height from that with calc(), then toggle a class or a second variable when the value crosses 4000 so the fill switches to blue. That way the number, the bar, and the ring all stay in sync when LP changes instead of updating three separate things.
2
u/Evgenii_Korolev 3d ago •
the ring's already been answered, for the left gauge you can get away with one custom property and clip-path, no svg needed:
then from js just do
el.style.setProperty('--lp', lp)and toggle.overwhen lp goes above 4000. swap the colors to match.