I want to decorate a horizontal navigation with a div
-element that "slides" below the navigation, depending on which <li>
item is currently hovered.
Example:
li:nth-child(1):hover { transform: translateX(100px) };
li:nth-child(2):hover { transform: translateX(200px) };
li:nth-child(3):hover { transform: translateX(300px) };
li:nth-child(4):hover { transform: translateX(400px) };
Challenge: Until now I couldn't figure out which CSS-selector I have to use according to move the div
. I have tried all solutions mentioned in this approach, but none of them has worked yet.
Example:
* { list-style-type: none; }
ul { display: flex }
a {
display: block;
padding: 1em;
color: white;
background-color: orange;
}
.red_circle {
display: block;
top: 100px;
height: 50px;
width: 50px;
background-color: red;
}
li:nth-child(1):hover > .red_circle,
li:nth-child(1):hover + .red_circle,
li:nth-child(1):hover .red_circle,
li:nth-child(1):hover ~ .red_circle, {
transform: translatex(400px);
}
<container>
<ul>
<li><a href="#">Test 1</a></li>
<li><a href="#">Test 2</a></li>
<li><a href="#">Test 3</a></li>
<li><a href="#">Test 4</a></li>
</ul>
<div class="red_circle"</div>
</container>