悬停语法差异
之间有什么区别:
a.cvc-formsHelpText:hover {
text-decoration:none;
}
和:
.cvc-formsHelpText:hover {
text-decoration:none;
}
HTML 是:
<a class="cvc-formsHelpText" href="javascript: void(0)">
<img src="img.gif">
<span>Text.</span>
</a>
第一个有效,第二个无效,但两者都引用 标记。
What is the difference between:
a.cvc-formsHelpText:hover {
text-decoration:none;
}
And:
.cvc-formsHelpText:hover {
text-decoration:none;
}
The HTML is:
<a class="cvc-formsHelpText" href="javascript: void(0)">
<img src="img.gif">
<span>Text.</span>
</a>
The first works and the second not, but both refer to <a>
tag.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
当您说第二个不起作用时,问题在于您省略了一个点,正如 BoltClock 指出的那样:
.cvc-formsHelpText
至于两种语法之间的区别,前者表示该元素必须是类
cvc-formsHelpText
的锚点。后一个选择器(前提是您包含省略的点)适用于具有cvc-formsHelpText
类的任何元素。显然,如果只有锚元素包含该类,则您的网站行为方式不会有明显的差异。The problem, when you're saying that the second doesn't work, is that you've omitted a dot, as BoltClock points out:
.cvc-formsHelpText
As for the difference between the two syntaxes, the former denotes that the element must be an anchor with the class
cvc-formsHelpText
. The latter selector (provided that you include the dot that you've omitted) applies to any element with the classcvc-formsHelpText
. Obviously, if only anchor elements contain that class, there will be no perceived difference in the way your website behaves.它与悬停完全无关。
这是一般语法。第一个选择器之所以有效,是因为它选择的是
cvc-formsHelpText
类,而不是徒劳地尝试定位不存在的cvc-formsHelpText
元素。It has nothing to do with hover at all.
That's the general syntax. The first selector works because it's selecting the
cvc-formsHelpText
class, not trying to fruitlessly target a non-existentcvc-formsHelpText
element.a.blah 定义了锚标记(“a”标记)的类。 .blah 为任何标签定义一个类。
a.blah defines a class for anchor tags (the "a" tag). .blah defines a class for any tag.
cvc-formsHelpText
是一个类。你需要一个“。”如果你想设计它的样式,就在它前面。cvc-formsHelpText
is a class. You need a "." in front of it if you want to style it.cvc-formsHelpText:hover
表示:悬停名为cvc-formsHelpText
的元素。例如,
,它不存在。a.cvc-formsHelpText:hover
表示:一个带有cvc-formsHelpText
类的标签,悬停。
cvc-formsHelpText:hover
means: an element namedcvc-formsHelpText
, hovered. For example,<cvc-formsHelpText>
, which doesn't exist.a.cvc-formsHelpText:hover
means: an<a>
tag, with classcvc-formsHelpText
, hovered.第一个表示找到所有 CSS“class”属性具有“cvc-formsHelpHext”的“a”标签。第二个查找名为“cvc-formsHelpHext”的标签,这不是您想要做的。
The first says that all "a" tags are found that have "cvc-formsHelpHext" for the CSS "class" attribute. The second looks for tags named "cvc-formsHelpHext", which is not what you are trying to do.