Joystick Junkies: The CSS Language (Lab 3)

This is Lab 3 in Developing Web Pages (BUS1880) and Web Fundamentals (CSCI1450). Before you start Lab 3, be sure you have studied, watched the videos, and completed the exercises in the Slideshow for Module 3.

The objective of this lab assignment is to learn some beginning CSS, including selectors, properties, and values, while styling your first website with fonts, colors, and spacing.

This lab requires that you have completed Lab 2. Beyond that, all the code you need is provided here.

Jump to:

What is different from the Lab 2 to Lab 3? You can see the differences in the screenshots below. In this module we are going to add background colors, text colors, and font changes.

Side by side comparison of the Joystick Junkies home page after Lab 2, with no CSS, and after Lab 3, with fonts and colors applied

A. Attach and Test Your Stylesheet

In this section, we’ll connect your stylesheet to both HTML pages and make sure it’s actually working before building out any real styles.

Attach CSS Stylesheet

First, let’s link your stylesheet to both HTML pages.

Step 1. Open the index.html file. Copy the <link> below and add to your stylesheet between <head> and </head>: (See the lesson on Attaching an External Stylesheet for more detail.)

<link rel="stylesheet" href="style.css">

Step 2. Repeat in the gaming-systems.html file.

Code showing the head section with the meta charset, title, and link tag referencing style.css

Test the Stylesheet

Let’s add a pink background color temporarily, just to make sure we have the stylesheet connected correctly.

Step 1. Open the style.css file.

Step 2. Add a temporary background-color to the body and test to see if it is linked correctly. Here is the code you need:

body{
   background-color:pink;
}

Check the browser. Your website should looks like the screenshot below:

Home page with a temporary pink background color to test that the stylesheet is linked correctly

If the pink background-color doesn’t appear on index.html and gaming-systems.html, then we need to diagnose the problem:

  1. Is the CSS file name exactly the same in the HTML reference (e.g. style.css)?
  2. Is the CSS file in the same folder as the HTML file and at the same level?
  3. Did you save all three files: index.html, gaming-systems.html, and style.css?

White Background

Now that we know that the style.css stylesheet is attached, we can change the background-color back to white. The hex color for white is #FFFFFF.

Code setting the body background-color back to white

B. Add Fonts

In this section, we’ll install custom Google Fonts for the site.

Install the Google Fonts on the website. We are going to use Open Sans for regular text, and the Play font for headings for Joystick Junkies. (For more detail, see the lesson on Font Families and Google Fonts.)

Step 1. Add this  import tag. It is important that the @import tag be at the top of the CSS file.

@import url('https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&family=Play:wght@400;700&display=swap');

Step 2. Find the body selector.

Step 3. Add this font-family: font-family: “Open Sans”, sans-serif;

Step 4. Create a new selector for the h1, h2, and h3 tags. You can have more than one selector by putting a comma between the selectors. Set the font-family to: font-family: “Play”, sans-serif;

Check your code against the screenshot below:

Code for the Google Fonts import line and the body and heading font-family rules

Check the fonts in the browser:

Home page showing the Play font used for headings and the Open Sans font used for body text

C. Style the Header

In this section, we’ll add color and style to the header, style the logo text inside of it, and clean up the white space around it.

Select the header Element

Now let’s add some color and style to the header itself.

Step 1. In style.css, add header as a selector.

Step 2. Set the background color to #00195C, a dark blue color.

Step 3. Set the text color to #FFFFFF. #FFFFFF is white. (For more on choosing and writing colors, see the lesson on CSS Colors.)

Step 4. Center the text with the text-align property.

Code for the header selector with background-color, text color, and text-align

Save style.css and view the index.html file in the browser. The header should look like the screenshot below.

Header styled with a dark blue background and centered white text

Select the h1 Inside the Header

Next, let’s style the heading text inside the header.

Step 1. Make a new header h1 selector in style.css. In English, selecting header h1 means “select h1 elements only if they are inside of the header.” (This is a descendent selector.)

Step 2. Add line-height: 200% to the h1 selector. What this step does is add more space above and below the <h1> text by setting the line height to 200%. (See the lesson on Font and Text Properties for more detail.)

Step 3. Add margin: 0 to the header h1 selector.

Step 4. Add color: #FFFFFF to the header h1 selector.

Code for the header h1 selector with line-height, margin, and color

Save your file and check it in index.html in the browser.

Remove White Space

See the white space around the <header>? Browsers come with their own built-in CSS, called a user agent stylesheet, that applies baseline styles before any of your own CSS loads. One of those defaults adds 8px of margin around the <body> element on every page, which is exactly the small gap you’re seeing now. We can override that default with a simple fix. This matters because going edge to edge, with no gap around the outside of the page, is part of how modern websites are designed.

Step 1. Find the existing body selector.

Step 2. Add margin: 0 to the selector. The code looks like this:

Code for the body selector with background-color, font-family, and margin 0

Now check in the browser and make sure you <header> looks like the After screenshot.

Before and after comparison showing the default margin removed from around the header

D. Style the Navigation

In this section, we’ll give the navigation bar some style.

Step 1. Add a selector for the nav element in style.css.

Step 2. Set the navigation font to bold with the font-weight property.

Step 3. Set the background-color to #EEEEEE. #EEEEEE is a light gray.

Step 4. Center the text with the text-align property.

Step 5. Add a line-height of 200% to give it more space.

Code for the nav selector with font-weight, background-color, text-align, and line-height

Save and check the index.html file in the browser. It should look like the screenshot below.

Navigation styled with a light gray background, bold centered text, and added line height

E. Style the Headings

In this section, we’ll add some color to the headings on the Gaming Systems page.

Step 1. Find the existing h1, h2, h3 selector.

Step 2. Set the text color to the same dark blue color in the header: #00195C.

Code for the h1, h2, h3 selector setting font-family and color

Save and check the result in the browser. The result should look like the screenshot below.

Gaming systems page headings shown in the same dark blue color as the header

F. Style the Main Section

Notice how the text in the main section touches the left side? We need to add CSS styles to the <main> section. We are going to add a max-width and center the content.

Note: We will learn more about padding and margin in upcoming modules. Just use the code provided for now.

Step 1. Add a main selector.

Step 2. Add a max-width of 1000px.

Step 3. Add a margin to center the text. Use this property/value: margin: 30px auto; (See the lesson on Centering Content with CSS for more detail.)

Step 4. Add 10px of padding.

Code for the main selector with max-width, margin, and padding

What does the property/value margin: 30px auto do? The code is adding 30 pixels to the top and bottom, and auto to the sides. Adding auto to the sides centers the content of the <main> element.

Check in a browser: In the last step, we added a max-width and centering to the main section. In order to see the max-width applied your browser view must be over 1000px in width. Drag the sides of your browser window so you can see the max-width in action.

Browser screenshot of the home page with the main section's max-width and centering applied

In this section, we’ll style the footer to match.

Step 1. Add a footer selector.

Step 2. Add a max-width of 1000px.

Step 3. Add a margin to center the text. Use this property/value: margin: 30px auto;

Step 4. Add 10px of padding.

Step 5. Add a font-style of italic.

Step 6. Center the footer text with the text-align property.

Code for the footer selector with max-width, margin, padding, font-style, and text-align
Footer styled with italic centered text

Final Pages Check

Check the browser to make sure your work looks like the screenshots below.

The finished index.html and gaming-systems.html pages shown together after all Module 3 CSS styling is applied

Checklist for Grading

Here is a checklist of what I will be looking for when grading the lab:

From the Module 3 Slideshow

When you worked through Module 3, you added to your website template. The template work will be graded as part of this lab.

Joystick Junkies Lab


Now you know some CSS! Move on to Lab 4 to learn about website images.

This is how the Joystick Junkies looks after Lab 3. There are CSS color and fonts.

Need Help?

Using AI for coding is not allowed in this course, so if you get stuck simply Make an Appointment for office hours. In addition, if you run into a bug as you are working, you may email your websites folder to me at susan.metoxen@saintpaul.edu.

Browse All Lessons

CSS Design Tools