Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 Hexagon with dotted border

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:

Hexagon with a dotted border

like image 670
Pugazh Avatar asked Apr 07 '16 13:04

Pugazh


People also ask

How do you put a border on a hexagon in CSS?

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.

How do you make a hexagon shape in CSS?

You can use the html character &#x2B22; (hexagon)...

How do I create a polygon shape in CSS?

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.

How to create a hexagon shape border using CSS?

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.

What is border-style in CSS?

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?

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.

How many border-style values can the border-color property have?

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.


1 Answers

Here is an approach with an inline svg using:

  • the polygon element for the hexagon shape
  • stroke-dasharray for the dotted border (control of the size and space between dots)
  • stroke-linecap for the dotted border

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>
like image 66
web-tiki Avatar answered Sep 20 '22 09:09

web-tiki