Hexagon shape with a border/outline

前端 未结 5 1477
余生分开走
余生分开走 2020-11-27 07:53

I know it\'s possible to create a hexagon shape using the following code:

.hex:before {
    content: \" \";
    width: 0; height: 0;
    border-bottom: 30px          


        
5条回答
  •  隐瞒了意图╮
    2020-11-27 08:14

    Just found this link to a hexagon designer that you can copy the html and css from to get what you want. Thought i'd leave it here for anyone else coming across this post.

    So using the tool, to have a white hexagon with a green outline:

    .hexagon {
      position: relative;
      width: 100px; 
      height: 57.74px;
      background-color: #ffffff;
      margin: 28.87px 0;
      border-left: solid 5px #28bf20;
      border-right: solid 5px #28bf20;
    }
    
    .hexagon:before,
    .hexagon:after {
      content: "";
      position: absolute;
      z-index: 1;
      width: 70.71px;
      height: 70.71px;
      -webkit-transform: scaleY(0.5774) rotate(-45deg);
      -ms-transform: scaleY(0.5774) rotate(-45deg);
      transform: scaleY(0.5774) rotate(-45deg);
      background-color: inherit;
      left: 9.6447px;
    }
    
    .hexagon:before {
      top: -35.3553px;
      border-top: solid 7.0711px #28bf20;
      border-right: solid 7.0711px #28bf20;
    }
    
    .hexagon:after {
      bottom: -35.3553px;
      border-bottom: solid 7.0711px #28bf20;
      border-left: solid 7.0711px #28bf20;
    }

提交回复
热议问题