<分区>
标签 css
<分区>
是否可以仅使用 CSS 创建一个包含四个四分之一的圆圈?
我不能更进一步:
.circle {
border-radius: 50%;
width: 40px;
height: 40px;
colour: red;
}
<div class="circle"> </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/