Joystick Junkies: Website Images (Lab 4)

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

The objective of this lab assignment is to learn how to work with website images, both embedded and background images, while continuing to build your CSS skills.

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

Jump to:

In Lab 4 you will:

  • Add the logo with an embedded image <img>
  • Add a hero to the home page with a background-image
  • Decorate the headings and clean up the navigation
  • Add a third page to the website

Adding images makes a huge difference! By the end of Lab 4 you will have created a professional website! See the screenshot below to compare the finished Lab 3 to the finished Lab 4.

Shows the difference between the home page from Lab 3 to Lab 4

During Lab 4 we will add the third page to Joystick Junkies. At the end of this lab, your 3 pages will look like the screenshot below.

The three finished pages in Lab 4 of Joystick Junkies.

“Hey, where is the code?” Going forward, I will not always be providing screenshots of the code. Instead, the instructions refer to the “Selector,” “Property,” and “Value.”

  • Selector: The “selector” selects the HTML.
  • Property: The property defines which aspect of the selector will be changed; for example, the color or the font.
  • Value: The value defines what the color, size, or shape of the property is. For example, if the property is “color,” then the value could be “blue.”

In this section, we’ll add the Joystick Junkies logo image, copy it to the other pages, and make sure it resizes well on mobile.

Remember in Lab 2 where you downloaded the starter files? Inside that folder is an images folder that contains all of the images you need for this module. If you didn’t start the lab with the starter files, you will need to return to Lab 2, download the starter files, and move the images folder into your file structure. When you reference the images as you are coding, be sure to reference them inside of the images folder.

Folder structure showing the images folder with gamer photos, hero image, logo, and favicon

Add the Logo Image

Work in the index.html file.

Step 1. Delete the <h1> element from the <header>. We are going to replace that text with the logo image.

Step 2. Add an image tag into the <header>. Remember that the code for an image is <img src="" width="" height="" alt="">

  • For src use: images/logo.png
  • For width use: 400
  • For height use: 72
  • For alt use: Joystick Junkies Logo

Step 3. Now we are going to add one more attribute. Insert the attribute class="logo". We are adding the class so we can select the logo separately from the image for styling.

Code for the logo img tag inside the header

Check index.html in a browser and make sure it looks like the screenshot below.

The header in Joystick Junkies showing the logo without a gradient and touching the sides.

Possible image code errors. If your image isn’t appearing, make sure you are referencing it correctly. The image src needs to be exactly “images/logo.png”. The source is referencing its relative location.

If your image is stretched, check your height and width entries.

Copy the Logo Code to the Game Systems Page

Now that we have the logo installed into index.html, we need to copy it to the game-systems.html page.

Step 1. Copy the <header>…</header> from the index.html file into your clipboard.

Step 2. Open the game-systems.html file.

Step 3. Delete the current <header>…</header> in the game-systems.html file and paste in the new <header> from index.html.

Step 4. Save and check the game-systems.html page.

Making Images Mobile Ready

We have a bit of a problem with our logo on mobile. The logo width is 400px, but most mobile devices are 320px in width. As you can see in the screenshot below, the logo goes off the screen. Whenever you have images over 320px in width, it will cause a problem on mobile devices. There is an easy correction we can make.

Logo overflowing off the edge of the screen on a mobile-width browser view

Style the Logo Class

Remember when we added the attribute class="logo" to the <img> tag? The class allows us to select the logo in the CSS for styling. Work in the style.css file.

Step 1. Add a new selector: .logo

Step 2. Add max-width of 100% to the logo class. What this does is make sure that the logo is never over 100% on mobile devices.

Step 3. Add height: auto. This makes sure that if the logo size needs to be reduced to fit the screen, that the height is adjusted proportionately.

Step 4. Add 15px space to the top of the logo with the padding property.

CSS code for the logo class with max-width, height, and padding-top
The before and after showing how the logo goes off the page on mobile before you add max-width to it.

B. Style the Header and Navigation

In this section, we’ll add a gradient background to the header and clean up the default styling on the nav links.

Styling the <header>

The <header> and <nav> are the most important parts of any web page, because they appear at the top of ALL pages on a website.

Step 1. Find the existing header selector in style.css.

Step 2. Add 20px of space around the header with the padding property.

Step 3. Go to: webdevstudents.com/gradient-generator and create a gradient to use for the header. Copy the code from the generator into the header selector.

Step 4. Check your gradient in the browser to make sure it looks good with the logo.

Joystick Junkies with the header complete, and the navigation styling in process.

More gradient ideas: You can choose whatever colors you would like for the gradient on the header. The logo will stand out more if you choose colors that contrast to the logo.

A variety of options for the gradient for the header in Joystick Junkies

Navigation Clean Up

Now we need to eliminate the default underlining on the nav links. To do this we need to create a descendent selector, nav a. In English, nav a is saying, “if a link is in the nav, then apply this CSS.”

Step 1. Add a new selector: nav a

Step 2. Add the property value, text-decoration: none;

CSS code for the nav a selector removing text-decoration

Check your browser against the screenshot above — the nav links should no longer be underlined.

The finished header and navigation on Joystick Junkies

C. Add the Hero Image

In order to design a hero image, we need to make changes to both the HTML and CSS. For the hero, we will use a background-image rather than an embedded image.

HTML Changes for the Hero

First, the HTML code: Add the hero image div to index.html.

Step 1. Add the div element after the closing </nav> and before the opening <main> element — this <div> will hold the hero image.

Step 2. Give the new div a class of home-hero: <div class="home-hero"></div>

Step 3. Put the tagline “Fueling Your Game Addiction” in <h1> tags inside of the div.

HTML code for the hero div with class home-hero placed between the nav and main elements

Save and check the browser. It should look like the screenshot below. (We’ll make it look like a hero next.)

Hero tagline text showing in the browser before any CSS styling is applied

CSS Changes for the Hero

Work in style.css.

Step 1. Add a selector called .home-hero

Step 2. In the .home-hero selector, add a background image with the background-image property. The image is in the images folder and is named “hero-image.jpg”. Remember that the code for a background image is: background-image: url();

Step 3. Set the height property to 300 pixels.

Step 4. Set the background-size property to cover.

Step 5. Set the background-position to top and center.

CSS code for the home-hero class with background-image, height, background-size, and background-position

At this stage you can see the background image, although we have some problems we need to repair: we need to make the text easier to see, and we need to remove that white space at the top of the hero.

Hero section with the background image applied before the text is styled

CSS Changes for the Hero Text

We need to make the text easier to see, arrange it on the hero, and remove the white space at the top. Work in style.css.

Step 1. Create a descendent selector that selects the h1 tags in a hero, i.e. .home-hero h1

Step 2. Change the text-color to white. White will show up better on the background-image.

Step 3. Add a text shadow so the text is easier to see. (Use text-shadow: 2px 2px 2px black;)

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

Step 5. Add 115px of padding to the top so that the text is centered vertically.

Step 6. Change the font-size to 3em.

Step 7. Change the font-weight to normal.

Step 8. Remove the margin with margin: 0. That removes the white space at the top of the page.

CSS code for the home-hero h1 selector styling the hero text color, shadow, alignment, and spacing

Check Your Hero in the Browser

Your <header>, <nav>, and hero image should look like the screenshot below. (Your gradient on the header will be different.) If it doesn’t, go back and check the steps. Make sure you saved both the index.html and the style.css file.

Finished hero section with white centered text, text shadow, and background image

D. Style the Headings

An easy way to make site-wide styles to a website is by styling the headings.

Step 1. Add a selector for the h1 headings, then add the following property/values:

  • Add a font-size of 3.5em. (The default size is 3em, so this makes the text a bit larger.)
  • Add a margin of 0.

Step 2. We’ll do something fancier for the h2 headings. Start by adding a selector for the h2 headings, and then add the following:

  • Add a border-bottom of 2px solid #1C2995. Remember that you need all three values for the border to appear.
  • Add the display property with a value of flex (display: flex;)
  • Add the padding property with a value of 5px
  • Add the font-size property with a value of 2em
  • Add the font-weight property with a value of 100. The 100 value makes the lightest font weight for the font-family

Step 3. Add a selector for the h3 headings, and change the font-size to 1.7em.

Open the gaming-systems.html page. Check to see that the headings look like the examples below. Adding a border-bottom to the <h2> is a nice design trick. When designing your headings, it is important to have a good design contrast between the <h1>, <h2> and <h3> headings, so the organization is clear to the website visitor.

The Video Gaming System page with arrows showing the H1, h2, and h3s

E. Add the Top Games Page

We are going to add the third page to the website: the Top Games page. You’ll work in the file game-list.html, so keep in mind that the file name and the page name are different — “Top Games” is what the page is called, while game-list.html is the file you’ll open and edit to build it. You will be surprised how easy it is to create a new page now that you have the layout ready to go. We will cut and paste the work we have already done in order to create the page more quickly.

The finished version of The Most Popular Video Games page

Copying to the Top Games Page

The Top Games page (game-list.html) will be very easy to create because we are going to cut and paste the <head> <header> <nav> and <footer>. Only the content of the <main> section is different on this page.

Step 1. Open the game-list.html page. It should already be in your joystick-junkies folder.

Step 2. Open the index.html file. Copy everything through the opening <main> element and paste it into the top of game-list.html.

Step 3. From the index.html file, copy everything from the closing </main> to the end of the page and paste it at the bottom of game-list.html.

Check game-list.html in the browser. It should look like the screenshot below. As you would expect, the logo, navigation, and footer are just like the other pages, but the <main> section needs some HTML.

The Most Popular Video Games page after the header, nav, and footer are added, but before there is markup to the main section

<main> Section HTML

As you can see in the browser, all we need to do is add some formatting to the <main> section and delete the hero image.

Step 1. Delete the hero image <div> from the game-list.html page.

Step 2. Add <h1> tags to “The Most Popular Video Games.”

Step 3. Add <h2> tags to “A Snapshot of Modern Gaming” and “Conclusion.”

Step 4. Put <h3> tags around the 10 video game names, starting with “1. Fortnite” and ending with “10. The Legend of Zelda.”

Step 5. Add <p> tags on the remaining paragraphs.

Make sure you have the <main> tags in, because the CSS on the main tags centers the text on the page.

The Most Popular Video Games page with arrows pointing to the h1, h2 and h3s

F. Add Favicon Code

For favicons to appear on a published website, all you need to do is create a file named favicon.ico and place it at the root. However, since we aren’t publishing this website (yet) the favicon may not appear. We can force it to appear by including this code in the website <head>:

<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">

Add the favicon code to all three HTML pages. The code looks like this after it is installed.

HTML code for the head section including the favicon link tag

The favicon looks like this in the browser:

Browser tab showing the Joystick Junkies favicon, with an arrow pointing to it

Checklist for Grading

Here is a checklist of what I will be looking for when grading the lab. You now have three formatted pages on the website — compare your result to the three pages below.

The three finished pages in Lab 4 of Joystick Junkies.

Note: There were no changes to the website template this module.


Now you know how to work with website images! Move on to Lab 5 to learn about layout and positioning.

This is how Joystick Junkies looks after Lab 4. There is a gradient behind a logo image and a hero background image.

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