Make Hexagon Shape with Border, Rounded Corners and Transparent Background

Make hexagon shape with border, rounded corners and transparent background

Hexagon with rounded corners are complex shapes to create and I usually recommend using SVG for creating them. The need for a transparent background makes it even more better suited for SVG. With SVG you can get better control over the shape, its curves etc and you don't have to add a lot of extra (unnecessary) elements to your markup also.

All that is needed for creating this shape with SVG is to use a single path element along with a few L (line) and A (arc) commands. The L (line) command basically draws a line from point 1 to point 2 whereas the A (arc) command draws an arc of the specified radius (the first two values immediately following the A command).

You can read more about the SVG path element and its commands in this MDN tutorial.

svg {  height: 200px;  width: 240px;}path {  stroke: #777;  fill: none;}
body { background: black;}
<svg viewBox='0 0 120 100'>  <path d='M38,2            L82,2            A12,12 0 0,1 94,10            L112,44            A12,12 0 0,1 112,56           L94,90                  A12,12 0 0,1 82,98           L38,98           A12,12 0 0,1 26,90           L8,56           A12,12 0 0,1 8,44           L26,10           A12,12 0 0,1 38,2' /></svg>

How to make a curved edge hexagon by using CSS

I think you are looking for this.

.hex {
position: relative;
margin: 1em auto;
width: 10em;
height: 17.32em;
border-radius: 1em/.5em;
background: orange;
transition: opacity .5s;
}

.hex:before,
.hex:after {
position: absolute;
width: inherit;
height: inherit;
border-radius: inherit;
background: inherit;
content: '';
}

.hex:before {
-webkit-transform: rotate(60deg);
transform: rotate(60deg);
}

.hex:after {
-webkit-transform: rotate(-60deg);
transform: rotate(-60deg);
}
<div class="hex"></div>

Making a hexagon with a mask and border in css3

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>


Related Topics



Leave a reply



Submit