CSS3 里的子元素选择器是怎么用的.比如h1 p{ color:black} 这是啥意思. 和h

html-css06

CSS3 里的子元素选择器是怎么用的.比如h1 p{ color:black} 这是啥意思. 和h,第1张

加不加大于号的区别是:

加上大于号就表示必须是”直接子元素“,不加的话只要是子元素就行。

比如如下html:

<h1>

    <div>

         <p>some text</p>

    </div>

</h1>

那么h1  p就可以选择到”some text",而h1>p就不能。

li:nth-child(3n+1){background:orange}/*匹配第1、第4、第7、…、每3个为一组的第1个LI*/

li:nth-child(3n+5){background:orange}/*匹配第5、第8、第11、…、从第5个开始每3个为一组的第1个LI*/

li:nth-child(5n-1){background:orange}/*匹配第5-1=4、第10-1=9、…、第5的倍数减1个LI*/