0

I have three divs with its correponding span children in my html page

<ul>
   <li><div><span class="spinner">A</span></div></li>
   <li><div><span>B</span></div></li>
   <li><div><span>C</span></div></li>
</ul>

and I would like for only the one who has the children span class="spinner" to actually spin when I hover over the div but I cannot accomplish such task witht the following lines:

ul li div:hover span.spinner {
    animation: spin 1s linear infinite;
}

You can see my code in JSFiddle

Temani Afif
  • 245,468
  • 26
  • 309
  • 415

1 Answers1

2

Your span.spinner needs to have display: inline-block;

here is your code with the display property

ul{
    list-style-type: none;
}

li {
    display: inline-block;
}

ul li div{
    width: 100px;
    height: 100px;
    background-color: red;
}

ul li div:hover span.spinner {
    animation: spin 1s linear infinite;
    display: inline-block;
}

@keyframes spin{
    from{ 
        transform: rotate(0deg); 
    }
    to{ 
        transform: rotate(360deg); 
    }
}
<!DOCTYPE HTML>
<html lang="en">
    <head>
        <title> Main Page </title>
        <link rel="stylesheet" href="main.css">
    </head>
    <body>
        <ul>
            <li><div><span class="spinner">A</span></div></li>
            <li><div><span>B</span></div></li>
            <li><div><span>C</span></div></li>
        </ul>
    </body>
</html>
Nico Shultz
  • 1,872
  • 1
  • 9
  • 23