CSS3 selector :first-of-type with class name?

后端 未结 9 1982
梦毁少年i
梦毁少年i 2020-11-22 03:06

Is it possible to use the CSS3 selector :first-of-type to select the first element with a given class name? I haven\'t been successful with my test so I\'m thin

9条回答
  •  无人及你
    2020-11-22 03:36

    I found a solution for your reference. from some group divs select from group of two same class divs the first one

    p[class*="myclass"]:not(:last-of-type) {color:red}
    p[class*="myclass"]:last-of-type {color:green}
    

    BTW, I don't know why :last-of-type works, but :first-of-type does not work.

    My experiments on jsfiddle... https://jsfiddle.net/aspanoz/m1sg4496/

提交回复
热议问题