例如:
div > p.some_class {
/* Some declarations */
}
究竟是什么的>符号是什么意思?
Answer 1:
>是子组合子 ,有时被误称为直系后裔组合子。 1
这意味着选择器div > p.some_class仅选择的段落.some_class是直接嵌套在内部 div ,而不是被内进一步嵌套的任何段落。
一个例证:
Some text here
More text here
什么是选择,什么是不:
选
此p.some_class直接位于内侧div ,因此在两元件之间建立父子关系。
未选中的
这p.some_class是由包含blockquote的内div ,而不是div本身。 虽然这p.some_class是的后代div ,它不是一个孩子; 这是一个孙子。
因此,尽管div > p.some_class不会匹配这个元素, div p.some_class意志,使用后代组合子来代替。
1 很多人去进一步称之为“直子”或“直接子”,但这是完全没有必要的(和令人难以置信的讨厌我),因为一个子元素是通过定义即时无论如何,所以他们的意思是完全一样的事情。 有作为“间接子”没有这样的事。
Answer 2:
> (大于符号)是一个CSS Combinator的。
一个组合子是什么,解释了选择之间的关系。
CSS选择器可以包含多个简单的选择。 简单的选择之间,我们可以包括组合子。
有CSS3中四个不同的组合子:
后代选择(空间)
子选择(>)
相邻的兄弟选择器(+)
一般兄弟选择(〜)
注:
例如:
div > p {
background-color: yellow;
}
Paragraph 1 in the div.
Paragraph 2 in the div.
Paragraph 3 in the div.
Paragraph 4. Not in a div.
Paragraph 5. Not in a div.
输出:
关于CSS组合子的更多信息
Answer 3:
正如其他人提到,这是一个子选择。 下面是相应的链接。
http://www.w3.org/TR/CSS2/selector.html#child-selectors
Answer 4:
它匹配p与类元素some_class是直接一个下div 。
Answer 5:
所有p与类标签some_class这是一个直接的孩子div标签。
Answer 6:
html
lohrem text (it will be of red color )
lohrem text (it will NOT be of red color)
lohrem text (it will be of red color )
css
div > p.some_class{
color:red;
}
所有这一切都直接子女
与.some_class会得到应用到他们的风格。
Answer 7:
(子选择器)中CSS2引入。 DIV p {}选择div元素的所有p元素继承人,而DIV> p选择上等等独生子女p元素,没有隆重的孩子,大孩子盛大。
div p{ color:red } /* match both p*/
div > p{ color:blue } /* match only first p*/
para tag, child and decedent of p.
para inside list.
有关CSS策[讲师和他们使用的更多信息,请查看我的博客, CSS选择器和CSS3选择器
文章来源: