DEV Community

Cover image for Tutorial on CSS Background Image Hovers & Transitions
Adrian Twarog
Adrian Twarog

Posted on

8 1

CSS Background Image Tutorial on CSS Background Image Hovers & Transitions

In CSS, background-image(s) are used everywhere, but not many people animate or transition them. I will cover a few cool ways you can start using them with hover effects.


We will cover:

  • Using background-image, position, size, repeat,
  • Using background-blend-mode,
  • Creating transitions for the blend mode,
  • Using background-size and animating it on hover,
  • Animating a background image with gifs,
  • Combine all the elements we learnt (up above)

The end result should look something like this:
Example 1

// SASS Syntax
.bg-transition {
    .img {
        background-color:rgba(red,0.75);
        background-image:url(./youtube-a.jpg);
        background-size:125%;
        background-repeat:no-repeat;
        background-position: center;
        transition: 2s ease all;
        background-blend-mode:multiply;
    }
    &:hover {
        .img {
            background-color:rgba(red,0);
            background-size:100%;
            background-image:url(./youtube-a.gif);
        }
    }
}

Want to see more:

I will try to post new great content every day. Here are the latest items:

Follow and support me:

Adrian @ Youtube
Adrian @ Patreon
Adrian @ Twitter

PS. Does anyone know how to add colors to 'pre' code on dev.to?

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (1)

Collapse
 
thomasbnt profile image
Thomas Bnt

Hello Adrian,
Maybe is late but always useful.

PS. Does anyone know how to add colors to 'pre' code on dev.to?

For you code uses

Code block on dev.to example

.myclass { color: red }
Enter fullscreen mode Exit fullscreen mode

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay