Joystick Junkies: Layout and Positioning (Lab 5)

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

The objective of this lab assignment is to learn CSS layout and positioning, including floats and pseudo-classes, while styling a more complex navigation.

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

Jump to:

In this module on Joystick Junkies, you will be adding your own color choices to the website. In addition, we will:

  • Nest and indent your code
  • Make the website logo into a link
  • Change the navigation to an unordered list and apply pseudo-classes to the links
  • Style the nav bar
  • Add a floated image to two pages
  • Add a floated text box to one page

A. Nest and Indent Your Code

If you didn’t complete this step in the Module 5 slideshow, do it now. Part of your grade for this week, and going forward, will be how well your code is indented. Also be sure to add the code comments.

  • HTML Comments: <!-- This is a comment -->
  • CSS Comments: /* This is a comment */

In this section, we’ll turn the logo into a clickable link back to the home page, with a hover effect.

Add the Logo as a Link

Ever notice that on most websites, the website logo is a link to the home page? We will do that now by changing the logo into a link.

Step 1. In index.html, add a link to the home page around the <img> tag.

Step 2. Check your indenting. The <img> tag is nested inside of the <a> tag.

Step 3. Copy the <header>…</header> from the index.html page and replace the <header>…</header> on the other two pages.

Code showing the logo image wrapped in an anchor tag linking to index.html

Add a Hover Effect

It helps the user know that the logo is a link by adding a hover effect. An easy hover effect is to change the image opacity.

Step 1. Find the existing .logo selector.

Step 2. Create a new selector directly underneath it. The selector is .logo:hover.

Step 3. Add an opacity of 0.8 (which is 80%).

Step 4. Go to any page in the browser, and hover over the image. You will see the opacity change when you hover over the image.

CSS code for the .logo selector and .logo:hover selector with opacity 0.8

C. Change Navigation to an Unordered List

We need to change our navigation to an unordered list. First we will make the changes in index.html, and then copy it to the other pages.

HTML Changes

Step 1. Change the navigation into an unordered list with <ul> and <li> tags in index.html.

Step 2. Delete the extra non-breaking space (&nbsp;) tags. (We added those in Chapter 2 because we didn’t know the code for margins and padding.)

Step 3. Check your indenting. The indenting needs to show that the <li> tags are inside of the <ul> tags and the <ul> tags are inside of the <nav> tags.

Step 4. Copy the <nav>…</nav> from the index.html page and replace the <nav>…</nav> on the other two pages.

HTML code showing the navigation changed to an unordered list with li and a tags

Check the Changes in a Browser

As you can see, the navigation is now a bulleted list. We also picked up some extra white space we don’t want. We’ll add some CSS to turn off the bullets and format the navigation, and also add our custom colors to the navigation. There are several steps.

Browser screenshot showing the navigation as an unstyled bulleted list

CSS for the nav ul Selector

Step 1. In style.css, add a nav ul selector. Remember that nav ul is a descendent selector, which in English says: “Apply this CSS if it is a ul inside of a nav.”

Step 2. Remove the bullet with the list-style-type property. Set the value to none.

Step 3. Add the margin property with a value of 0 to remove the white space at the top and bottom.

Step 4. Add the padding property with a value of 10px. This restores the white space, but with padding instead of margin.

Check your work in a browser to make sure it looks like the screenshot below before you move on.

Browser screenshot showing the navigation with bullets removed but still stacked vertically

CSS for the nav li Selector

Step 1. In style.css, add a nav li selector. Remember that nav li is a descendent selector, which in English says: “Apply this CSS if it is an li inside of a nav.”

Step 2. Change the navigation to horizontal by adding the display property with a value of inline.

Step 3. Add a bit of space between each nav item with 10px of padding.

Browser screenshot showing the navigation displayed horizontally

D. Style the Navigation

In this section, we’ll add your own colors to the navigation, including a background color and pseudo-classes for the links.

Make Modifications As Desired

If you would like to, you can create your own logo for Joystick Junkies, and then choose colors to match. A student (Sophie Hanson) made the example below.

Student example website by Sophie Hanson with a custom pink color theme

Add a Background Color to Nav

Step 1. Find the existing nav selector.

Step 2. Choose a background-color for the navigation and find the value for the color you want. You are required to choose your own color. Go to the W3 Color Picker to choose a color.

Step 3. Choose and add a color for the navigation border. Add a border-top and/or border-bottom to the nav. Remember that when you use the border property, you need three values: the width, the type (e.g. solid), and the color. The code for a border looks like this:

border-top: 5px solid #FFC0CB;

If you use the code shown above, be sure to change all three border values to match your design. You can also use our Border Generator tool to experiment with different styles. Another option is to use a CSS gradient for the nav bar, which you can create with our Gradient Generator tool. See the second example below. If you picked a dark color, the text may be hard to see — we’ll work on that next.

Example navigation bar with a solid background color and border
Example navigation bar with a gradient background color

Pseudo-classes on Nav Links

In style.css, create the pseudo-classes for the nav links. Use the color property. Choose colors that align with your design choices for the header and nav. Make sure that your color choices are clear in all states (link, visited, hover, and active). For a navigation, use the same color for link and visited.

CSS code for the nav a link, visited, hover, and active pseudo-classes

Check Your Links

Make sure that when you hover over your navigation links, the hover color appears. Make sure that the navigation is easy to read before and after you hover. If it isn’t, then change your link colors.

E. Change Your Heading Colors

Now that you have chosen colors for your header and nav, change your heading colors to a corresponding color. You are required to choose your own color. Go to the W3 Color Picker to choose a color.

CSS code setting the font-family and color for h1, h2, and h3 headings

F. Float an Image on the Home Page and Top Games Page

In this section, we’ll add an image to the Home page and the Top Games page, and float each one so the text wraps around it.

Add <img> on index.html

Work in index.html. Remember that the code for an image is:

<img src="" height="" width="" alt="" class="">

Insert the image code as the first element in the <main> section.

  • For the image src on the home page, choose one of the gamer images that are already in the images folder.
  • Set the height and width to 600px.
  • Write some appropriate alt text for the image you are using.
  • Set the class name to “float-right.”

Need help coding an image? Take a look at your code for the logo. (On a side note, I named the class “float-right” because there may be other images on a website I would like to code similarly and float to the right of the page.)

HTML code showing an img tag added as the first element inside the main section

Check the browser to make sure your image appears on the page. As you can see below, it isn’t positioned well on the page yet. We’ll work on that next.

Browser screenshot of the home page with an unstyled image that is not yet floated

Float Image to Right on the Home Page

Step 1. Working in style.css, add a selector for the .float-right class.

Step 2. Add the float property with a value of right.

Step 3. Add a max-width of 40% and a height of auto. This makes sure that the image never uses more than 40% of the available space. It’s a nice trick to make images work better for mobile.

Step 4. Add some CSS to decorate the image. In the example below I used a white border with a box-shadow to make the image look like a printed photograph. I also added a small border-radius to soften the corners. Choose from the following properties for your image design:

  • box-shadow
  • border (needs a width, style, and color)
  • border-radius

Step 5. Add some margin to the image so that it doesn’t touch the text.

Browser screenshot of the home page with the image floated to the right and styled with a border and shadow

Float Image to Left on Top Games

Now we are going to do the same thing on the Top Games page, except this time we are going to float the image to the left instead of the right. You may want to copy code from the index.html page to get started.

Step 1. Open the game-list.html page.

Step 2. Place a different image from the images folder after the first paragraph on the page. Use the class of “float-left.” This image should be placed underneath the <h1> and <h2> on the page.

Step 3. In the style.css file, add a new selector named .float-left. As a nice shortcut, you can start by copying your CSS from .float-right, and simply change the float to left.

Step 4. Adjust the margin. Placing the image on the left instead of the right requires different margins for good alignment. In the example below I used margin: 30px 30px 30px 0;

Browser screenshot of the Top Games page with an image floated to the left

G. Float a Text Box on the Gaming Systems Page

Rather than add an image to the Gaming Systems page, we are going to add a text box and float it to the right.

Step 1. In gaming-systems.html, move the <h2>The Bottom Line</h2> and the paragraph underneath it to the top of the <main> section, just underneath the <h1> and <h2> at the top of <main>.

Step 2. Add a div with a class of “text-box” around the text you moved. See the code below for Steps 1 and 2.

HTML code showing The Bottom Line text wrapped in a div with class text-box

Step 3. In style.css, add some styles to design your text box. Create a new selector, .text-box, and add CSS for the following:

  • Float to the right
  • Max-width of 40%
  • Margin of 10px on the top and bottom, and 20px on the sides
  • A background-color with light colored text on it. Choose colors to match your existing colors.
  • A border-radius
  • Space inside the text box with padding
  • Italic font (optional for your design)

Step 4. Now we need to style the h2 inside of the text box. In style.css, create a new selector: .text-box h2

  • Change the text color
  • Add a border-bottom (optional)
  • Make the font smaller (try 1.5em)
Browser screenshot of the Gaming Systems page with a floated text box styled in dark blue

H. Design Buttons

In this section, we’ll turn the two links on the Home page into styled buttons.

Design Buttons for Joystick Junkies

Another job when designing a website is to style the buttons. The two links we have on the home page would be better as buttons — buttons are more likely to be clicked than a link. It is best to use the same button design throughout a website.

Screenshot of the home page links with an annotation arrow suggesting they would be better as buttons

Design Home Page Buttons

Step 1. In index.html, add a class to the <a> tags so that you can style them as buttons in the CSS. You can name the class anything, but for the example below I chose the class name of “button-design.”

HTML code showing a class of button-design added to an anchor tag

Step 2. In style.css, add the button-design class to the CSS and style the buttons. See the example below. Use different values for the border-radius and background-colors to create your own design. The colors you choose should align with the colors in your header and nav — use any colors except for the colors shown in the example code below.

CSS code for the button-design class including link and hover states

Check Home Page Buttons

Check your buttons in the browser for the following:

  • The text isn’t underlined in either the link or hover state.
  • The text color is easy to read on the background color.
  • There is a good contrast between the link and hover state.

In the example below, the button color is blue. When you hover over the button, the background-color changes to red.

Browser screenshot of two styled buttons with arrows labeling the link color and hover color

Checklist for Grading

Turn in your entire “websites” folder for grading. Here is a final checklist for this module:

From the Module 5 Slideshow

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

Joystick Junkies Lab


Now you know how to lay out and position elements! Move on to Lab 6 to make your site responsive.

This is how Joystick Junkies looks after Lab 5. There is now a floated image on the home page as well as decorated buttons.

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