样式< a>无href属性 [英] Styling <a> without href attribute
本文介绍了样式< a>无href属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以匹配所有链接,而不通过CSS指定 href
?
Is it possible to match all links without href
specified via CSS?
示例:
<a>Invalid link</a>
我知道它可能匹配href的所有链接,但我只是寻找相反。 / p>
I know its possible to match all links with href but I'm just looking for the opposite.
推荐答案
使用CSS3的:not()
:
a:not([href]) {
/* Styles for anchors without href */
}
$ c> a ,并为 a [href]
设置
a {
/* Styles for anchors with and without href */
}
a[href] {
/* Styles for anchors with href, will override the above */
}
对于最佳浏览器支持(包括古老但不是完全被遗忘的浏览器),请使用 :link
和:visited
伪类而不是属性选择器(两者的组合与 a [href]
)相同:
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 */
另请参阅此答案,以深入解释 a [href]
对 a:link,a:visited
。
Also see this answer for an in-depth explanation of a[href]
versus a:link, a:visited
.
这篇关于样式< a>无href属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文