The following files are required for this lesson:

Introduction

This lesson will be taught in two parts:

Demo Instructions

You can follow along with your instructor to complete this build and/or you can use this document as a guide in completing the demo build.

Steps - Part 1: Media Queries

  1. Download the demo-media-queries.zip file and extract its contents to a folder named demo-media-queries.
  2. A wide resolution of the index.html should look like:
    media-01.jpg
  3. When you narrow your browser, you want to see something like:
    media-01.jpg
    Note: the color changes.
  4. Open the styles.css file and scroll down to find the comment about Media Queries and add the following:
    media-css-styles-01.jpg
    Question: What did this media query do?
  5. Add the following query below the one you just added:
    media-css-styles-02.jpg
    Question: What did this media query do?
  6. Now add the last media query:
    media-css-styles-03.jpg
    Question: What did this media query do?
  7. For each of the media queries, use the developer tools to set the width that will trigger the change.

Steps - Part 2: RWD Menu

  1. Download the demo-rwd-menu.zip file and extract its contents to a folder named demo-rwd-menu.
  2. A wide resolution of the index.html should look like:
    menu-01.jpg
  3. When you narrow your browser, you want to see something like:
    menu-02.jpg
  4. Examine the index.html file to see the menu:
    menu-index-01.jpg
    Note: There is nothing special here; we can see the <nav> element is inside a flex container.
  5. Open the styles.css file and scroll down to find the start of the first media query and code as shown below:
    menu-css-styles-01.jpg
    Here you see the style rules that get applied when the width is >= 750px.
  6. Open the developer tools in your browser and make the following change:
    menu-03.jpg
  7. Now, change the width to 749 px and you should get:
    menu-04.jpg
    Notice that the layout changed as the width now is less than the width set in the media query.
  8. Now add the code below to the second media query in your styles.css:
    menu-css-styles-02.jpg
  9. In developer tools make the following change:
    menu-05.jpg
  10. Now change the size and see what happens, i.e.:
    menu-06.jpg
    And:
    menu-07.jpg
    Notice that no matter how wide we make the browser window, the menu is locked at a width of 1400 px.

Summary

More media query examples will be demonstrated in the next demo.

Module Home

DMIT1530 Home