The following files are required for this lesson:

Introduction

This lesson will be taught in tw0 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: CSS Selectors

  1. Download the demo-selectors.zip file and extract its contents to a folder named demo-selectors.
  2. The completed output should look like:
    selectors-01.jpg
  3. You need to add some code to the index.html file:
    1. Add a flex container:
      selectors-index-01
    2. Add <section> blocks inside the flex container:
      selectors-index-02
    3. Add a <footer>:
      selectors-index-03
      The output in your browser should look like:
      selectors-02
  4. Now you need to add style rules to the styles.css file:
    1. Add a .flex-container class:
      selectors-css-styles-01
      Question: What does this style rule do?
    2. Add styling for the <section> elements:
      selectors-css-styles-02
      selectors-03
    3. As the individual <section> blocks do not appear, you need to use a pseudo-selector to target the styling of each <section>:
      1. first-child:
        selectors-css-styles-03
      2. last-child:
        selectors-css-styles-04
      3. >nth-child(2):
        selectors-css-styles-05
      4. nth-child(3):
        selectors-css-styles-06
        Refresh your browser to see:
        selectors-04
      5. nth-last-child(3):
        selectors-css-styles-07
      6. nth-last-child(2):
        selectors-css-styles-08
        Refresh your browser to see the following making note of the colours you used for each <section>’s background:
        selectors-05
    4. The <footer> needs to have a different background colour:
      selectors-css-styles-09
      selectors-06
    5. The nth of type selector can be used to target the position of a child element. Each <section> has two <p> elements, thus you can target each of these using:
      selectors-css-styles-10
      selectors-07
      Note: the font of the 1st paragraph is now bolded and has a slight text shadow:
    6. Targeting the other paragraphs is done using:
      selectors-css-styles-11
      selectors-01

Steps - Part 2: Flex Order

  1. Download the demo-flex-order.zip file and extract its contents to a folder named demo-flex-order.
  2. Open the index.html in your browser to see something like:
    order-01.jpg
  3. The completed output should look like:
    order-02.jpg
    Question: What do you think we need to do to achieve the completed output?
  4. Examine the styles.css file and make note of the two changes that need to be made.
    1. Add a media query to change the layout and order of the items:
      1. Add the media query:
        order-css-styles-01
      2. Change to a 3-column layout and space the <section> elements equally:
        order-css-styles-02
      3. Change the order of the items in the layout:
        order-css-styles-03
        order-03
    2. Position items in the order of 6, 4, 2, 5, 3, 1. In your media query set the order of the other items:
      1. 4th child:
        order-css-styles-04
      2. 2nd child:
        order-css-styles-05
      3. 5th child:
        order-css-styles-06
      4. 3rd child:
        order-css-styles-07
      5. 1st child:
        order-css-styles-08
        order-02
  5. Now you need to test the media query to see what is happening to the output:
    1. Width < 950px:
      order-04
    2. Width >= 950px:
      order-05

Activity

For extra practice, open the css-selectors-activity.pdf file and complete the activity.

Module Home

DMIT1530 Home