Problem with odd/even child elements in nth-child

前端 未结 2 1967
闹比i
闹比i 2020-12-06 10:40

I have a web site like this:



    
    

        
相关标签:
2条回答
  • 2020-12-06 11:17

    Use nth-of-type instead:

    Live Demo

    div.section
    {
        border: 1px solid black;
    }
    div.section div:nth-of-type(even)
    {
        color: Green;
    }
    div.section div:nth-of-type(odd)
    {
        color: Red;
    }
    
    0 讨论(0)
  • 2020-12-06 11:23
    div > :nth-child(3)     the third child of a div element
    div > :nth-child(even)  every even child of a div element
    div > :nth-child(odd)   every odd child of a div element
    div > :nth-child(3n)    every third child of a div element
    
    0 讨论(0)
提交回复
热议问题