Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - style a link based on its "rel" attribute?

Tags:

css

hyperlink

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

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

like image 490
Alex Avatar asked Apr 10 '11 00:04

Alex


People also ask

What is REL attribute in CSS link?

The rel attribute specifies the relationship between the current document and the linked document. Only used if the href attribute is present. Tip: Search engines can use this attribute to get more information about a link!

When should I use link rel?

The <link> element creates a link between your HTML document and an external resource. The rel attribute specifies the relationship between the two documents.


3 Answers

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.

like image 57
unor Avatar answered Oct 12 '22 22:10

unor


It is possible with the attribute selector:

a[rel=external] {

}

Note: This is selector is not supported in IE6.

like image 24
Felix Kling Avatar answered Oct 12 '22 23:10

Felix Kling


Use the attribute selector:

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

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

Works in all modern browsers, and IE7+

like image 4
thirtydot Avatar answered Oct 12 '22 21:10

thirtydot