My ‘tour-boxes’ are not full page width and I’d like to push them to either side of the browser alternating left and right. And I’ve created little arrows which point downwards to the next box and direct the user flow. I’ve got this in my CSS
Everything was working just fine yesterday.but for some reason today, it seems like only the :nth-child(odd) selectors are being applied and they are applied event to the (even) boxes.
I can’t for the life of me figure out what has happened. You can see a live version in development at http://couturemedia.ca/sandbox/how-it-works/ and it’s behind a wall; user: child pw: splay
Any tips on troubleshooting this would be awesome. I’ve validated HTML and the CSS only triggers an error with some media queries which I disabled for testing and which didn’t have any effect.
That somnambulist must have been my alter ego. I used as a cheap way to space things out a bit more even though I had also placed CSS margin-bottom: of 10rem when I should have just removed the . WP then wrapped those non-breaking spaces in p tags.
So it seems this was really a misunderstanding of how the :nth-child() pseudo class works. As I saw those p tags and I didn’t see how they should affect the :nth-child behaviour. From my understanding the following selector
.tour-box:nth-child(odd) {..}
should only be counting (or registering) all elements with the class ‘tour-box’. which are the divs, not the <p>s. Looking at the W3C definition
The :nth-child(n) selector matches every element that is the nth child, regardless of type, of its parent.
I am surprised to see the ‘regardless of type’ at the end. And I smiled to see the suggested link to :nth-of-type as the selector which I believe would have rectified the issue?
It is very common for coders, the first-time they use the nth-child pseudo-class, to assume that :nth-child looks at the type, class and/or ID rather than simply the number of all children. Most have never heard of the :nth-of-type pseudo-class. You are in crowded company.
<off-topic:fyi-only>
The W3Schools company is not the same as the W3Consortium that writes the web standards. The names are conveniently similar, but there is no affiliation.
The W3C reference page for selectors is here: http://www.w3.org/TR/CSS2/selector.html. I use the W3Schools site occasionally, but not as an “authoritative” reference.
Thanks for the clarification on W3Schools. While the reference page on W3C seems to be more legit with them being the body which sets web standards they don’t have any info there about the nth-child selector and thus I would have been up the creek in determining where I was going wrong without W3Schools. I understand it’s because it’s a CSS3 selector, not CSS2. Is CSS3 supported by the W3C?