Is it possible to apply the CSS rule only if we detect that a div follows the rule?
Example
<div class="div1">...</div>
<div class="div2">..</div>
CSS Example
(if exist div2) .div2 .div1 (aply rule css to div1) {
background-color: red;
}
Is it possible to apply the CSS rule only if we detect that a div follows the rule?
Example
<div class="div1">...</div>
<div class="div2">..</div>
CSS Example
(if exist div2) .div2 .div1 (aply rule css to div1) {
background-color: red;
}
3
Answers
I found the solution:
You can use the
has()
pseudo-class in combination with the next siblingselector:
In this example, the CSS rule .div2 + .div1 targets a .div1 that directly follows a .div2.