0
0
CSSmarkup~20 mins

Not selector in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Not Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
selector
intermediate
2:00remaining
Using :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>
Ap:not(.exclude) { color: blue; }
Bp:not(#exclude) { color: red; }
Cp:not(.exclude) { color: red; }
Dp:not(.exclude) { background-color: red; }
Attempts:
2 left
💡 Hint
Use :not() with the class selector inside parentheses to exclude elements with that class.
selector
intermediate
2:00remaining
Selecting 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>
Ainput:not(type="checkbox") { border: 2px solid green; }
Binput:not([type="checkbox"]) { border: 2px solid green; }
Cinput:not(#checkbox) { border: 2px solid green; }
Dinput:not(.checkbox) { border: 2px solid green; }
Attempts:
2 left
💡 Hint
Use attribute selectors inside :not() to exclude inputs with type checkbox.
rendering
advanced
2:00remaining
Visual 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>
ABlue background
BYellow background
CNo background color
DBoth yellow and blue backgrounds layered
Attempts:
2 left
💡 Hint
Check which selectors apply and which have higher specificity.
🧠 Conceptual
advanced
2:00remaining
Understanding :not() with complex selectors
Which statement about the CSS selector div:not(.active) > p is true?
ASelects all <p> elements that are direct children of <div> elements without class 'active'.
BSelects all <p> elements inside any <div> that does not have class 'active', including nested descendants.
CSelects all <p> elements that do not have class 'active' and are inside any <div>.
DSelects all <div> elements that do not have class 'active' and contain <p> children.
Attempts:
2 left
💡 Hint
Look carefully at the combinator and :not() placement.
accessibility
expert
3:00remaining
Using :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?
A:is(button, a, input):not(:disabled:focus-visible) { outline: 3px solid orange; }
B:is(button, a, input):focus-visible:not(:disabled) { outline: 3px solid orange; }
C:is(button, a, input):focus:not(:disabled) { outline: 3px solid orange; }
D:is(button, a, input):not(:disabled):focus-visible { outline: 3px solid orange; }
Attempts:
2 left
💡 Hint
Use :not() to exclude disabled elements before applying :focus-visible.