Conditional CSS (if div present, set top = x, else, set top = y) -


i have relatively positioned div (call "marker") in markup influences top "y" position of sibling's absolutely positioned child div (call "subject").

the marker div may or may not present in markup. how can write css sibling child div it's top position increased 100px when marker div present in markup.

here's markup when marker div present...

<div class="wrapper">     <div class="marker"></div>       <div class="content"></div>     <div class="sidebar">         <div class="subject"></div>     </div> </div> 

the "subject" div 1 need conditional height defined in css.

here's markup when marker div not present...

<div class="wrapper">     <div class="content"></div>     <div class="sidebar">         <div class="subject"></div>     </div> </div>   

does following work?

.sidebar .subject { top: 0px; } .marker ~ .sidebar .subject { top: 100px; } 

~ adjacent sibling selector; .marker ~ .sidebar matches element of class sidebar after element of class marker , shares same parent.

there's excellent tutorial on sibling etc. selectors here.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -