Simple Image Hover Effects using HTML & CSS

Simple Image Hover Effects using HTML & CSS

In this article, I have shown you how to create Simple Image Hover Effects using HTML and CSS. Earlier I shared with you many more tutorials on CSS Image Hover Effects. This type of Simple Image Hover is important for you if you are a beginner. 

Here I have shared the completed step-by-step tutorial and the required source code. First I made a box at the top of the web page in which I put the images. When you click on that image, the image will split in two from the middle. As a result, the image on the back can be seen. 

That is, two layers of the image have been used here. The first layer will move on both sides and the second layer will be visible.

Simple Image Hover Effects

This Image Hover effect is simple enough and suitable for use in any work. Here I have basically used three images. Under normal circumstances, the second and third images can be seen above. 

When you mouse over or click on the images, those two images will move to either side. And we get to see the first image at the back. Below I have given a preview that will help you to know how it works.

See the Pen Untitled by Ground Tutorial (@groundtutorial) on CodePen.



If you only want the source code, you can use the download button below the article. But here I have shared a step-by-step tutorial for you.

Step 1: Basic structure of image hover effect

I have created the basic structure of this Simple Image Hover Effects using the following HTML and CSS codes. That is, I have created a box in which the images can be seen. I have used black as the background color of the webpage here.

<div ontouchstart="" class="wrapper">

  <div class="row">

  </div>

</div>


* {
    margin: 0;
    padding: 0;
}
body{
      background: #272d2f;
}
.wrapper {
    font-family: 'Montserrat', sans-serif;
    color: #fff;
    padding: 50px 0;
}

.row {
    margin: 0 auto;
    width: 80%;
    max-width:600px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 50px;
    border: 4px solid white;
}
Basic structure of image hover

Step 2: Add the necessary images

Now I have added the images. As I said I used three images. These three have used the same image. You can change the first image if you want.

<div class="effect container">
   <img src="https://user-images.githubusercontent.com/26748614/112761666-84f34c80-8ffc-11eb-9405-7621f584bbe5.jpg" class="firstImg" alt="">
   <img src="https://user-images.githubusercontent.com/26748614/112761666-84f34c80-8ffc-11eb-9405-7621f584bbe5.jpg" class="secondImg" alt="">
   <img src="https://user-images.githubusercontent.com/26748614/112761666-84f34c80-8ffc-11eb-9405-7621f584bbe5.jpg" class="thirdImg" alt="">
</div>


.row img {
    cursor: pointer;
    display: block;
    width: 100%;
}

.effect {
    position: relative;
    overflow: hidden;
}

.effect .firstImg {
    transition: transform .8s;
}

.effect:hover .firstImg {
    transform: scale(1.2)
}

Add the necessary images

Step 3: Design the second and third images

Arrangements have been made to cut the second and third images along the middle using the following CSS. The second image is placed along the left side and the third image is placed along with the right side. 

When you hover the mouse over the images, the second image will move along the left side and the third will move along the right side.

.effect .secondImg,
.effect .thirdImg {
    position: absolute;
    top: 0;
    z-index: 3;
    filter: saturate(0);
    transition: transform 1.6s;
}

.effect .secondImg {
    left: 0;
    clip-path: polygon(0 0, 50% 0, 50% 100%, 0% 100%);
}

.effect .thirdImg {
    right: 0;
    clip-path: polygon(50% 0, 100% 0, 100% 100%, 50% 100%);
}

Design the second and third images

Step 4: Add hover effect on image

Hover effects have been added to the images using the following CSS. When you click on these images, the second image will be reduced to 700 along the X-axis, that is, 700px along with the left side. As a result, we do not see the second image.

In the case of a similar third image, This will move the third image along the right side. As a result, I can't see this image. As the second and third images move, we get to see the first image.

.effect:hover .secondImg {
    transform: translateX(-700px) skewX(40deg);
}

.effect:hover .thirdImg {
    transform: translateX(700px) skewX(-40deg);
}

Add hover effect on image

Hopefully from the above tutorial, you have learned how I created these Simple Image Hover Effects. If there is any problem then you can definitely let me know by commenting. The source code for creating this CSS Simple Image Hover Effects is in the button below.







Comments

Popular posts from this blog

Simple Day Night Toggle Button Using HTML and CSS

Splash Image Mask Using HTML and CSS (Free Code)

Simple RGB Color Generator Using JavaScript & CSS