Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add glow effect to hexagon class

Tags:

html

css

I am currently attempting to add a uniform glow effect around a hexagon created with CSS classes but due to the way the hexagon is drawn, the glow effect ends up with odd breaks that I cannot seem to fix.

.hexagon {
	position: relative;
	border-radius: 5px;
	height: 125px;
	width: 75px;
	margin: 50px;
	box-sizing: border-box;
	border: 5px solid transparent;
	border-top-color: black;
	border-bottom-color: black;
	display: inline-block;
}
.hexagon:before, .hexagon:after {
	content: "";
	border: inherit;
	position: absolute;
	top: -5px;
	left: -5px;
	background: inherit;
	border-radius: inherit;
	height: 100%;
	width: 100%;
}
.hexagon:before {
	transform: rotate(60deg);
}
.hexagon:after {
	transform: rotate(-60deg);
}
.hexagon:hover, .hexagon:hover:before, .hexagon:hover:after {
	box-shadow: 0 10px 2px -2px rgba(255,0,0,0.5), 0 -10px 2px -2px rgba(255,0,0,0.5);
}
<div class=hexagon></div>
like image 830
Kohila Avatar asked Dec 02 '25 20:12

Kohila


1 Answers

You may add more padding inside the element and adjust the border radius. All line will cross and the radius will fix the shape :

.hexagon {
  position: relative;
  border-radius: 20px;
  padding: 40px;
  height: 125px;
  width: 75px;
  margin: 50px;
  box-sizing: border-box;
  border: 5px solid transparent;
  border-top-color: black;
  border-bottom-color: black;
  display: inline-block;
}

.hexagon:before,
.hexagon:after {
  content: "";
  border: inherit;
  position: absolute;
  top: -5px;
  left: -5px;
  background: inherit;
  border-radius: inherit;
  height: 100%;
  width: 100%;
}

.hexagon:before {
  transform: rotate(60deg);
}

.hexagon:after {
  transform: rotate(-60deg);
}

.hexagon:hover,
.hexagon:hover:before,
.hexagon:hover:after {
  box-shadow: 0 10px 2px -2px rgba(255, 0, 0, 0.5), 0 -10px 2px -2px rgba(255, 0, 0, 0.5);
}
<div class=hexagon></div>

You can of course control the radius of your shape by changing simultaneously the padding and border-radius

like image 139
Temani Afif Avatar answered Dec 05 '25 12:12

Temani Afif



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!