Hello I'm trying out CSS transition property, and I'm having some trouble, when I hover the main tag, the images transitions into their respective positions which I have given, but as soon as I remove the cursor, the images disappear in an instant, without the transition property which I have set, it works just fine when I'm using only background color instead of image, I want the transition to be applied also when I remove the hover from the images,
This is the CSS code that I have written
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
main {
width: 900px;
height: 600px;
margin: 10px auto;
border: 1px solid black;
position: relative;
overflow: hidden;
}
.box {
width: 300px;
height: 600px;
position: absolute;
top: 0;
left: -300px;
transition: ease-out;
transition: 2s;
}
main:hover .box:nth-child(1) {
top: 0;
left: 0;
background: url('https://picsum.photos/seed/picsum/300/600');
background-size: cover;
}
main:hover .box:nth-child(2) {
top: 0;
left: 300px;
background: url('https://picsum.photos/id/237/300/600');
background-size: cover;
}
main:hover .box:nth-child(3) {
top: 0;
left: 600px;
background: url('https://picsum.photos/300/600.jpg');
background-size: cover;
}
<main>
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
</main>
this happens because when you're not hovering anymore the image gets removed solution keep the image even without hover... Also transition property should be
ease-in-out
.