I could achieve a hexagon with solid border as below:
.hex {
margin-top: 70px;
width: 208px;
height: 120px;
background: red;
position: relative;
}
.hex:before,
.hex:after {
content: "";
border-left: 104px solid transparent;
border-right: 104px solid transparent;
position: absolute;
}
.hex:before {
top: -59px;
border-bottom: 60px solid red;
}
.hex:after {
bottom: -59px;
border-top: 60px solid red;
}
.hex.inner {
background-color: lightgreen;
-webkit-transform: scale(.98, .98);
-moz-transform: scale(.98, .98);
transform: scale(.98, .98);
z-index: 1;
}
.hex.inner:before {
border-bottom: 60px solid lightgreen;
}
.hex.inner:after {
border-top: 60px solid lightgreen;
}
<div class="hex">
<div class="hex inner">
</div>
</div>
However, I would like to create a hexagon with a dotted border as seen in the image below:
We can make a curved edge hexagon by using the pseudo-element property of CSS. Use a div element to create a rectangle and also add border-radius to it. Now create a pseudo-element after using CSS and rotate it by using 60deg. Also create another pseudo-element before by using CSS and rotate it by -60deg.
You can use the html character ⬢ (hexagon)...
CSS | polygon() Function The polygon() function is an inbuilt function in CSS which is used with the filter property to create a polygon of images or text. Syntax: polygon( percentage | length); Parameter: This function accepts two parameter percentage or length which is used to hold the value of polygon size.
This tutorial explains how to create a hexagon shape border using CSS and set an image inside it. Basically, there is no direct option in CSS to draw a hexagon border around an element (an image in our case). But how can we do so? well, the answer is very simple.
CSS Border Style The border-style property specifies what kind of border to display. The following values are allowed: dotted - Defines a dotted border
How to increase the space between dotted border dots using CSS? The task is to increase space between the dotted border dots. you can just adjust the size with the background-size property, the proportion with the background-image property, and the proportion with the linear-gradient percentages.
The effect depends on the border-color value The border-style property can have from one to four values (for the top border, right border, bottom border, and the left border). A dotted border.
Here is an approach with an inline svg using:
svg{width:30%;margin:0 auto;}
<svg viewbox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
<polygon fill="#92D050"
stroke="red"
stroke-width="1"
stroke-linecap="round"
stroke-dasharray="0.5,3"
points="50 1 95 25 95 75 50 99 5 75 5 25"/>
</svg>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With