How to draw an equilateral hexagon with a border

problem description

take a look at the demo on the Internet are all nesting with div and then transform, but this does not support the emergence of borders, only borders should be how to draw?

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?


<!-- html  -->
<div class='div'></div>
<style>

.div {
    position: relative;
    width: 50px;
    height: 86.6px;
    margin: 50px auto;
    background-color: red;
}
.div:before {
    content: '';
    display: block;
    position: absolute;
    width: 0;
    height: 0;
    right:50px;
    border-width: 43.3px 25px;
    border-style: solid;
    border-color: transparent red transparent transparent;
}
.div:after {
    content: '';
    display: block;
    position: absolute;
    width: 0;
    height: 0;
    left:50px;
    border-width: 43.3px 25px;
    border-style: solid;
    border-color: transparent transparent transparent red;
    top:0;
}
</style>

this kind of Baidu is a big one. No, no, no.

< hr >

of the border you want

<div style='position:relative;width:100px;margin:0 auto;'>
  <div class='one'></div>
  <div class='two'></div>
  <div class='three'></div>
</div>
<style>
  .one {
    width: 50px;
    height: 86.6px;
    margin: 0 auto;
    border-top: 1px solid red;
    border-bottom: 1px solid red;

  }

  .two {
    position: absolute;
    width: 50px;
    height: 86.6px;
    left: 25px;
    top: 0;
    transform: translate(-50%, -50%);
    transform: rotate(60deg);
    border-top: 1px solid red;
    border-bottom: 1px solid red;
  }

  .three {
    position: absolute;
    width: 50px;
    height: 86.6px;
    left: 25px;
    top: 0;
    transform: translate(-50%, -50%);
    transform: rotate(300deg);
    border-top: 1px solid red;
    border-bottom: 1px solid red;

  }

</style>

read this blog


draw with svg.

Menu