3

In order to show links that go to an external page, I have a little gif that goes after the text, using the after property of css.

.[style]:after{content:url(../images/main/externallink.gif)}

The problem is when it comes to making the image change (to change the colour) on roll-over; the following code works fine but adds the image to the first one instead of changing it!

.[style] a:hover:after{content:url(../images/main/externallinkover.gif)}

Can anyone suggest a way to make the original 'after' image disappear, or suggest a completely different way of doing this?

3
  • 1
    there's a space between .[style] and the a:hover? Commented Jul 8, 2013 at 13:29
  • What if a:hover, a:after .. Commented Jul 8, 2013 at 13:32
  • In one statement you have .[style]:after and in the second you have .[style] a:hover:after. They are not following the same structure and so will not match the same element in two different states. Commented Jul 8, 2013 at 13:35

1 Answer 1

4

You're applying the hover image to a different element than the initial image.

If you apply both images to the link, you should get the behaviour you want:

.[style] a:after{content:url(../images/main/externallink.gif)}

.[style] a:hover:after{content:url(../images/main/externallinkover.gif)}

(Query: I take it .[style] isn't the actual selector you're using?)

Sign up to request clarification or add additional context in comments.

2 Comments

Great - that's worked perfectly, thanks. (And no, I wasn't actually calling my style '[style]'!)
@MattBowyer: hurray! Sure - [style] is a bit of a confusing way to write it, because it's actually a CSS selector (specifically, the attribute selector).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.