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