html - 如何使用 CSS 分割不同颜色的圆

标签 html css svg css-shapes

我希望能够用另一种颜色的一部分绘制一个圆,我希望所覆盖的部分的数量能够从 10% 的增量中增加>0%100%

Google 上的任何示例都是部门而不是分割。

Segments

到目前为止,这是我能想到的最好的:

div.outerClass {
    position: absolute;
    left: 10px;
    top: 10px;
    height: 2.5px;
    overflow: hidden;
    -ms-transform: rotate(270deg); /* IE 9 */
    -webkit-transform: rotate(270deg); /* Chrome, Safari, Opera */
    transform: rotate(270deg);
}

div.innerClass {
    width: 10px;
    height: 10px;
    border: 5px solid green;
    border-radius: 36px;
}
<div class="outerClass">
    <div class="innerClass"></div>
</div>

0%50%100% 我都能做到。

最佳答案

你可以使用linear-gradient

.circle{
  position:absolute;
  width:80px;
  height:80px;
  border-radius:50%;
  background: linear-gradient(
    to right,
    yellow  0%, yellow 10%,
    orange 10%, orange 20%,
    yellow 20%, yellow 30%,
    orange 30%, orange 40%,
    yellow 40%, yellow 50%,
    orange 50%, orange 60%,
    yellow 60%, yellow 70%,
    orange 70%, orange 80%,
    yellow 80%, yellow 90%,
    orange 90%, orange 100%
  );
}
<div class="circle"></div>

否则,您可以将 10 个子元素放入您的 overflow:hidden 圈子父元素中:

.circle{
  position:absolute;
  width:80px;
  height:80px;
  border-radius:50%;
  overflow:hidden;
}
.circle > span{
  width:10%;
  height:100%;
  float:left;
}

.circle > span:nth-child(1){ background: yellow;}
.circle > span:nth-child(2){ background: orange;}
.circle > span:nth-child(3){ background: blue;}
.circle > span:nth-child(4){ background: green;}
.circle > span:nth-child(5){ background: fuchsia;}
.circle > span:nth-child(6){ background: orange;}
.circle > span:nth-child(7){ background: gold;}
.circle > span:nth-child(8){ background: tan;}
.circle > span:nth-child(9){ background: navy;}
.circle > span:nth-child(10){background: brown;}
<div class="circle">
  <span></span><span></span><span></span><span></span><span></span>
  <span></span><span></span><span></span><span></span><span></span>
</div>

关于html - 如何使用 CSS 分割不同颜色的圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30413024/

相关文章:

html - Bootstrap Grid 在屏幕尺寸之间跳转

java - 如何构建一个可以通过全局移动通信系统 (GSM) 调用和接听电话的应用程序?

css - 使用 SVG 组件的 css 样式,使可见性为 "sticky"

html - 试图让 FlexBox 正确呈现的问题

css - 如何在 CSS 中记住边距在边框外,填充在边框内

html - Firefox/Chrome 上的字体大小和缩进不一致

css - 从 gnome-shell.css 文件破解 gnome 3

html - 每个浏览器对简单搜索字段的处理方式不同

html - iframe 中的 SVG 存在奇怪的不一致问题

html - 将 1 个超链接鼠标悬停在颜色上,而不是在 css 中,而是在 html 中