css - 如何创建四个四分之一的圆

标签 css

<分区>

是否可以仅使用 CSS 创建一个包含四个四分之一的圆圈?

我不能更进一步:

.circle {
  border-radius: 50%;
  width: 40px;
  height: 40px;
  colour: red;
}
<div class="circle">&nbsp;</div>

最佳答案

轻松...使用边框和旋转。

.circle {
  margin: 1em auto;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  box-sizing: border-box;
  border-width: 20px;
  border-style: solid;
  border-color: red green blue yellow;
  transform: rotate(45deg);
}
<div class="circle"></div>

你甚至可以有彩色的空心圆圈。

.circle {
  border-radius: 50%;
  width: 40px;
  height: 40px;
  box-sizing: border-box;
  border-width: 20px;
  border-style: solid;
  border-color: red green blue yellow;
  transform: rotate(45deg);
}
.wide {
  width: 100px;
  height: 100px;
}
<div class="circle wide"></div>

或者可能使用伪元素(不需要旋转),只是渐变。

*,
*::before,
*::after {
  box-sizing: border-box;
}
.circle {
  width: 100px;
  height: 100px;
  margin: 1em auto;
  position: relative;
  border-radius: 50%;
  overflow: hidden;
  border: 6px solid pink; /* borders on it too */
}
.circle::before,
.circle::after {
  content: '';
  position: absolute;
  height: 100%;
  width: 50%;
  top: 0;
}
.circle::before {
  left: 0;
  background: linear-gradient(green, green 50%, yellow 50%);
}
.circle::after {
  left: 50%;
  background: linear-gradient(red, red 50%, blue 50%);
}
<div class="circle"></div>

关于css - 如何创建四个四分之一的圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34955574/

上一篇:html - 这一长串CSS是什么?

下一篇:javascript - 如何按图库的 ID 过滤 div 元素

相关文章:

css - gulp-recess 不会改变属性顺序

javascript - 当输入类型文本小于 0 或大于 24 时,如何禁用输入类型按钮?

javascript - 两次设置属性背后的想法是什么,一次在 html 中,然后在 jquery 中?

css - 元素需要百分比高度,但实际数字无关紧要

javascript - 无法在网页上显示和隐藏雷达层

html - 一些CSS3动画解释

html - Bootstrap 背景图像无法在 iPhone 上调整大小

html - 根据内容自动调整div的高度

javascript - 如何在 HTML 中创建一个外观和功能类似于带线条的打印文本框的可编辑文本框?

javascript - 我们如何在淡入期间删除 Bootstrap 中模态的背景颜色?