html - 如何在 CSS 中绘制一个带有起始位置和结束位置(以度为单位)的圆形扇区

标签 html css geometry

我正在尝试创建一个圆形扇区。该扇区应在 CSS 中构建,并以度为单位测量起始位置和结束位置。

例如:startPosition: 155deg; endPosition: 245deg;

enter image description here

我试图在这里找到这个问题的答案: How to draw a circle sector in CSS?

但是没有一个答案真正对我有帮助。

这是我到目前为止的代码( http://jsfiddle.net/idoglik6/1mvgnsrc/ ):

.pivot-control {
  float: left;
  position: relative;
}
.pivot-control .pivot-container {
  border-radius: 50%;
  border-style: solid;
  border-width: 3px;
  border-color: #2e3d5d;
  box-sizing: border-box;
  background-color: #bcd0e7;
  width: 76px;
  height: 76px;
}
.pivot-control .pivot-container .pivot-circle {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}
.pivot-control .pivot-container .pivot-circle .pivot-hand {
  position: relative;
  background: #228ad5;
  height: 38px;
  left: 49%;
  top: 0;
  transform-origin: 50% 100%;
  width: 2px;
  box-shadow: 0 -2px 0 2px #fafafa;
}
<div class="pivot-control">
  <div class="pivot-container">
    <div class="pivot-circle">
      <div class="pivot-hand" >
      </div>
    </div>
  </div>
</div>

谢谢!

最佳答案

选项 1 此处摘录

div {
    width: 5em;
    height: 5em;
    display: block;
    border-radius:50%;
    background-color: green;
    border: 2px solid green;
    float: left;
    margin: 1em;
}


.test {
        background-image:
      /*add 90 to 245deg to get the END point to  */
        linear-gradient(335deg, transparent 50%,  #bcd0e7 50%),
      /*add 90 to 155deg to get the START point to  */
        linear-gradient(245deg,  #bcd0e7 50%, transparent 50%);
}
<div class="test"></div>

选项2

这里是片段

div {
    width: 5em;
    height: 5em;
    display: block;
    border-radius:50%;
    background-color: green;
    border: 2px solid green;
    float: left;
    margin: 1em;
}


.test {
    background-image:
      /*subtract 155 from 90 to get the start point*/
        linear-gradient(65deg, transparent 50%,  #bcd0e7 50%),
       /*subtract 245 from 90 to get the end point*/
        linear-gradient(155deg,  #bcd0e7 50%, transparent 50%);
}
<div class="test"></div>

关于html - 如何在 CSS 中绘制一个带有起始位置和结束位置(以度为单位)的圆形扇区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34796889/

相关文章:

css - 伪元素 : proper z-index stacking context?

css - 网站仅在 iPad 上被切断

检查多边形是否是多面体投影的算法

html - 顶部导航在 safari 中消失,在 IE、Mozilla 中显示

python - 使用 Python 抓取 .aspx 表单

html - 2 列表 - 将第 1 列文本堆叠到第 2 列

html - 侧边栏的 CSS float 属性(必要时我可以使用表格)

javascript - top navbar sticky 不适用于 Chrome 和 Safari,但适用于 mozilla

javascript - 如何为所有 SVG 元素添加相同的属性

c++ - 对于非常多的点,找出三角形上或三角形内的点数?