Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to CSS select each first div without class after div with class?

Tags:

html

css

How to CSS select each first div without class following after div with certain class? Example:

<div class="someclass"></div>
<div class="someclass"></div>
<div class="someclass"></div>
<div></div> <!-- must be selected -->
<div></div>
<div></div>
<div class="someclass"></div>
<div class="someclass"></div>
<div class="someclass"></div>
<div></div> <!-- must be selected -->
<div></div>
<div class="someclass"></div>
<div class="someclass"></div>
<div class="someclass"></div>
<div class="someclass"></div>
<div></div> <!-- must be selected -->
<div class="someclass"></div>
<div class="someclass"></div>
<div></div> <!-- must be selected -->
<div></div>
<div></div>
<div></div>
<div class="someclass"></div>
<div class="someclass"></div>

Is it possible to select it without JS/JQuery?

like image 640
Kainax Avatar asked Dec 09 '22 03:12

Kainax


2 Answers

you can try using following CSS

   .someclass + div:not(.someclass, .someclass) {
    }

Use can pass multiple values in not selector if you have different classes in this structure

like image 93
Vineeta Mehta Avatar answered Feb 13 '23 04:02

Vineeta Mehta


try https://jsfiddle.net/jr9wsr49/

CSS

.someclass + div:not(.someclass) {
  background:green
}
like image 38
Nilesh Mahajan Avatar answered Feb 13 '23 03:02

Nilesh Mahajan