Joystick Junkies: Responsive (Lab 6)

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

The objective of this lab assignment is to learn the basics of responsive design, including the viewport meta tag and media queries, while adapting a website for different screen sizes.

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

Jump to:

At the end of Lab 6 you will have three different versions of Joystick Junkies: desktop, tablet, and smartphone.

Three versions of the Joystick Junkies home page shown at desktop, tablet, and smartphone widths

A. Add the Viewport Meta Tag

Add the viewport tag to all three HTML files between <head> and </head>, before your title. Place it underneath the other <meta> tag. Here is the code so you can copy and paste it.

<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />

HTML code showing the viewport meta tag added inside the head section

B. Add Media Queries

Let’s start by adding our two media queries. The top one is for tablets, and the bottom one is for smartphones.

Carefully copy the media query code below and paste it at the bottom of the style.css file. The media queries must go at the bottom of the page because they will override the other CSS for the desktop.

CSS code showing two empty media query blocks, one for tablets and one for smartphones

C. Adjust Fonts and Spacing for Tablets

Adjust the Heading Font Sizes

We need to adjust the heading font-size for mobile. Add CSS in the media queries to change the font-sizes as follows:

HeadingDesktopTabletSmartphone
<h1>3.5em2.5em2em
<h2>2em1.5em1.5em
<h3>1.7em1.3em1.3em

Check the font sizes in a browser. You should see smaller sizes in the tablet and smartphone screen widths.

Main Section on Tablet Size

Take a look at the tablet size for mobile. (See the screenshot below.) It looks pretty good, except for one thing — the text is too close to the edge on the main section and the footer. Make both of these changes in the media query for tablets:

Step 1. Add a selector for main and footer.

Step 2. Add a width of 90%.

Check and double check your curly braces. An extra or missing curly brace will break your CSS.

CSS code inside the tablet media query setting smaller heading font sizes and 90 percent width on main and footer
Browser screenshot of the Top Games page at tablet width with text touching the edges of the main section

Before

Browser screenshot of the Top Games page at tablet width with comfortable spacing after adding width to main and footer

After

On a side note, in Lab 5, we added a 40% max-width to the floating images. Adding a max-width to floated images is a good trick for mobile. Without a max-width, the images will go off the viewport on smartphones.

D. Make Adjustments for Smartphones

In the next set of steps, we are going to make the following changes for only the smartphone size. Since these changes are only for the smartphone size, we will put the CSS into the media query for smartphones. Here is a list of changes we are going to make:

  1. Change the text arrangement in the hero image. As you can see below, it is too large and the text is wrapping.
  2. Remove the photos with display: none. These particular images don’t add enough value for smartphone screen sizes.
  3. Change the text box position on the Gaming Systems page.
  4. Change the navigation style to one that is mobile-friendly.
Before and after comparison of the home page at smartphone width showing the planned hero and navigation changes

Adjust Text on the Hero

In the media query for smartphone sizes:

Step 1. Create a selector for the .home-hero class. Set the height to 125px. This will override the height we added previously for tablets.

Step 2. Create a selector for h1 elements inside of the hero image (.home-hero h1).

  • Add a height of 125px.
  • Add a font-size of 1.5em.
  • Add 45px of padding to the top.
CSS code inside the smartphone media query resizing the hero image and its heading text

Check in a browser and compare it to the screenshot below.

Browser screenshot of the hero image and heading at smartphone width after resizing

Remove Unnecessary Images

The photos we added to the Home and Top Games pages don’t add enough value for small screens. Let’s remove them. Add this code in the media query for smartphone sizes.

Step 1. Add a new selector for .float-right, .float-left

Step 2. Add the display property with a value of none.

CSS code inside the smartphone media query setting display none on the float-right and float-left classes

Check in a browser to make sure the images are still in place on the tablet and desktop sizes, but disappear on the smartphone size.

Browser screenshot of the home and Top Games pages at smartphone width with the floated photos hidden

Text Box Position on the Gaming Systems Page

On the Gaming Systems page, the text box needs adjustment. We’ll change the text box to full width. To do that, we need to override the values we added to the .text-box class. Work in the media query for smartphones.

Step 1. Add a selector for .text-box inside of the smartphone media query.

Step 2. Override the float on the text box with float: none

Step 3. Override the max-width of 40% with max-width: 100%

Step 4. Override the inline display with display: block

Before and after comparison of the Gaming Systems text box at smartphone width, changed from floated to full width

Mobile Navigation

Last, but not least, we are going to change the navigation so it is smartphone friendly. Work in the media query for smartphones.

Step 1. Add a selector for nav ul

  • Add padding of 0
  • Add margin of 0

Step 2. Add a selector for nav li inside of the smartphone media query.

  • Change the display property to block
  • Add .5em padding to the top and bottom, and 1em of padding to the left and right
  • Add a border-bottom that is solid, with a width of 1px, and a color of gray. (Remember you need three values for a border.)
Before and after comparison of the navigation at smartphone width, changed from horizontal to a stacked mobile-friendly list

E. Check All Pages at All Widths

Check all three pages (Home, Gaming Systems, and Top Games) at all three widths (desktop, tablet, and smartphone) before moving on.

The finished Joystick Junkies home page shown together at desktop, tablet, and smartphone widths

F. Check Your Template

Done with Joystick Junkies! In addition to checking your Joystick Junkies website, I will be making one last check of your website template this week. Here are some common file name problems you should fix.

Check Template Folders and Files

  1. Make sure the HTML file is named “index.html” instead of “template.html.” The reason for that is so that when you copy your template for upcoming labs, you already have an index.html file.
  2. You should only have two files in your website template: index.html and style.css. If you have other files, move them somewhere else. Everything in the template folder will be copied to your new websites.
  3. Check to make sure that your folder and file names are all lowercase.
File browser showing a website template folder containing only index.html and style.css

Check Template in Browser

Your final template will look like this. Your colors and fonts will be different.

Browser screenshot of a generic finished website template with a header, magenta navigation bar, page title, and footer

Problems with Your Template

Since you will start the Module 7 lab by copying your template, it is important to make sure your template is in good shape. Otherwise you will not have the right starting point for ongoing lab assignments.

Need a fresh start? If you have a lot of missing code or major gaps in your template, I have a blog post with all of the template work on one page. Go to this link:

https://webdevstudents.com/making-a-website-template

Note: If you have been keeping up with the template work and only have a few problems, I’ll help you find those. Either email it to me as a zip file or put a note in the Assignment Folder.

Checklist for Grading

From the Module 6 Slideshow

When you worked through Module 6, 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 make your site responsive! Move on to Lab 7 to learn about tables and forms.

This is a screenshot of Joystick Junkies after Lab 6. There is now an ipad and mobile view.

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