I just have some child div with a some class, in this case .element. And first one with some other class, in this case .skip. I need to don’t count that element, like it doesn’t exist. So if i take every odd div with .element class to take same divs even if .skip div is there or deleted. If it possible with some css selector like you can with .nth-of-type if that .skip element isn’t a div, or somehow just with css to make it hidden to nth selector.
It’s important not to use javascript.
<div>
<div class="skip">no</div>
<div class="element">1</div>
<div class="element">2</div>
<div class="element">3</div>
<div class="element">4</div>
<div class="element">5</div>
<div class="element">6</div>
</div>
3
Answers
simply ignore the skip div and take only odd values of element divs like so:
https://codepen.io/ibrahim-abboud/pen/JjaNVPR
If you can use different HTML tags for the elements mentioned, you could still define a
nth-of-child
selector. For instance, adding strikethrough to all odd elements withelement
classYou can try this. It reads the following way: "If there is a .element element that’s preceded by a .skip element, when the .element element is in an even position do whatever css rules establish". You will need to switch selections -> odd becomes even and even becomes odd (in your case, odd numbers are in even positions). I’ve added a color change to make it obvious. Switching it to odd will select 2,4,6 etc.