CSS Zoom Image on Hover

12/31/2020

Contents

Demo

Full Screen

Code

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Zoom Image on Hover</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">
      <img class="image" src="image.png" alt="">
      <h1>Zoom Image on Hover</h1>
    </div>
  </body>
</html>

CSS

@charset "utf-8";
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  font-size: 16px;
}
body {
  background-color: #bfccad;
  font-family: futura-pt, sans-serif;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}
#container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
}
.image {
  cursor: zoom-in;
  width: 150px;
  transition: .5s;
}
.image:hover {
  transform: scale(1.2);
}
h1 {
  margin: 30px 0 0;
  color: #3d3935;
  font-size: 2.5rem;
  text-align: center;
}
@media screen and (max-width: 480px) {
  .image {
    width: 100px;
  }
  h1 {
    margin-top: 20px;
    font-size: 1.75rem;
  }
}