1

I checked the special selection of input elements as shown here. I tried to apply this to select all links except a link which has a rel atribute. Here you have the example:

CSS

.language a:not[rel=author]{
    background: red;
}

HTML

<section class="language">
   <a href="/en/">
       <abbr lang="en" title="english">EN</abbr>
   </a>
   <a href="/spa/">
       <abbr lang="es" title="english">ES</abbr>
   </a>
   <a href="http://whatever.com/" rel="author">Designed by me</a>
</section>

I would like only to target the first two links. I would like to avoid a class and try to target them with CSS.

Filburt
  • 17,626
  • 12
  • 64
  • 115
Daniel Ramirez-Escudero
  • 3,877
  • 13
  • 43
  • 80

4 Answers4

2

Do it like that:

.language a:not([rel=author]){
    background: red;
}

You just forgot parentheses after :not

Ricky Stam
  • 2,116
  • 21
  • 25
1

Select all anchors that don't have a rel attribute:

.language a:not([rel]){
    background:#F00;
}

JSFiddle

George
  • 36,413
  • 9
  • 66
  • 103
1

Just target the attribute...

.language a abbr[title="english"] {
   /* woohoo! */
}
Paulie_D
  • 107,962
  • 13
  • 142
  • 161
1

Instead of the [att=val] attribute selector, you should use the [att~=val] attribute selector:

.language a:not([rel~=author]){
    background: red;
}

[rel~=author] also matches if author is not the only value of the rel attribute. So it matches links like:

<a href="http://whatever.com/" rel="author">Designed by me</a>
<a href="http://whatever.com/" rel="author external">Designed by me</a>
<a href="http://whatever.com/" rel="author external nofollow">Designed by me</a>
<!-- … -->
Community
  • 1
  • 1
unor
  • 92,415
  • 26
  • 211
  • 360