Jump to content

CSS Transition Code for List Item.

Recommended Posts

Hi,

I've created a simple list. I've added some custom code, to make the image in the list a rollover image. The only thing I cannot figure out is how to make the rollover images transition smoothly with a CSS fade effect. Below is my code without the transition CSS.

<style>

  /* Rollover images */
  
    li:nth-child(1):hover img {
    content: url(https://cdn.pixabay.com/photo/2021/12/23/13/25/flower-6889331__480.jpg);
}
li:nth-child(2):hover img {
    content: url(https://cdn.pixabay.com/photo/2022/01/18/03/16/deer-6946129__340.jpg);
}
li:nth-child(3):hover img {
    content: url(https://cdn.pixabay.com/photo/2018/07/16/04/43/tea-3541205__340.jpg);
}

</style>

 

You can see the page here: https://caper-synthesizer-8pat.squarespace.com/.  pass: test

Any advice on how to code the CSS transition effect here is appreciated.

Link to comment
  • Replies 1
  • Views 1.2k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Try this

<style>

  /* Rollover images */
  
    li:nth-child(1):hover img {
    content: url(https://cdn.pixabay.com/photo/2021/12/23/13/25/flower-6889331__480.jpg);
}
li:nth-child(2):hover img {
    content: url(https://cdn.pixabay.com/photo/2022/01/18/03/16/deer-6946129__340.jpg);
}
li:nth-child(3):hover img {
    content: url(https://cdn.pixabay.com/photo/2018/07/16/04/43/tea-3541205__340.jpg);
}
  img, li:hover img {
  	transition: all 0.3s;
  }
</style>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.