Link to home
Create AccountLog in
Avatar of Henry Starcher
Henry StarcherFlag for United States of America

asked on

CSS Link Attribute to All except Two

I am trying to add an icon to the end of all external links to my site, with the exception of the links that appear in the website's footer (one link).

The code I'm using is as follows:
a[href^='http://'] {
background: url('..images/icons/globe.png') no-repeat right center;
padding-right: 20px;
margin-right: 10px;
}

Open in new window


Is there any way to just identify one link to exclude from this style or am I going to have to add a class identifier to all of my external links to get this to do what I want it to do? If I can exclude the footer link, how would I go about doing that?
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
CSS3 has :not, but only use if you can be certain visitors are using IE9+

a[href^='http://']:not(#footer a[href^='http://']){

else (robert forgot the external target)

#footer  a[href^='http://'] {
I didn't forget, I understood the question to be to exclude any link(s) in the footer.

But you're probably right to use :not, IE8 doesn't recognise "href^=" so I guess CSS3 support is already assumed/needed.
I assumed not external links in the footer...but you know what assumption is...
IE8 should recognise href^=
Avatar of Henry Starcher

ASKER

Thanks for both of these, I'll try them when I get back to the office.
Always a jQuery/CSS option (if you're using the library anyway!)

$('a[rel=external]').addClass('external');
+
.external { ... }
...if they have rel set...
This worked perfectly for what I was needing, thanks so much.