0

I have :

<div class="myclass"> 
   <div >
       <div>
           <div>
           </div>
       </div>
   </div>
</div>

Ok, I'm using .myclass div:first-child {} to give style to the first div but I discover how the style is applied by inheritance to the nested divs....????
Any idea what I'm doing bad ?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
civiltomain
  • 1,136
  • 1
  • 9
  • 27
  • I recommend using classes to style your div's. – syrkull Jan 22 '15 at 19:42
  • This depends on the styles you're applying. Right now you're actually applying to all the inner divs because they are the first children of their own parent divs, so no inheritance is actually occurring. But even if you select just the one you're looking for, the inner ones can still inherit if the properties are set to inherit by default, like `color`. – BoltClock Jan 22 '15 at 19:42
  • possible duplicate of [css selector for first direct child only](http://stackoverflow.com/questions/2094508/css-selector-for-first-direct-child-only) – TylerH Jan 22 '15 at 19:49

1 Answers1

5

.myclass > div:first-child {} will only affect the direct child div.

More information on the various selectors available is here: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/Selectors

rwacarter
  • 1,915
  • 1
  • 14
  • 25