Challenge - 5 Problems
Not Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ selector
intermediateUsing :not() to exclude elements
Given the HTML below, which CSS selector will color all
elements except those with class exclude in red?
CSS
<section> <p>Paragraph 1</p> <p class="exclude">Paragraph 2</p> <p>Paragraph 3</p> <p class="exclude">Paragraph 4</p> </section>
Attempts:
2 left
💡 Hint
Use :not() with the class selector inside parentheses to exclude elements with that class.
✗ Incorrect
The :not() selector excludes elements matching the selector inside it. Here, p:not(.exclude) selects all
elements that do NOT have the class 'exclude'. Option C colors those paragraphs red as required. Option C is invalid syntax because #exclude is an ID selector and missing parentheses. Option C colors the correct elements but uses blue instead of red. Option C changes background color, not text color.
❓ selector
intermediateSelecting inputs except checkboxes
Which CSS selector will select all elements except those of type checkbox?
CSS
<form> <input type="text" /> <input type="checkbox" /> <input type="radio" /> <input type="password" /> </form>
Attempts:
2 left
💡 Hint
Use attribute selectors inside :not() to exclude inputs with type checkbox.
✗ Incorrect
Option B correctly uses the attribute selector [type="checkbox"] inside :not() to exclude checkbox inputs. Option B is invalid syntax because it misses brackets around the attribute selector. Options A and D try to exclude by ID or class which do not apply here.
❓ rendering
advancedVisual effect of :not() with multiple classes
Consider the CSS below. What color will the
with classes
box and highlight have?CSS
<style> .box:not(.highlight) { background-color: yellow; } .box.highlight { background-color: blue; } </style> <div class="box highlight">Test Box</div>
Attempts:
2 left
💡 Hint
Check which selectors apply and which have higher specificity.
✗ Incorrect
The div has both classes 'box' and 'highlight'. The selector .box:not(.highlight) excludes elements with class 'highlight', so it does not apply here. The selector .box.highlight applies and sets background to blue. Therefore, the background color is blue.
🧠 Conceptual
advancedUnderstanding :not() with complex selectors
Which statement about the CSS selector
div:not(.active) > p is true?Attempts:
2 left
💡 Hint
Look carefully at the combinator and :not() placement.
✗ Incorrect
The selector div:not(.active) > p means: select
elements that are direct children (>) of
elements that do NOT have the class 'active'. Option A states this correctly. Option A is incorrect because it says nested descendants, but > means direct children only. Option A incorrectly applies :not() to
elements. Option A selects
elements, but the selector targets
elements.
❓ accessibility
expertUsing :not() for accessible focus styling
You want to style all interactive elements except disabled buttons when they receive keyboard focus. Which CSS selector correctly applies a visible outline only to those elements?
Attempts:
2 left
💡 Hint
Use :not() to exclude disabled elements before applying :focus-visible.
✗ Incorrect
Option D correctly selects buttons, links, and inputs that are not disabled and are focused via keyboard (:focus-visible). Option D places :focus-visible before :not(:disabled), but best practice is to exclude first. Option D uses :not(:disabled:focus-visible) which doesn't properly target the focus state. Option D uses :focus instead of :focus-visible, which is less accessible because it applies on mouse focus too.
Practice
1. What does the CSS
:not() selector do?easy
Solution
Step 1: Understand the purpose of
The:not():not()selector excludes elements that match the selector inside it.Step 2: Identify what it selects
It selects all elements except those that match the selector inside:not().Final Answer:
It selects all elements except those matching the selector inside:not(). -> Option BQuick Check:
:not()excludes matching elements [OK]
Hint: Think 'everything but' the selector inside
:not() [OK]Common Mistakes:
- Thinking it selects only matching elements
- Confusing it with :only-child or :empty
- Assuming it selects hidden elements
2. Which of the following is the correct syntax to select all
p elements except those with class intro?easy
Solution
Step 1: Check the syntax for
The correct syntax uses parentheses with a class selector inside::not()with class selector:not(.intro).Step 2: Verify the selector targets
pelements except those with classintrop:not(.intro)means allpelements except those with classintro.Final Answer:
p:not(.intro) { color: blue; } -> Option AQuick Check:
Correct:not()syntax uses parentheses and proper selector [OK]
Hint: Use parentheses and proper selector inside
:not() [OK]Common Mistakes:
- Using square brackets instead of parentheses
- Missing dot for class selector
- Using # instead of . for class
3. Given this HTML:
And CSS:
What color will the text inside each
<div> <p class="intro">Hello</p> <p>World</p> <p class="note">Note</p> </div>
And CSS:
p:not(.intro) { color: red; }What color will the text inside each
<p> be?medium
Solution
Step 1: Identify which
Thepelements match:not(.intro)pwith classintrois excluded. The other twopelements match.Step 2: Determine the color applied
Onlypelements without classintrogetcolor: red;. So "World" and "Note" are red, "Hello" stays default black.Final Answer:
Hello: black (default), World: red, Note: red -> Option AQuick Check:
:not(.intro)excludes "Hello" [OK]
Hint: Only elements NOT matching inside
:not() get styles [OK]Common Mistakes:
- Assuming all
pget red color - Confusing which elements are excluded
- Ignoring default browser styles
4. What is wrong with this CSS selector?
div:not .highlight { background: yellow; }medium
Solution
Step 1: Check syntax of
The:not()usage:not()selector requires parentheses around the selector inside it.Step 2: Identify the error in the given selector
The selector uses:not .highlightwithout parentheses, which is invalid syntax.Final Answer:
Missing parentheses around the selector inside:not(). -> Option CQuick Check:
:not()always needs parentheses [OK]
Hint: Always use parentheses immediately after
:not [OK]Common Mistakes:
- Omitting parentheses in
:not() - Adding space between
:notand parentheses - Assuming
:notworks like a combinator
5. You want to style all
button elements except those that are disabled or have the class cancel. Which CSS selector achieves this?hard
Solution
Step 1: Understand multiple exclusions with
To exclude multiple selectors, chain multiple:not():not()selectors.Step 2: Analyze each option
button:not(:disabled):not(.cancel) { background: green; } correctly chains:not(:disabled)and:not(.cancel). button:not(:disabled, .cancel) { background: green; } tries to combine selectors inside one:not(), which is invalid. button:not(:disabled .cancel) { background: green; } uses invalid syntax. button:not(:disabled) .cancel { background: green; } selects.cancelinsidebutton:not(:disabled), which is incorrect.Final Answer:
button:not(:disabled):not(.cancel) { background: green; } -> Option DQuick Check:
Chain multiple:not()for multiple exclusions [OK]
Hint: Chain multiple
:not() for multiple exclusions [OK]Common Mistakes:
- Trying to combine selectors inside one
:not() - Using spaces inside
:not()incorrectly - Misunderstanding descendant selectors
