Is it present or absent? Your question is causing confusion :)
If .div1
is present, apply style to .div2
:
Option 1: .div2
directly follows .div1
.div1 + .div2 {
property: value;
}
Option 2: .div2
is a sibling of .div1
:
.div1 ~ .div2 {
property: value;
}
Style .div2
even without .div1
:
This might be a workaround, but you could try doing the opposite.
Style .div2
as usual, then modify the styling using the selectors mentioned above.
If .div1
is not available, .div2
will retain its default styling.
.div2 {
background: #fff;
}
.div1 + .div2 {
background: #f00; /* override */
}
/* or */
.div1 ~ .div2 {
background: #f00; /* override */
}