The W3C Recommendations定义了使用A[CLASS]{/*Code*/}选择具有已定义类的任何锚的能力,但是否存在先行项?
我可以选择所有没有类的锚吗?
我的直觉是使用A[~CLASS]{/*Code*/},但没有记录在案,A[CLASS=]{/*Code*/}会选择所有具有空字符串类名的锚(例如,<A CLASS="" HREF="http://example.com/">This anchor has a class, but it's empty.</A>)。
示例用法
在这段代码中,我只希望无类链接是绿色的。

<HTML>
<HEAD>
<LINK REL="stylesheet" TYPE="text/css" HREF="http://example.com/externalUneditableStyles.CSS" />
<STYLE>
A.deadLink{
color:#FF0000 !important;
}
A{
color:#00FF00;
}

</STYLE>
</HEAD>

<BODY>
<A HREF="http://fakesite.not/" CLASS="deadLink">This link is red, as specified by the CSS above.</A>
<A HREF="http://example.com/">This link is green, as specified by the CSS above.</A>
<A HREF="#/childpage/" CLASS="childLink">This is a link to a child page, and is styled by external uneditable CSS. That CSS doesn't specify a color, so it is green, even though that might not be the intended effect.</A>
</BODY>
</HTML>

最佳答案

使用这样的东西:

a:not([class]) {
    /*some styling here*/
}

小演示:little link

09-25 17:14