jQuery addClass example

Change class name on click in jQuery

by Craig Martin

HTML

<div class="hexagon">
  <div class="hexTop"></div>
  <div class="hexBottom"></div>
</div>
<div class="hexagon">
  <div class="hexTop"></div>
  <div class="hexBottom"></div>
</div>
<div class="hexagon">
  <div class="hexTop"></div>
  <div class="hexBottom"></div>
</div>
<div class="hexagon">
  <div class="hexTop"></div>
  <div class="hexBottom"></div>
</div>
<div class="hexagon">
  <div class="hexTop"></div>
  <div class="hexBottom"></div>
</div>
<div class="hexagon">
  <div class="hexTop"></div>
  <div class="hexBottom"></div>
</div>
<div class="hexagon">
  <div class="hexTop"></div>
  <div class="hexBottom"></div>
</div>

CSS

.hexagon {
  position: relative;
  width: 300px; 
  height: 173.21px;
  margin: 86.60px 0;
  background-image: url(http://csshexagon.com/img/meow.jpg);
  background-size: auto 334.8632px;
  background-position: center;
  border-left: solid 5px #6d6d6d;
  border-right: solid 5px #6d6d6d;
}

.hexTop, 
.hexBottom {
	position: absolute;
	z-index: 1;
	width: 215.13px;
	height: 210.13px;
	overflow: hidden;
	-webkit-transform: scaleY(0.5774) rotate(-45deg);
	-ms-transform: scaleY(0.5774) rotate(-45deg);
	transform: scaleY(0.5774) rotate(-45deg);
	background: inherit;
	left: 38.98px;
	top: 64px;
}

/*counter transform the bg image on the caps*/


.hexTop:after, .hexBottom:after {
	content: "";
	position: absolute;
	width: 290.0000px;
	height: 167.4315780649915px;
	-webkit-transform: rotate(45deg) scaleY(1.7321) translateY(-83.7158px);
	-ms-transform: rotate(45deg) scaleY(1.7321) translateY(-83.7158px);
	transform: rotate(45deg) scaleY(1.7321) translateY(-83.7158px);
	-webkit-transform-origin: 0 0;
	-ms-transform-origin: 0 0;
	transform-origin: 0 0;
	background: inherit;
}

.hexTop {
  top: -106.0660px;
  border-top: solid 7.0711px #6d6d6d;
  border-right: solid 7.0711px #6d6d6d;
}

.hexTop:after {
  background-position: center top;
}

.hexBottom {
	bottom: -106.0660px;
	border-bottom: solid 7.0711px #6d6d6d;
	border-left: solid 7.0711px #6d6d6d;
}

.hexBottom:after {
  background-position: center bottom;
}

.hexagon:after {
  content: "";
  position: absolute;
  top: 2.8868px;
  left: 0;
  width: 290.0000px;
  height: 167.4316px;
  z-index: 2;
  background: inherit;
}