Body selector requires a space before colon - correct?


#1


More of a question/discussion. I've almost finsihed the CSS Selectors course, but I'd been having trouble using pseudo-selectors for children of <body>. So far I've been substituting in a different selector, but I think I found out the correction today, and I just wanted to make sure that this was done on purpose?

To use a pseudo-selector for 'body' you must put a space after the word. Otherwise it doesn't work. So the script below worls

body :nth-child(3) {
    font-size: 26px;
}

However 

body:nth-child(3) {
    font-size: 26px;
}

Does not.
Is this supposed to be the case? It certainly isn't for other selectors like p and a

Thanks

Alex


#2

the space before the colon plays a huge roll, look at this example

okay, so we have a space between div and :first-child, this will select the first element inside div

If you now where to remove the space, the div which is first child of any parent would be selected

i was hoping this example clearly shows the difference


#3

I think I understand.

I must have misunderstood somewhere, because p:first-child; was having an effect wherease body:first-child; wasn't, and I assumed there was a mistake somewhere. No worries, thanks for getting back to me.


#4

if you want me to understand this, you will need to provide code

I do hope you understand now


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.