CS1109 Lab 2

This lab helps you to master CSS selectors. Put your work in a new folder called lab2 (no spaces, all lowercase), which you should create inside your cs1109 folder, which is inside your public_html folder.

A preliminary exercise

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. Put your answers into a file called quiz.txt, which you should store in your lab2 folder. When you have completed all eight, call one of us over and we will correct your answers.

  1.  
    .food {color: red;}
    .food {color: blue;}
  2.  
    li {color: red;}
    .food {color: blue;}
  3.  
    body ul li {color: red;}
    .food {color: blue;}
  4.  
    li {color: red;}
    ul {color: blue;}
  5.  
    #menu {color: blue;}
    ul {color: red;}
  6.  
    #menu {color: red;}
    .food {color: blue;}
  7.  
    li {color: green;}
    ul {color: red;}
    body {color: blue;}
  8.  
    ul {color: red;}
    body {color: blue;}

This week's work

(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.)

This lab helps you to master CSS selectors. Put your work in a new folder called lab2 (no spaces, all lowercase), which you should create inside your cs1109 folder, which is inside your public_html folder.

Download rainbow.html and save it in your lab2 folder. (Right-click the link and choose Save Link As….) It contains a couple of tags that we haven't covered but that should not be a problem in tackling this lab.

Important.

In your lab2 folder, create a CSS stylesheet, rainbow.css (no spaces, all lowercase) that, from the point of view of colours and background colours, causes rainbow.html to appear as it appears below.

The more elegant your stylesheet is, the better!

You only need to write rules that change color and background-color. The colours I have used are: black, white, red, purple, lime, blue, aqua, and yellow.

Deadline: 1pm, Tuesday 23rd October.

If you have named your files and folders correctly, your work will be collected automatically at that time by my software.

A screenshot of how rainbow.html should appear when this exercise is complete.

Challenge exercise

Challenge exercises are always optional. They do not form part of your year's work and they are not worth any marks. They are designed for those students who finish the main exercise quickly and easily, and wish to explore further.

This challenge is to find the shortest CSS stylesheet that can do the job. You can interpret short in one of two ways: fewest rules or fewest characters.

We'll make this a competition. If you think you've got a potential winner, before the submission deadline (above), create a subfolder of your lab2 folder, call it challenge, and put your short version of rainbow.css into it. The shortest may or may not win a prize. Judge's decision (my decision) is final.