CSS'>'选择器它是什么? [英] CSS '>' selector; what is it?
问题描述
可能重复:
在CSS规则中>是什么意思?
我看过在CSS代码中使用了大于(>
)几次,但我不能解决它的作用。
因此,如果您有三层div:
< div class ='a'>
< div>
< div> ...< / div>
< / div>
< / div>
且您有选择器
.a> div {...}
那么它将影响第二级div, / p>
如果你只是在选择器之间有一个空格,而不是>
,那么它将影响第二个和第三级div。 (空格更常用,并定义了一个后代选择器,这意味着它在树中查找任何匹配的元素,而不是直接的孩子,因为>
)
希望有帮助。
注意:>
选择器不支持IE6。它可以在所有其他当前的浏览器中工作,包括IE7和IE8。
如果你正在寻找不太好用的CSS选择器,你可能还想看 +
,〜
和 [attr]
所有这些都非常有用。
此页有所有可用的选择器的完整列表,以及它们在各种浏览器(其主要是IE有问题)中的支持的细节,以及它们的使用的良好示例。
Possible Duplicate:
What does ">" mean in CSS rules?
I've seen the "greater than" (>
) used in CSS code a few times, but I can't work out what it does. What does it do?
It means immediate children.
Thus if you have three tiers of divs:
<div class='a'>
<div>
<div>...</div>
</div>
</div>
and you have a selector
.a > div { ... }
then it will affect the second level div, and not the third.
If you just have a space between the selectors instead of the >
, then it will affect both the second and third level divs. (The space is much more commonly used and defines a "descendant selector", which means it looks for any matching element down the tree rather than just immediate children as the >
does)
Hope that helps.
NOTE: The >
selector is not supported by IE6. It does work in all other current browsers though, including IE7 and IE8.
If you're looking into less-well-used CSS selectors, you may also want to look at +
, ~
, and [attr]
selectors, all of which can be very useful.
This page has a full list of all available selectors, along with details of their support in various browsers (its mainly IE that has problems), and good examples of their usage.
这篇关于CSS'>'选择器它是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!