仅CSS的饼图百分比
我发现“百分比饼图”非常不错,只想使用CSS创建它。无需动画。只是静态的“图片”。
我明白如果我想创建此类图表,我需要使用
问题是
- 如何创建元素#2?
- 如何管理较小(5%)或更高百分比(80%)值的元素2的形状?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我发现“百分比饼图”非常不错,只想使用CSS创建它。无需动画。只是静态的“图片”。
我明白如果我想创建此类图表,我需要使用
问题是
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
嘿,您可以添加小型CSS样式
html
js:自动显示填充的百分比,
我创建了示例
Hey gus you can add small CSS styles
HTML
JS : display the % of filling automatically
I created sample https://codepen.io/arun-b-shet/pen/mdVVWXo
借助现代技术,我们可以改进代码。您可以拥有圆形的边缘并考虑动画:
以及带有渐变色的版本,您也可以在我的网站上找到: https:https:https:https:https:https:https:https: //css-shape.com/arc/
旧答案
您可以在多个背景下完成此操作。
从
0%
到50%
:从
50%
到100%
:您可以将两者结合起来:
现在,我们可以像以下那样优化以考虑percetange值:
相关的问题要获得另一个版本:使用CSS创建静态饼图
我们也可以考虑<代码>掩码添加透明度:
也喜欢以下:
相关:带边框半径的边界梯度
With modern techniques we can improve the code. You can have rounded edges and also consider animation:
And a version with gradient coloration that you can also find on my website: https://css-shape.com/arc/
Old answer
You can do this with multiple background.
From
0%
to50%
:From
50%
to100%
:You can combine both like this:
Now we can optimize like below to consider percetange value:
Related question to get another version: Creating a static pie chart with CSS
We can also consider
mask
to add transparency:Also like below:
Related: Border Gradient with Border Radius
使用新的 圆锥梯度 ,这可以用单个DIV来管理,该DIV刚刚降落在Chrome中作为实验属性。
结果的图像
感谢Temani Afif,可以使用边框和利用
background-clip
...Using the new conic gradient, this can be managed with a single div which just landed in Chrome as an experimental property.
Image of Result
With thanks for Temani Afif it's possible to achieve this without the pseudo element using a border and leveraging
background-clip
...