36
<a href="http://google.com" rel="external"> LINK </a>

is it possible to add css rules for rel="external" ?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Alex
  • 66,732
  • 177
  • 439
  • 641

4 Answers4

74

Felix Kling and thirtydot suggested to use the [att=val] attribute selector (a[rel="external"]). But this will only work if external is the only rel value.

If you want to style links that could have 1 or more rel values, you should use the [att~=val] attribute selector:

a[rel~="external"] (note the tilde character)

An example for such a link could be:

<a href="http://google.com" rel="external nofollow">LINK</a>

See http://www.w3.org/TR/css3-selectors/#attribute-representation for the specification.

unor
  • 92,415
  • 26
  • 211
  • 360
12

It is possible with the attribute selector:

a[rel=external] {

}

Note: This is selector is not supported in IE6.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
  • 3
    it works :D I dont care about IE 6, my site doesn't even show up in that browser :x – Alex Apr 10 '11 at 00:21
4

Use the attribute selector:

a[rel="external"] {
    color: red
}

http://jsfiddle.net/thirtydot/yUmJk/

Works in all modern browsers, and IE7+

thirtydot
  • 224,678
  • 48
  • 389
  • 349
1

Possible with *.

// i.e: <a rel="nofollow external foo">
a[rel*="external"] { color:red; }

// you can add target attribute to open them in a new window
so.dom("a[rel*='external']").setAttr("target", "_blank");

Links:
http://github.com/qeremy/so
http://css-tricks.com/attribute-selectors/
http://www.vanseodesign.com/css/attribute-selectors/

Kerem
  • 11,377
  • 5
  • 59
  • 58