html - Apply css if element exists using CSS selector -
i have header in such way hide image , span's in pheader div if "banner" exists. there quick way using css selectors? below html code.
<header> <div id="banner"> <!-- main content --> </div> <div class="pheader"> <div class="user-panel"> <div id="hey-user" class="d2c-user-panel"> <img src="../images/defaultheadshot_lg.png" class="userimg"> <!-- hide --> <span class="caret" id="down-arrow"></span> <span class="hey-user d2c-header-username"><b>hello</span> </div> </header>
yes.
#banner + .pheader img, #banner + .pheader span { display:none; }
this selector applies if .pheader
directly after #banner
.
you might find tutsplus article useful:
the 30 css selectors must memorize
.pheader { padding: 1em; background: lightblue; } #banner + .pheader img, #banner + .pheader span { display: none; }
<header> <div id="banner"> <!-- main content --> </div> <div class="pheader"> <div class="user-panel"> <div id="hey-user" class="d2c-user-panel"> <img src="http://lorempixel.com/output/animals-q-c-100-100-3.jpg" class="userimg" /> <span class="caret" id="down-arrow">arrow</span> <span class="hey-user d2c-header-username"><b>hello</b></span> </div> </div> </div> </header>
it's worth noting i've had close few divs in original html structure missing code.
Comments
Post a Comment