css制作圆孔
使用 CSS 制作圆孔的方法
方法一:使用 border-radius 创建圆形
通过设置元素的 border-radius 为 50%,可以将元素变为圆形。结合 width 和 height 控制圆的大小。
.circle {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: black;
}
方法二:使用 clip-path 创建圆孔
clip-path 可以裁剪元素为任意形状,包括圆形。这种方法适合更复杂的裁剪需求。

.circle-hole {
width: 100px;
height: 100px;
background-color: black;
clip-path: circle(50% at 50% 50%);
}
方法三:使用伪元素创建镂空圆孔
通过伪元素叠加实现圆孔效果,适合在背景上打孔。
.container {
position: relative;
width: 200px;
height: 200px;
background-color: lightgray;
}
.container::after {
content: "";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100px;
height: 100px;
border-radius: 50%;
background-color: white;
}
方法四:使用 box-shadow 创建环形圆孔

通过 box-shadow 的扩散效果模拟圆孔,适合需要发光或阴影的场景。
.ring {
width: 100px;
height: 100px;
border-radius: 50%;
box-shadow: 0 0 0 10px black;
}
方法五:使用 SVG 嵌入圆孔
通过 SVG 的 <circle> 元素实现圆孔,适合需要矢量图形的场景。
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" fill="black" />
</svg>
注意事项
- 圆孔的大小通过
width和height调整。 border-radius: 50%需确保元素的宽高相等。clip-path的兼容性较差,需检查目标浏览器支持情况。- 伪元素方法适合在复杂背景上创建圆孔效果。






