Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Css 3 Selector not working proberly

Css 3 Selector not working proberly

Problem

I'm trying to do something what I thought would be a simple task but it wasnt that quite simple... the issue in hand can be seen on this 2 links

http://kurdaktuellt.se/

http://kurdaktuellt.se/category/aktuellt/

the Selector im using is rather simple

body:not(.single) #content > .post:nth-child(odd){
}
body:not(.single) #content > .post:nth-child(even){
}

The thing is that it work one way on the front page(first link) and another way on the category page(the second link) it's as it takes a count the header element which it shouldnt if it would follow my selector properly... Is there something im missing here?

all help is appreciated... aloot! thx in advance

Problem courtesy of: Breezer

Solution

In your categories page you have an h1 as the first child of #content, which is interfering with the ordering of your children, causing your first div.post to no longer be the first child but really the second child (see the spec).

You can either use :nth-of-type() instead so only your divs (which have the class .post) are taken into account:

body:not(.single) #content > div.post:nth-of-type(odd)
body:not(.single) #content > div.post:nth-of-type(even)

Or you can choose to modify your HTML instead, either by moving that h1 elsewhere, or by adding another container around your div.post elements, such that your :nth-child() ordering won't be messed up.

Solution courtesy of: BoltClock

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

Css 3 Selector not working proberly

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×