How to add CSS if element has more than one child?

前端 未结 6 1814
不思量自难忘°
不思量自难忘° 2020-12-28 14:40

I have td tags and a several div inside td:


   
6条回答
  •  不知归路
    2020-12-28 15:29

    Well actually you can do this with css using the nth-last-child selector

    FIDDLE

    So if your markup was like this:

    test
    test

    test

    CSS

    div:nth-last-child(n+2) ~ div:last-child{
        margin-bottom: 40px;
    }
    

    ... the above css will style the last div element only if there exists a container that has at least 2 child divs

    Just to see how this works better - here's another example fiddle

提交回复
热议问题