← Which CSS rule wins? lesson New set →

CSS Worksheet: Which Rule Wins

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

Answer key

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

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