3 个回答

SVG:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>SVG</title>
        <link rel="styleSheet" type="text/css" href="./style.css">
    </head>
    <body>
        <svg width="500" height="500">
            <polygon points="100,30 140,50 140,90 100,110 60,90 60,50" style="fill: transparent;stroke: #e07cc2; stroke-width:3px;"></polygon>
        </svg>
    </body>
</html>     

image.png

<!DOCTYPE html>
<html>
<head>
<style>
  .hexagon-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px; /* 调整容器高度以适应你的需要 */
  }

  .hexagon {
    position: relative;
    width: 100px; /* 调整六边形大小 */
    height: 100px; /* 计算六边形高度,可以根据需要进行调整 */
    background-color: pink;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  }

  .hexagon:before {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 96px;
    height: 96px;
    background-color: #fff;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  }
</style>
</head>
<body>

<div class="hexagon-container">
  <div class="hexagon"></div>
</div>

</body>
</html>

image.png

.hexagon {
  position: relative;
  width: 100px;
  height: 58px;
  background-color: transparent;
  border-left: 1px solid transparent;
  border-right: 1px solid transparent;
}

.hexagon::before,
.hexagon::after {
  content: "";
  position: absolute;
  width: 0;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
}

.hexagon::before {
  top: -29px;
  border-bottom: 29px solid transparent;
}

.hexagon::after {
  bottom: -29px;
  border-top: 29px solid transparent;
}

<div class="hexagon">
  
</div>
.hexagon {
            width: 100px;
            height: 100px;
            background-color: skyblue;
            position: relative;
            border-top: none;
            border-bottom: none;
        }

        .hexagon::before {
            content: "";
            width: 0px;
            height: 0px;
            margin: 100px auto;
            border-bottom: 50px solid #000;
            border-left: 50px solid transparent;
            border-right: 50px solid transparent;
            border-top: 50px solid transparent;
            position: absolute;
            top: -200px;
        }

        .hexagon::after {
            content: "";
            width: 0px;
            height: 0px;
            margin: 100px auto;
            border-bottom: 50px solid #000;
            border-left: 50px solid transparent;
            border-right: 50px solid transparent;
            border-top: 50px solid transparent;
            position: absolute;
            transform: rotate(180deg);
        }

<div class="hexagon"></div>
一个盒子加调整伪元素的位置 ,自己改改颜色和宽度就行

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏