html - Is there a CSS selector for the first direct child only? -
i have following html
<div class="section">    <div>header</div>    <div>           contents           <div>sub contents 1</div>                         <div>sub contents 2</div>    </div> </div>   and following style:
div.section div:first-child  {   ... }   for reason don't understand style getting applied "sub contents 1" <div> "header" <div>.  
i thought selector on style apply first direct child of div class called "section". how can change selector want?
what posted literally means "find divs inside of section divs , first child of parent." sub contains 1 tag matches description.
it unclear me whether want both children of main div or not. if so, use this:
div.section > div   if want header, use this:
div.section > div:first-child   using > changes description to: "find divs direct descendents of section divs" want.
please note major browsers support method, except ie6. if ie6 support mission-critical, have add classes child divs , use that, instead. otherwise, it's not worth caring about.
Comments
Post a Comment