子代选择器

以多个p标签为例:

当需要选择奇数p标签,将其中的内容变成红色:

方式一:  

 p:nth-child(odd){

   color:red;   

}

方式二:

p:nth-of-type(2n+1){//n从0开始的

    color:red;

}

方式三:

p:nth-of-type(odd){//n从0开始的

    color:red;

}

方式四:

p:nth-child(2n+1){//n从0开始的

    color:red;

}

前面两个与后面两个的区别:如果在p里面在添加其兄弟元素后,前面两个就选择不到奇数p,它是按位置选择的;后面两个是首先针对p元素,针对p元素进行奇偶选择,能精确选择。

posted on 2017-10-15 10:13  comeOngo  阅读(454)  评论(0)    收藏  举报

导航