• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
rahmanzeb.com

rahmanzeb.com

Rahman Zeb's Portfolio & Blog

  • Home
  • About
  • Tutorials
    • Google Sites Tutorials
    • WordPress Tutorials
    • CSS Tutorials
  • Templates
    • Google Sites Templates
  • Portfolio
  • Hire me!
  • Contacts

Make an image scroll from top to bottom on hover

27/11/2021 By Rahman Zeb 1 Comment

Image Scroll on hover Demo

In this tutorial I’ll be explaining in detail how to make an image scroll from top to bottom on hover using only CSS.

I’ll first create a div and give it a class of image-wrap or you can give it any class you think is better. Inside that I am going to put an a tag or link tag and then I’ll put my img tag inside the link tag.

<div class="image-wrap">
    <a href="https://rahmanzeb.com">
        <img src="theme-screenshot.jpg" />
    </a>
</div>

Then I’ll apply the following CSS code to achieve the image scroll from top to bottom on hover.

.image-wrap {
    width: 300px;
    height: 300px;
    overflow: hidden;
    margin: 50px auto;
}
.image-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    transition: all 1s ease-in-out;
}
.image-wrap:hover img {
    object-position: bottom center;
}

If you are familiar with CSS and HTML you should not have any problem understanding the code above, but I’ll explain it in simple terms to make it clear for you in case you are not good in HTML & CSS. I have simply created a div and given it a class of image-wrap and then I have given it a height and width of 300px and set the overflow to hidden to hide the image portion that extends the border width and height. Then I have targeted the image using CSS and set its height and width to 100% so that the object-fit and object-position works on it. The object-fit and object-position works similar like background-size and background-position. Then I set the object-fit to cover so it’s 100% width of the box and afterwards I set the object-position to top and center so it’s vertically align at top and horizontally at center. I used the transition so the animation looks smoother and beautiful as without transition it won’t look good at all. Finally I set the object-position on hover to bottom and center so the image start scrolling from top to bottom.

I have also created a video on this topic, make sure to check it in case you have any problem understanding this tutorial.

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on LinkedIn (Opens in new window) LinkedIn

Filed Under: CSS Tutorials

About Rahman Zeb

Rahman Zeb is a passionate freelance web designer and developer and loves creating awesome and interactive websites. Beside Web design and development he loves to play cricket and badminton with his friends.

Reader Interactions

Comments

  1. Manisha says

    18/07/2024 at 4:31 pm

    nice

    Reply

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Hire Me

zebkhan
Fiverr
Seller
I'm web designer and developer and an expert in languages like html, css, javascript, php & mysql. I also know Joomla & Wordpress and have designed and developed dozens of sites. Most of the sites I have designed were responsive.

Follow Me

  • Facebook
  • X
  • Google
  • LinkedIn
  • Pinterest

Top Posts & Pages

  • How to add typing text effect in Google Sites
    How to add typing text effect in Google Sites
  • How to add click to Call button in google sites
    How to add click to Call button in google sites
  • How to make mailchimp's popup window appear with a click only?
    How to make mailchimp's popup window appear with a click only?
  • How to create striped background in CSS
    How to create striped background in CSS
  • Templates
    Templates

Main Menu

  • Home
  • About
  • Tutorials
    • Google Sites Tutorials
    • WordPress Tutorials
    • CSS Tutorials
  • Templates
    • Google Sites Templates
  • Portfolio
  • Hire me!
  • Contacts

Footer

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 239 other subscribers

Recent Posts

  • How to add typing text effect in Google Sites
  • Top 3 Custom Forms you can use in Google sites instead of google forms for free
  • Add click to chat on WhatsApp & facebook buttons or links in google sites
  • How to add video background in Google Sites
  • Make an image scroll from top to bottom on hover

Best Web Hosting

BlueHost SiteGround iPage Godaddy

Created with Genesis Framework on Wordpress and hosted by BlueHost

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT