在 CSS 中,clip-path
属性允许你创建复杂的裁剪路径,包括多边形。然而,clip-path
本身并不直接支持圆角边框。如果你想创建一个具有圆角边框的多边形,可以结合 clip-path
和 border-radius
属性来实现。
以下是一个示例,演示如何创建一个具有圆角边框的多边形:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Clip-Path with Rounded Corners</title>
<style>
.polygon {
width: 200px;
height: 200px;
background-color: #3498db;
clip-path: polygon(
50% 0%,
100% 25%,
100% 75%,
50% 100%,
0% 75%,
0% 25%
);
border-radius: 20px;
position: relative;
}
.polygon::before {
content: '';
position: absolute;
top: -20px;
left: -20px;
right: -20px;
bottom: -20px;
border: 10px solid #2980b9;
border-radius: 30px;
clip-path: polygon(
50% 0%,
100% 25%,
100% 75%,
50% 100%,
0% 75%,
0% 25%
);
}
</style>
</head>
<body>
<div class="polygon"></div>
</body>
</html>
.polygon
元素:clip-path: polygon(...)
创建一个六边形。border-radius: 20px
为元素添加圆角。::before
:.polygon
元素上。border
属性为伪元素添加边框。border-radius: 30px
为伪元素添加圆角。clip-path: polygon(...)
为伪元素创建一个六边形裁剪路径。clip-path
和 border-radius
的组合效果可能因浏览器的不同而有所不同,请确保在多个浏览器中进行测试。border-radius
值应比实际元素的 border-radius
值大,以确保边框的圆角效果。领取专属 10元无门槛券
手把手带您无忧上云