css怎么制作圆圈
使用 border-radius 属性制作圆圈
将元素的 border-radius 设置为 50%,可以将正方形元素变为圆形。同时需要确保元素的宽度和高度相等。
.circle {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: #3498db;
}
使用 clip-path 制作圆圈
clip-path 可以裁剪元素的形状,使用 circle() 函数可以直接生成圆形。
.circle {
width: 100px;
height: 100px;
clip-path: circle(50% at 50% 50%);
background-color: #e74c3c;
}
使用 SVG 绘制圆圈
SVG 提供 <circle> 标签,可以精确控制圆的大小和位置。
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" fill="#2ecc71" />
</svg>
使用伪元素生成圆圈
通过 ::before 或 ::after 伪元素,结合 border-radius 可以动态生成圆形。
.element::before {
content: "";
display: block;
width: 50px;
height: 50px;
border-radius: 50%;
background-color: #9b59b6;
}
使用 CSS 渐变制作空心圆圈
结合 border-radius 和 border 可以制作空心圆。
.hollow-circle {
width: 80px;
height: 80px;
border: 5px solid #f39c12;
border-radius: 50%;
background: transparent;
}
使用 box-shadow 制作多个圆圈
box-shadow 可以叠加多个阴影效果,生成多个同心圆。

.multi-circle {
width: 60px;
height: 60px;
border-radius: 50%;
background: #1abc9c;
box-shadow: 0 0 0 10px #16a085, 0 0 0 20px #27ae60;
}






