css3伪类选择器nth-of-type,:nth-last-of-type,:first-of-type,:last-of-type,:only-of-type

时间:2023-01-30 12:34:24

1, :nth-of-type(n) 匹配属于父元素的特定类型的第N个子元素

css3伪类选择器nth-of-type,:nth-last-of-type,:first-of-type,:last-of-type,:only-of-type

匹配结果:

css3伪类选择器nth-of-type,:nth-last-of-type,:first-of-type,:last-of-type,:only-of-type

2, :nth-last-of-type(n),匹配其父元素下的第N个特定类型的子元素,从后往前

满足条件:1,必须是特定类型    2,从后往前的第N个

3,:first-of-type 

css3伪类选择器nth-of-type,:nth-last-of-type,:first-of-type,:last-of-type,:only-of-type

css3伪类选择器nth-of-type,:nth-last-of-type,:first-of-type,:last-of-type,:only-of-type

4,  :last-of-type 匹配其父元素下的最后一个特定类型的子元素

         body div:last-of-type 满足条件,body下的所有DIV元素,最后一个DIV

5, :only-of-type 选择其父元素上的唯一一个相同类型的子元素

css3伪类选择器nth-of-type,:nth-last-of-type,:first-of-type,:last-of-type,:only-of-type

css3伪类选择器nth-of-type,:nth-last-of-type,:first-of-type,:last-of-type,:only-of-type

6, :empty()  空选择器

7, :not()  否定选择器

  

<nav>
        <a href="#">1</a>
        <a href="#">2</a>
        <a href="#">3</a>
        <a href="#">4</a>
        <a href="#">5</a>
    </nav>
 *{
           margin:0;
           padding:0;
       }
        nav{
            margin:0 auto;
            width:530px;
            font-size:0;
        }
        a{
            text-decoration: none;
            display: inline-block;
            width:100px;
            height:30px;
            line-height:30px;
            text-align: center;
            font-size:14px;
            margin-left:5px;

        }
        nav > a:not(:last-of-type){
            border-right:1px solid red;
        }

css3伪类选择器nth-of-type,:nth-last-of-type,:first-of-type,:last-of-type,:only-of-type