样式< a>无href属性 [英] Styling <a> without href attribute

查看:85
本文介绍了样式< a>无href属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以匹配所有链接而不通过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.

这篇关于样式&lt; a&gt;无href属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆