1

I am trying to make a hexagon with border radius, border and something like a mask. Something like this : enter image description here
However, I am a bit stumped by the 'mask' and how I should go about making that shape. Would it be better to export this as svg than to make it with css3?

Currently I have this:

<div id="hexagon"></div>
#hexagon { 
    position: relative;
    margin: 1em auto;
    width: 10.2em;
    height: 17.32em;
    border-radius: 1em/.5em;
    background: #FF5E5E;
    transition: opacity .5s;
    cursor: pointer;
    border-top: 2px solid black;
    border-bottom: 2px solid black;
} 

#hexagon:before { 
    position: absolute;
    width: inherit;
    height: inherit;
    border-radius: inherit;
    background: inherit;
    content: '';
    -webkit-transform: rotate(60deg);  /* Chrome, Opera 15+, Safari 3.1+ */
    -ms-transform: rotate(60deg);  /* IE 9 */
    transform: rotate(60deg); /* Firefox 16+, IE 10+, Opera */
    border-top: 2px solid black;
    border-bottom: 2px solid black;
}

#hexagon:after { 
    position: absolute;
    width: inherit;
    height: inherit;
    border-radius: inherit;
    background: inherit;
    content: '';
    -webkit-transform: rotate(-60deg);  /* Chrome, Opera 15+, Safari 3.1+ */
    -ms-transform: rotate(-60deg);  /* IE 9 */
    transform: rotate(-60deg); /* Firefox 16+, IE 10+, Opera */
    border-top: 2px solid black;
    border-bottom: 2px solid black;
}

But even then this isnt very good since it looks a little off at the corners:

enter image description here

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
hui13
  • 67
  • 1
  • 7
  • this codepen might helpful for you https://codepen.io/interdruper/pen/GrBEk – Frontend Dev Web Accessibility Jul 06 '21 at 06:15
  • 1
    You should go for the svg option it is better and reliable also. – Sudhanshu Singh Jul 06 '21 at 06:24
  • 1
    Absolutely. And you can still use css classes for scaling and coloring it if you use inline `` tags instead of loading it as an ``. INFINITELY better and easier than using just css on a `
    ` And Blazor absolutely ROCKS svg-- you can control every single part of your svg-- line thickness and color, text contents, rotation, canvas size, just about anything.
    – Bennyboy1973 Jul 06 '21 at 06:27

1 Answers1

0

I would consider my previous answer where I will duplicate the shape to create the border:

.hex {
  position:relative;
  --s:200px;
  width: 200px;
  height:calc(0.866*var(--s));
}

.hex div {
  filter: url('#goo');
  position:absolute;
  inset:0;
}

.hex div::before{
  content: "";
  position:absolute;
  inset:0;
  background:#000;
  clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}
.hex div:nth-child(2)::before{
  background:red;
  inset:4px;
}
<div class="hex">
  <div></div>
  <div></div>
</div>

<svg style="visibility: hidden; position: absolute;" width="0" height="0" xmlns="http://www.w3.org/2000/svg" version="1.1">
  <defs>
        <filter id="goo"><feGaussianBlur in="SourceGraphic" stdDeviation="8" result="blur" />    
            <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 19 -9" result="goo" />
            <feComposite in="SourceGraphic" in2="goo" operator="atop"/>
        </filter>
    </defs>
</svg>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415