There are many div elements with the same class= "demo" class name on the page. How to use css to select the first div? whose class is demo

there are many div elements with the same class= "demo" class name in the page, but not all of them are in the same parent element. How to use css to select the first div? whose class is demo

Feb.28,2021

what a pure css selector cannot do with different parent elements, change the implementation idea, such as changing the structure or using js.


$('.demo'). Eq (0); so not the first


I don't know whether you use jq or native
var demon_01 = $('.demon'). Eq (0)
var demon_01 = document.querySelectorAll ('.swiper-slide') [0]


people use css a bunch of jQuery disdain->


.test:nth-of-type(N) {
  //  N  div
}
.test:last-child {
  //  div
}
Menu