5

When i hover a "li a" can i then affect another element in plain CSS?

becuase I'm trying to make a box slide in, as a background element, when hovering my link. Exactly like this sites navigation, just instead of when activated, it works with hover

http://www.zindhai.com

this is my code

nav ul li a:hover{
    color: #C3E1FF;
    font-weight: 700;
}

nav ul li span:hover{
    -webkit-transform:translate(0px, 0px);
    -webkit-transition:all 0.5s ease-out;
    transition:all 0.5s ease-out;
}

nav ul li span{
    height:43px;
    width:300px;
    position: absolute;
    background-color:#47525D;
    -webkit-transform:translate(300px, 0px);
    -webkit-transition:all 0.5s ease-out;
    transition:all 0.5s ease-out;
    background-position:initial initial;
    background-repeat:initial initial;
}

thanks in advance!

This is how it looks now;

http://jsfiddle.net/mbyc3tf9/

Tobias Madsen
  • 105
  • 1
  • 3
  • 9

2 Answers2

3

If you need move the span, when you put your mouse over the a, add this

nav ul li a:hover > span {}
Javier
  • 103
  • 11
  • Thank you! it works, but now my a hover effect has dissapeared? – Tobias Madsen Oct 10 '14 at 11:56
  • 1
    you need add nav ul li a:hover {} and nav ul li a:hover > span {} – Javier Oct 10 '14 at 12:02
  • Thanks! it works perfectly :) Actually i need help to another question if you have the time, do you know how i hide the span, so it only appears when hovering the li. Because right now it's visible to the right of the li – Tobias Madsen Oct 10 '14 at 12:12
  • Yes, add display: none; to nav ul li span and add display:block; to nav ul li a:hover > span – Javier Oct 10 '14 at 21:27
  • Yep it worked, though the "animation" disappeared, so the span isn't sliding in from the side, it just appears :/ – Tobias Madsen Oct 10 '14 at 22:00
  • you need add the animation code in the nav ul li a:hover > span – Javier Oct 11 '14 at 14:22
  • nav ul li a:hover > span{ -webkit-transform:translate(0px, 0px); -webkit-transition:all 0.5s ease-out; transition:all 0.5s ease-out; display:block; } This is my code, and that's not working :/ – Tobias Madsen Oct 11 '14 at 16:03
0

Yeah it's pretty easy to do. Assuming your HTML is called something like .myElement for example. All you need to do is...

nav ul li a:hover .myElement { ... }

Then enter your CSS inside the { }.

Dan
  • 152
  • 2
  • 14