Looking to style only the .box
div that directly follows the .wrap class in the following code snippet. If it appears after a <p>
tag or any other class besides .wrap
, I do not want to target it.
<div class="wrap">
<div class="box">Apply style to this box</div>
<p>random</p>
<div class="box">Do not apply style to this box</div>
</div>
I attempted to use the adjacent sibling selector, but it doesn't seem effective in this scenario.
.wrap + .box{
background: red;
}
JSFiddle: http://jsfiddle.net/8fjuz7sm/
Using :first-child
isn't an option since it may occur just once too.