← Which CSS rule wins? lesson New set →

CSS Worksheet: Which Rule Wins

HTML and CSS lesson 17: Which CSS rule wins? · Set 250 · 40 questions
TalentJR

Code tip (Stronger first, then later): Strength: #id > .class > element. The stronger selector wins, wherever it is written. Equal strength: the later rule wins.

NameDateTime takenScore ___ / 40
  1. 1.⚖️ Which selector is the weakest? (a) an id selector (b) a class selector (c) an element selector
  2. 2.⚖️ What colour is the text of this element?
    <p class="red" id="end">Hi</p>
    CSS:
    .red { color: blue; }
    .red { color: purple; }
    (a) black (b) blue (c) red (d) purple
  3. 3.⚖️ What colour is the text of this element?
    <h2 class="note" id="end">Hi</h2>
    CSS:
    .note { color: purple; }
    .note { color: blue; }
    (a) blue (b) yellow (c) purple (d) white
  4. 4.⚖️ Two rules with the same selector set a colour. Which one wins? (a) the first one (b) the shorter one (c) neither (d) the later one
  5. 5.⚖️ What colour is the text of this element?
    <h1 class="red" id="main">Hi</h1>
    CSS:
    .red { color: blue; }
    .red { color: green; }
    (a) green (b) blue (c) white (d) red
  6. 6.⚖️ Which selector is the strongest? (a) a class selector (b) an element selector (c) an id selector
  7. 7.⚖️ What colour is the text of this element?
    <p class="box" id="main">Hi</p>
    CSS:
    #main { color: white; }
    .box { color: black; }
    (a) black (b) white (c) orange (d) green
  8. 8.⚖️ What colour is the text of this element?
    <h2 class="big" id="main">Hi</h2>
    CSS:
    #main { color: white; }
    #main { color: yellow; }
    (a) green (b) white (c) yellow (d) orange
  9. 9.⚖️ What colour is the text of this element?
    <h1 class="star" id="main">Hi</h1>
    CSS:
    #main { color: purple; }
    .star { color: green; }
    (a) green (b) black (c) blue (d) purple
  10. 10.⚖️ What colour is the text of this element?
    <h1 class="red" id="intro">Hi</h1>
    CSS:
    h1 { color: red; }
    h1 { color: black; }
    (a) black (b) white (c) red (d) blue
  11. 11.⚖️ What colour is the text of this element?
    <h1 class="note" id="end">Hi</h1>
    CSS:
    .note { color: green; }
    .note { color: black; }
    (a) black (b) blue (c) green (d) red
  12. 12.⚖️ What colour is the text of this element?
    <h1 class="red" id="top">Hi</h1>
    CSS:
    #top { color: red; }
    #top { color: blue; }
    (a) green (b) black (c) red (d) blue
  13. 13.⚖️ What colour is the text of this element?
    <p class="red" id="intro">Hi</p>
    CSS:
    #intro { color: yellow; }
    p { color: green; }
    .red { color: purple; }
    (a) yellow (b) white (c) green (d) purple
  14. 14.⚖️ What colour is the text of this element?
    <p class="note" id="top">Hi</p>
    CSS:
    #top { color: blue; }
    #top { color: red; }
    (a) white (b) blue (c) red (d) black
  15. 15.⚖️ What colour is the text of this element?
    <p class="box" id="hero">Hi</p>
    CSS:
    .box { color: white; }
    p { color: purple; }
    #hero { color: green; }
    (a) red (b) white (c) purple (d) green
  16. 16.⚖️ What colour is the text of this element?
    <p class="star" id="top">Hi</p>
    CSS:
    p { color: green; }
    p { color: orange; }
    (a) orange (b) red (c) yellow (d) green
  17. 17.⚖️ What colour is the text of this element?
    <h1 class="big" id="intro">Hi</h1>
    CSS:
    #intro { color: blue; }
    h1 { color: green; }
    .big { color: purple; }
    (a) blue (b) white (c) purple (d) green
  18. 18.⚖️ What colour is the text of this element?
    <p class="note" id="hero">Hi</p>
    CSS:
    .note { color: red; }
    .note { color: black; }
    (a) purple (b) black (c) yellow (d) red
  19. 19.⚖️ What colour is the text of this element?
    <h2 class="red" id="top">Hi</h2>
    CSS:
    h2 { color: green; }
    h2 { color: blue; }
    (a) green (b) black (c) purple (d) blue
  20. 20.⚖️ What colour is the text of this element?
    <p class="box" id="intro">Hi</p>
    CSS:
    p { color: blue; }
    p { color: red; }
    (a) blue (b) black (c) green (d) red
  21. 21.⚖️ What colour is the text of this element?
    <h1 class="menu" id="intro">Hi</h1>
    CSS:
    h1 { color: green; }
    h1 { color: white; }
    (a) green (b) white (c) yellow (d) purple
  22. 22.⚖️ What colour is the text of this element?
    <h2 class="big" id="top">Hi</h2>
    CSS:
    .big { color: red; }
    h2 { color: green; }
    (a) orange (b) red (c) green (d) black
  23. 23.⚖️ What colour is the text of this element?
    <p class="red" id="hero">Hi</p>
    CSS:
    .red { color: white; }
    p { color: red; }
    (a) purple (b) white (c) red (d) blue
  24. 24.⚖️ What colour is the text of this element?
    <p class="red" id="end">Hi</p>
    CSS:
    p { color: purple; }
    p { color: black; }
    (a) blue (b) black (c) purple (d) red
  25. 25.⚖️ What colour is the text of this element?
    <h2 class="big" id="main">Hi</h2>
    CSS:
    #main { color: orange; }
    #main { color: red; }
    (a) orange (b) red (c) green (d) white
  26. 26.⚖️ What colour is the text of this element?
    <p class="red" id="main">Hi</p>
    CSS:
    .red { color: blue; }
    #main { color: purple; }
    (a) blue (b) yellow (c) white (d) purple
  27. 27.⚖️ What colour is the text of this element?
    <h2 class="box" id="intro">Hi</h2>
    CSS:
    #intro { color: black; }
    #intro { color: red; }
    (a) green (b) red (c) purple (d) black
  28. 28.⚖️ What colour is the text of this element?
    <p class="red" id="intro">Hi</p>
    CSS:
    .red { color: green; }
    p { color: orange; }
    (a) yellow (b) orange (c) green (d) red
  29. 29.⚖️ What colour is the text of this element?
    <p class="menu" id="end">Hi</p>
    CSS:
    p { color: yellow; }
    p { color: blue; }
    (a) white (b) blue (c) orange (d) yellow
  30. 30.⚖️ What colour is the text of this element?
    <h1 class="box" id="hero">Hi</h1>
    CSS:
    .box { color: black; }
    .box { color: blue; }
    (a) green (b) blue (c) orange (d) black
  31. 31.⚖️ What colour is the text of this element?
    <p class="menu" id="hero">Hi</p>
    CSS:
    .menu { color: black; }
    p { color: orange; }
    (a) blue (b) orange (c) white (d) black
  32. 32.⚖️ What colour is the text of this element?
    <h2 class="menu" id="top">Hi</h2>
    CSS:
    #top { color: orange; }
    #top { color: white; }
    (a) black (b) orange (c) green (d) white
  33. 33.⚖️ What colour is the text of this element?
    <p class="menu" id="end">Hi</p>
    CSS:
    p { color: black; }
    p { color: blue; }
    (a) white (b) blue (c) black (d) green
  34. 34.⚖️ What colour is the text of this element?
    <h2 class="red" id="top">Hi</h2>
    CSS:
    #top { color: green; }
    .red { color: black; }
    h2 { color: red; }
    (a) green (b) red (c) black (d) blue
  35. 35.⚖️ What colour is the text of this element?
    <p class="note" id="top">Hi</p>
    CSS:
    #top { color: orange; }
    .note { color: green; }
    p { color: blue; }
    (a) blue (b) green (c) red (d) orange
  36. 36.⚖️ What colour is the text of this element?
    <h1 class="note" id="end">Hi</h1>
    CSS:
    .note { color: black; }
    .note { color: white; }
    (a) white (b) black (c) yellow (d) blue
  37. 37.⚖️ What colour is the text of this element?
    <p class="box" id="main">Hi</p>
    CSS:
    #main { color: yellow; }
    #main { color: purple; }
    (a) blue (b) yellow (c) red (d) purple
  38. 38.⚖️ What colour is the text of this element?
    <h2 class="menu" id="main">Hi</h2>
    CSS:
    #main { color: purple; }
    #main { color: blue; }
    (a) purple (b) blue (c) red (d) orange
  39. 39.⚖️ What colour is the text of this element?
    <h2 class="star" id="main">Hi</h2>
    CSS:
    .star { color: blue; }
    h2 { color: black; }
    (a) black (b) blue (c) purple (d) orange
  40. 40.⚖️ What colour is the text of this element?
    <p class="star" id="logo">Hi</p>
    CSS:
    p { color: yellow; }
    p { color: purple; }
    (a) yellow (b) black (c) purple (d) green

Answer key

  1. an element selector
  2. purple
  3. blue
  4. the later one
  5. green
  6. an id selector
  7. white
  8. yellow
  9. purple
  10. black
  11. black
  12. blue
  13. yellow
  14. red
  15. green
  16. orange
  17. blue
  18. black
  19. blue
  20. red
  21. white
  22. red
  23. white
  24. black
  25. red
  26. purple
  27. red
  28. green
  29. blue
  30. blue
  31. black
  32. white
  33. blue
  34. green
  35. orange
  36. white
  37. purple
  38. blue
  39. blue
  40. purple

Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids