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