In the scenario where there is an HTML element with multiple siblings:
<div id=parent>
<div></div>
<div></div>
<div></div>
...
<div id=fourthToLast></div>
<div></div>
<div id=penultimate></div>
<div></div>
</div>
The penulimate and the fourthToLast siblings have unique requirements: One of them - never both - should be displayed at different widths based on media breakpoints and total number of siblings.
I've attempted to use pseudo-selectors in my CSS code:
silibingNrOf(#penultimate) mod x = y
For instance, if there are a total of 15 siblings inside the parent element, then silibingNrOf(#penultimate) will be 14.
silibingNrOf(#penultimate) mod 3 would return 2.
I am struggling to find the correct CSS selector syntax for this situation:
#fourthToLast, #penultimate { display: none; }
@media screen and (min-width: 400px) {
if silibingNrOf(#penultimate) mod 2 = 0 {
#penultimate { width: 25%; display: block; }
}
@media screen and (min-width: 800px) {
#penultimate { display: none; }
if silibingNrOf(#penultimate) mod 3 = 2 {
#penultimate { width: 33%; display: block; }
}
if silibingNrOf(#penultimate) mod 3 = 0 {
#fourthToLast { width: 16.666%; display: block; }
}
}
}