Html 样式 <a> 没有 href 属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5128711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Styling <a> without href attribute
提问by knoopx
Is it possible to match all links without href
specified via CSS?
是否可以在不href
通过 CSS 指定的情况下匹配所有链接?
Example:
例子:
<a>Invalid link</a>
I know its possible to match all links with href but I'm just looking for the opposite.
我知道可以将所有链接与 href 匹配,但我只是在寻找相反的内容。
回答by BoltClock
Either use CSS3's :not()
:
要么使用 CSS3 的: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.
或者为 all 指定一个通用样式a
,并a[href]
为具有该属性的那些指定一个 for覆盖它。
a {
/* Styles for anchors with and without href */
}
a[href] {
/* Styles for anchors with href, will override the above */
}
For the bestbrowser support (includes ancient but not quite forgotten browsers), use the :link
and :visited
pseudo-classesinstead of the attribute selector (combining both will match the same as a[href]
):
为了获得最佳浏览器支持(包括古老但未被遗忘的浏览器),请使用:link
和:visited
伪类而不是属性选择器(将两者结合将与 匹配a[href]
):
a {} /* All anchors */
a:link, a:visited {} /* Override */
Also see this answerfor an in-depth explanation of a[href]
versus a:link, a:visited
.
另请参阅此答案以深入了解a[href]
vs a:link, a:visited
。