CSS - style a link based on its rel attribute?
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.
Are there any use cases for using the HTML5 link rel attribute combination of stylesheet and next?
I believe that example was made up simply to illustrate the point that one can use both an external resource and a hyperlink keyword in the same link
tag. From the list of link types, stylesheet
seems to be the only external resource type in common use, which is why I guess it was chosen for this example. The next
could have very well been prev
or any other hyperlink keyword.
possible to style link rel?
Are you sure you're using link
right? See the spec here. A <link>
tag is only specified in the head of the document and isn't rendered. You might be thinking of anchor (<a/>
) tags.
You can specify a CSS attribute selector:
a[rel=next] { color: blue; }
Since IE6 doesn't support the attribute selector, you have a couple of options for complete compatibility. You could just hand code the class of the anchor or use JavaScript.
Here's a JavaScript solution using jQuery (similar syntax), but it's probably not the most ideal for just IE6 and below:
$("a[rel=next]").addClass("myRelClass");
Style sheets break with TITLE attribute on link tags?
This appears to be expected behavior. From, for example, the MDN docs
A preferred stylesheet [...] is one that has a value of
stylesheet
supplied for therel
attribute, and any value at all for thetitle
attribute. Here are two examples:<link type="text/css" rel="stylesheet" title="Basic styles" href="basic.css" />
<link type="text/css" rel="stylesheet" title="Fish and boats" href="ocean.css" />According to the HTML 4.01 specification, only one of the preferred stylesheets can be used at a time. Therefore, given the above example, only one of the two preferred stylesheets will be applied to the document. The specification does not supply a procedure to decide which one should be used, so user agents are free to make whatever choice they like.
Related Topics
Using Vim, How to Make CSS Rules into One Liners
How to Make Circular Background Using CSS
What Is -Webkit-Focus-Ring-Color
How to Get These Two Divs Side-By-Side
How to Customize the HTML5 Input Range Type Looks Using CSS
How to Rotate Text Left 90 Degree and Cell Size Is Adjusted According to Text in HTML
Multiline-Flexbox in Ie11 Calculating Widths Incorrectly
How to Have Different Colored Left and Top Borders in CSS with Straight Join
Linear-Gradient to Transparent Bug in Latest Safari
Purpose of *:Before, *:After Rule Without Content Property
How to Efficiently Load Google Fonts in Nuxt
How to Override Global CSS in a CSS Module File
Ie Alternative to Column-Count & Column-Gap
Amp: How to Toggle a CSS Class
What's the Difference Between Visibility: Hidden and Visibility: Collapse in Flexbox
How to Hide the Background Underneath the Border