css制作园
使用CSS制作圆形的方法
通过CSS可以轻松创建圆形,主要利用border-radius属性。以下是几种常见的实现方式:
基本圆形
设置元素的width和height相等,并将border-radius设为50%:
.circle {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: #3498db;
}
使用aspect-ratio保持比例
现代浏览器支持aspect-ratio属性,可确保宽高比始终为1:1:

.circle {
width: 100px;
aspect-ratio: 1/1;
border-radius: 50%;
background: linear-gradient(to right, #ff7e5f, #feb47b);
}
通过伪元素创建圆形
利用::before或::after伪元素生成圆形,无需额外HTML标签:
.element::before {
content: "";
display: block;
width: 50px;
height: 50px;
border-radius: 50%;
background-color: #2ecc71;
}
带边框的圆形
添加border属性可创建环形效果:

.ring {
width: 80px;
height: 80px;
border-radius: 50%;
border: 5px solid #e74c3c;
background-color: transparent;
}
响应式圆形
使用百分比或vw/vh单位创建响应式圆形:
.responsive-circle {
width: 20vw;
height: 20vw;
max-width: 200px;
max-height: 200px;
border-radius: 50%;
background-color: #9b59b6;
}
圆形渐变效果
结合CSS渐变创建更复杂的视觉效果:
.gradient-circle {
width: 120px;
height: 120px;
border-radius: 50%;
background: radial-gradient(circle, #1abc9c, #16a085);
}
注意事项
- 确保父容器有足够空间显示完整圆形
- 在旧版浏览器中测试
border-radius的兼容性 - 使用
overflow: hidden可裁剪超出圆形的部分内容 - 通过
box-shadow可为圆形添加投影增强立体感






