样式< a>无href属性 [英] Styling <a> without href attribute
问题描述
是否可以匹配所有链接而不通过CSS指定 href
?
示例:
< a>无效链接< / a>
我知道它可能匹配href的所有链接,但我只是寻找相反。 / p>
使用CSS3的:not()
:
a:not([href]){
/对于没有href的锚点* /
}
$ c> a ,并为 a [href]
设置
a {
/ *带和不带href的锚点的样式* /
}
a [href] {
/ *具有href的锚点样式将覆盖上述* /
}
对于最佳浏览器支持(包括古老而不是完全被遗忘的浏览器),请使用和:visited
伪/类而不是属性选择器(组合两者将匹配与 a [href]
)相同:
< > / *所有锚点* /
a:link,a:visited {} / *覆盖* /
另请参见 this answer ,以深入解释 a [href]
与 a:link,a:visited
。
Is it possible to match all links without href
specified via CSS?
Example:
<a>Invalid link</a>
I know its possible to match all links with href but I'm just looking for the opposite.
Either use CSS3's :not()
:
a:not([href]) {
/* Styles for anchors without href */
}
Or specify a general style for all a
, and one for a[href]
to override it for those with the attribute.
a {
/* Styles for anchors with and without href */
}
a[href] {
/* Styles for anchors with href, will override the above */
}
For the best browser support (includes ancient but not quite forgotten browsers), use the :link
and :visited
pseudo-classes instead of the attribute selector (combining both will match the same as a[href]
):
a {} /* All anchors */
a:link, a:visited {} /* Override */
Also see this answer for an in-depth explanation of a[href]
versus a:link, a:visited
.
这篇关于样式< a>无href属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!