Hover effect on image

by Jacob Birkett

HTML

<div id="black" class="hoverable">
  <img src="https://static.pexels.com/photos/39811/pexels-photo-39811.jpeg" alt="Road Image">
  <p>This text will be shown on hover.</p>
</div>

<div id="white" class="hoverable">
  <img src="https://static.pexels.com/photos/39811/pexels-photo-39811.jpeg" alt="Road Image">
  <p>This text will be shown on hover.</p>
</div>

<div id="blur" class="hoverable">
  <img src="https://static.pexels.com/photos/39811/pexels-photo-39811.jpeg" alt="Road Image">
  <p>This text will be shown on hover.</p>
</div>

CSS

/* BEGIN MAIN CODE */

.hoverable {
  position: relative;
  width: 400px;
  overflow: hidden;
}

.hoverable img {
  max-width: 100%;
  max-height: 100%;
  vertical-align: bottom;
}

.hoverable p {
  position: absolute;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0;
  transition: opacity 500ms;
  font-size: 20px;
  background: rgba(0, 0, 0, 0.5)
}

.hoverable:hover p {
  opacity: 1;
}

/* END OF MAIN CODE */

#black p {
    color: #fff;
    background: rgba(0, 0, 0, 0.5)
}

#white p {
    color: #000;
    background: rgba(255, 255, 255, 0.5)
}

/* BEGIN BLUR STYLE */

#blur {
    color: #000;
    background: rgba(255, 255, 255, 0.5)
}

#blur img {
  transition: filter 500ms;
}

#blur:hover img {
  filter: blur(2px) grayscale(50%);
}

#blur p {
  background: none;
}

#blur:hover p {
  background: none;
}

/* END BLUR STYLE */

#black, #white, #blur {
  float: left;
}