I am trying to create odd and even headings related to content. They are inside several DIVs, and I cannot get nth-child or nth-of-type to work, only odd styles are displayed. Here are some conceptual codes:
HTML:
<div class="content"> <h2>Welcome to my blog</h2> <div class="post"> <h2><a href="myPostLink">This is a post</a></h2> <div class="entry"> <p>here is some content</p> </div> <div class="meta"><p>Here is meta info</p></div> </div> <div class="post"> <h2><a href="myPostLink">This is another post</a></h2> <div class="entry"> <p>here is some more content</p> </div> <div class="meta"><p>Here is meta info</p></div> </div> </div>
CSS
.content h2 a:nth-of-type(odd){color: #444;} .content h2 a:nth-of-type(even){color: #ccc;}
jsfiddle
My thinking process was that, starting with .content in my CSS, the first .content h2 a will be considered odd, and the second even, etc. Apparently not so - they are all considered the first child. Is there a way to select the headers the way I want, only using CSS? Am I doing something stupid?
Thanks,
Ricky
css css-selectors
ricky
source share