CSS Image Overlay Hover Effects

Web Design & Web Development

Demo

Sponsored links

 

Code

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Image Overlay Hover Effects</title>
    <link rel="stylesheet" type="text/css" href="https://demo.plantpot.works/assets/css/normalize.css">
    <link rel="stylesheet" href="https://use.typekit.net/opg3wle.css">
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <div id="container">
      <div class="box">
        <h1>Image Overlay<br>Hover Effects</h1>
      </div>
    </div>
  </body>
</html>

CSS

@charset "utf-8";
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  font-size: 16px;
}
body {
  background-color: #ead9bd;
  font-family: futura-pt, sans-serif;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}
#container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
  padding: 20px;
}
.box {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  width: 100%;
  max-width: 400px;
  height: 100vw;
  max-height: 400px;
  background-image: url(bg.jpg);
  background-position: top left;
  background-size: cover;
  cursor: pointer;
}
.box::before {
  opacity: 0;
  z-index: 1;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #40011d;
  content: '';
  transition: .5s;
}
.box h1 {
  opacity: 0;
  z-index: 10;
  text-align: center;
  color: #fff;
  font-size: 3rem;
  letter-spacing: 1px;
  transition: .5s;
}
.box:hover h1 {
  opacity: 1;
}
.box:hover::before {
  opacity: .5;
}
@media screen and (max-width: 480px) {
  .box {
    width: 200px;
    height: 200px;
  }
  .box h1 {
    font-size: 2rem;
  }
}