Đinh Carabus
Đinh Carabus

Reputation: 3494

How to write this CSS-Selector (Target img from previous Anchor-Tag)

Basically I have this markup:

<a>Link</a>
<a>
  <img />
</a>

I would like to target the img on hover of the first Anchor-Tag. I have tried this

a:hover + a > img { ... }

but it didn't work. How could this be achieved?

Upvotes: 0

Views: 218

Answers (2)

Gourav
Gourav

Reputation: 1774

You need to write like this. This is an example I gave to give you clear idea about how to write the code. Even your code formation was correct.

    <a>Link</a>
     <a>
    <div>fgfgfg</div>
     </a>


 a div:hover{
      background-color:blue;
     }
   div{
       width:100px;
       background-color:red;
    }

Here is the demo http://jsfiddle.net/ZWhtQ/

Upvotes: 1

Tomzan
Tomzan

Reputation: 2818

The problem is not in the selector a:hover + a > img is formed correctly.

fiddle

Upvotes: 1

Related Questions