CSS Attribute selectors allow the selection of elements based on attribute values. Unfortunately, I've not used them in years (mainly because they're not supported by all modern browsers). However, I remember distinctly that I was able to use them to adorn all external links with an icon, by using a code similar to the following:
a[href=http] {
background: url(external-uri);
padding-left: 12px;
}
The above code doesn't work. My question is: How does it work? How do I select all <a>
tags whose href
attribute starts with "http"
? The official CSS spec (linked above) doesn't even mention that this is possible. But I do remember doing this.
(Note: The obvious solution would be to use class
attributes for distinction. I want to avoid this because I have little influence of the way the HTML code is built. All I can edit is the CSS code.)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…