Categories
CSS Web development

CSS Image Zoom on Hover

CSS Image Zoom on Hover

To create the CSS Image Zoom on Hover effect follow the steps below:

Demo:

*to see the CSS Image Zoom on Hover effect on the website click here.

Step1.

Add HTML

<div class="seaside">
  <img src="https://lenadesign.org/wp-content/uploads/2021/07/brighton-1.jpg" alt="Brighton">
</div>

Step2.

Add CSS

Set the color and the position of the background and elements:

body {
  display: flex;
  height: 100vh;
  align-items: center;
  justify-content: center;
}

Style the image:

.seaside {
  position: relative;
  top:0;
  left:0;
  overflow: hidden;
  width: 450px;
  height: 350px;
  box-shadow: 5px 5px 10px rgba(0,0,0,0.3);
}

.seaside img {
  width: 450px;
  height: 350px;
  position: relative;
  transition: .3s;
}

.seaside:before {
  position: absolute;
  content:"Sea Side";
  font-size: 60px;
  color: white;
  font-family: tahoma;
  background-color: rgba(69,123,157,0.4);
  text-shadow: 5px 5px 10px rgba(0,0,0,0.5);
  z-index:1;
  width: 450px;
  height: 350px;
  align-items: center;
  justify-content: center;
  display: flex;
  opacity:0;
  transition: .2s;
}

Use the :hover selector:

.seaside:hover:before {
  opacity:1;
}

.seaside:hover img {
  transform: scale(1.5);
}

Enjoy coding!