html - Apply css rule only if previous div exists -


if have div-a , div-b, possible apply css rule div-b if div-a exists? or apply rule div-a if div-b exists? (without using jquery).

<div class="box"> <div class="div-a>..</div> <div class="div-b>..</div> </div> 

generally, no. unless div-b child or sibling of div-a.

for descendant:

.div-a .div-b 

for direct children:

.div-a > .div-b 

for siblings:

.div-a ~ .div-b 

for adjacent siblings:

.div-a + .div-b 

see child , sibling selectors.

note these relations work 1 way only. in cases provided above, applied div-b, if div-b inside (child) or after (sibling) div-a. given mark-up, use sibling or adjacent sibling combinator style div-b, there no way style div-a conditionally.

i think best option add class parent if contains div-b. use simple combined selector .parent-class .div-a style it.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -