Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Rita Dunne
Rita Dunne
2,753 Points

When to use parentheses

In the section 'More Pseudo-classes' when using the 'not' selector, the example is

input:not([type="submit"]) {
      border:2px solid #000;
      color: #fff;
}

and I took the parentheses away and it didn't work.

But for the challenge using the 'checked' selector, I used

:checked[type="radio"] + label {
xxxxxxxxxxxxxxxxxxx
}

At first I wrote in parentheses around like :checked([type="radio"]) + label and it didn't work.

I was wondering why one of these uses parentheses and the other one does not? What are the rules to using them?

3 Answers

Stone Preston
Stone Preston
42,016 Points

the not uses parenthesis because :not(X), is a functional notation taking a simple selector X as an argument.

So, because it is functional notation it must have parentheses. the checked selector does not use functional notation therefore it does not have parentheses.

A similar functional notation pseudo class selector is :nth-child()

Source: https://developer.mozilla.org/en-US/docs/Web/CSS/:not

James Barnett
James Barnett
39,199 Points

Here's a list of 30 CSS selectors you should know

You only use parentheses for of-type & not selectors.

Rita Dunne
Rita Dunne
2,753 Points

wow thanks so much! Both of those posts are incredibly helpful!