">" 在 CSS 中是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9487483/
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
What does ">" mean in CSS?
提问by Ocelot
Possible Duplicate:
What does “>” mean in CSS rules?
可能的重复:
“>”在 CSS 规则中是什么意思?
What does the >
symbol mean in CSS? I noticed it in my Wordpress blog theme and want to know what it is doing.
>
CSS中的符号是什么意思?我在我的 Wordpress 博客主题中注意到了它,想知道它在做什么。
#access li:hover > a,
#access ul ul :hover > a,
#access a:focus {
background: #efefef;
}
#access li:hover > a,
#access a:focus {
background: #f9f9f9; /* Show a solid color for older browsers */
background: -moz-linear-gradient(#f9f9f9, #e5e5e5);
background: -o-linear-gradient(#f9f9f9, #e5e5e5);
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#f9f9f9), to(#e5e5e5)); /* Older webkit syntax */
background: -webkit-linear-gradient(#f9f9f9, #e5e5e5);
color: #373737;
}
#access ul li:hover > ul {
display: block;
}
回答by mkk
it means that only "first nested" elements will be targeted ("child" elements), for example
这意味着只有“第一个嵌套”元素将被定位(“子”元素),例如
<div id="a">
<div id="b">
<div id="c">
</div>
</div>
</div>
if you write
如果你写
#a div{
background: red;
}
then both #b and #c will be red, but if you use > like
那么 #b 和 #c 都会是红色的,但是如果你使用 > 喜欢
#a > div{
background: red;
}
then only #b will be red, #c will not.
那么只有#b 会是红色的,#c 不会。
回答by David Brainer
That is a child selector (also called a child combinator). You can find out more about selectors on the website of the World Wide Web Consortium (W3C), where you can read the CSS2 entry on the child selectoror you can skip straight to the CSS3 entry on the child selector.
那是一个子选择器(也称为子组合器)。您可以在万维网联盟 (W3C) 的网站上找到有关选择器的更多信息,您可以在其中阅读子选择器上的 CSS2 条目,也可以直接跳到子选择器上的 CSS3 条目。
Also, here's a great quote from another SO question about CSS Child vs Descendant selectors:
此外,这是另一个关于CSS Child vs Descendant selectors 的SO 问题的精彩引述:
Just think of what the words "child" and "descendant" mean in English:
My daughter is both my child and my descendant
My granddaughter is not my child, but she is my descendant.
想想“孩子”和“后代”这两个词在英语中的意思:
我的女儿既是我的孩子也是我的后代
我的孙女不是我的孩子,但她是我的后代。
回答by Jay
li > a
matches any a element that is a child of li.
See W3C CSS pagefor any selectors.
li > a
匹配作为 li 子元素的任何 a 元素。有关任何选择器,请参阅W3C CSS 页面。