This lab helps you to master CSS selectors.
Consider the following fragment of HTML:
<body> <ul id="menu"> <li class="food">badger burgers</li> <li class="food">wombat waffles</li> </ul> </body>
Without using your computer, work out the colour of the phrase "badger burgers" for each of the following stylesheets. Write your answers on a sheet of paper. When you have completed all 8, call one of us over and we will correct your answers.
.food { color: red; } .food { color: blue; }
li { color: red; } .food { color: blue; }
body ul li { color: red; } .food { color: blue; }
li { color: red; } ul { color: blue; }
#menu { color: blue; } ul { color: red; }
#menu { color: red; } .food { color: blue; }
li { color: green; } ul { color: red; } body { color: blue; }
ul { color: red; } body { color: blue; }
(My thanks go to the fine men and women of the National Weather Service Forecast Western Region Headquarters in Salt Lake City for their description of rainbows, which I have adapted for use in this worksheet.)
Download the following file to your public_html
directory and fix its permissions:
Important. For this lab, you must not modify rainbow.html
.
Use Kate to create a CSS stylesheet called rainbow.css
in your public_html
directory.
(Fix its permissions.) Your goal is to write a stylesheet that makes rainbow.html
appear like
this:
You only need to set the color
and background-color
properties. And the colours I have used are:
black
white
gray
red
lawngreen
yellow
blue
Your work will be checked by Derek Bridge some time after Friday 25th October.
Challenge exercises are always optional. They are designed for those students who finish the main exercise quickly and easily, and wish to explore further.
Download the following file to public_html
:
challenge.html
is basically identical to raninbow.html
.
The challenge is to find the smallest stylesheet that can do the job. Put your stylesheet into a file
called challenge.css
in your public_html
. As before, you must not
edit the HTML.
Here's what I mean by shortest: the one with the fewest characters. But note that each rule in your stylesheet must start on a separate line. As a guide to how well you're doing: the shortest is well below 200 characters!
We'll make this a competition — a competiton with a big money prize. If you think you've got a potential winner,
then email me your challenge.css
as an attachment by Friday 25th October.