gpt4 book ai didi

html - 如何仅使用 CSS 制作 donut 片段

转载 作者:技术小花猫 更新时间:2023-10-29 11:55:44 25 4
gpt4 key购买 nike

如何让这个形状只使用css

doughnut segment CSS

我尝试过的:

.button-up {
border-top: 100px solid red;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top-left-radius: 50%;
border-top-right-radius: 50%;
border-bottom: 35px solid transparent;
width: 200px;
}
<div class="button-up"></div>

最佳答案

我会像这样使用一些linear/radial-gradient:

.box {
width:200px;
height:200px;
border-radius:50%;
background:
linear-gradient(-30deg, white 50%,transparent 50.5%),
linear-gradient(30deg, white 50%,transparent 50.5%),
radial-gradient(farthest-side at center,transparent 40%,blue 41%);
}
<div class="box">

</div>

还有边框:

.box {
width:200px;
height:200px;
border-radius:50%;
background:
linear-gradient(to top,white 58.5%,transparent 60%),
linear-gradient(-30deg, white calc(50% - 4px),green calc(50% - 4px) 50%,transparent 0),
linear-gradient(30deg, white calc(50% - 4px),green calc(50% - 4px) 50%,transparent 0),
radial-gradient(farthest-side at center,
transparent calc(42% - 5px),
green calc(42% - 4px) 42%,
blue 42% calc(100% - 4px),green calc(100% - 3px));
}
<div class="box">

</div>

你也可以考虑 SVG,这样会更简单:

<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64' width='300' height='300' fill='blue'>
<path stroke="green" stroke-width=1 d='M24 32 C28 28 37 28 40 32 L52 22 C38 8 26 8 12 22 Z' />
</svg>

这是另一个带有clip-path的想法:

.box {
width:200px;
height:200px;
border-radius:50%;
background:
radial-gradient(farthest-side at center,transparent 40%,blue 41%);
clip-path: polygon(0 0,0 10%, 50% 50%, 100% 10%,100% 0);
}
<div class="box">

</div>

相关问题:CSS Only Pie Chart - How to add spacing/padding between slices?

关于html - 如何仅使用 CSS 制作 donut 片段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49907944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com