elschwartzo Posted November 17, 2023 Share Posted November 17, 2023 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
tuanphan Posted November 19, 2023 Share Posted November 19, 2023 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
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment