UNDER CONSTRUCTION

I am currently re-writing this page: use the refresh button in your browser to see if it's finished, yet.

Lesson 12: CSS Grid Layout

In this lesson, we'll continue with responsive design by learning how to lay out element using a CSS Grid.

CSS Grid

Notes

Resources

Homework

Practice/Study Questions

Practice Exercises

Note
In the practice exercises, elements are referred to in all-caps, e.g. FOOTER refers to the <footer></footer> element (or it could also refer to an opening <footer> tag or closing </footer> tag, you will know by the context in which it's used).

For each exercise, validate the HTML using the HTML Validator. Fix all problems until you get no errors.

  1. If you haven't already done so, create a sub-directory in your local workspace and in your server workspace (off /syst10049) called "week12". Feel free to add an extra level for all of your practice exercises (e.g. /exercises).
    • For each practice exercise in each lesson, you'll usually be asked to create an exercise directory for that project, such as "/exercise1".
    • It is assumed that you will create the exercise project directory in both your local workspace and in your server workspace using the appropriate and standard directory structure discussed in class.
  2. Use this CodePen. You can do the exercise in the CodePen or copy and paste the starter code into your own project.

    Add the CSS to create a CSS grid that looks exactly like the image below:

    a grid of 5 boxes, labeled A to E
    Row 1 contains equally-sized box A and box B. Row 2 contains box C and box D: box D is 3 times the width of box C. The third row contains box E, which takes up the width of the grid.

    The rows of the grid should size automatically to fit the height of their contents. There is a small amount of space between rows and columns in the grid (I used 2% of the font size, but feel free to use viewport units instead).

    Note that each inner DIV element has 2 classes: the .box class and a class whose name matches the letter inside the box. Any styles added to the .box class affect all the box DIVs. To style an individual DIV, just add a class corresponding to the box letter e.g. .f { ... }

  3. Use this CodePen. You can do the exercise in the CodePen or copy and paste the starter code into your own project.

    Add the CSS to create a CSS grid that looks exactly like the image below:

    a standard page layout with 
                 header, footer, 2 content areas, and navigation sidebar
    How the page should look

    The header spans across the page but stops when it reaches the left edge of the navigation element. The navigation element spans down the whole page until it reaches the top border of the footer element. The footer element spans across the entire width of the page. Between the header and footer, to the left of the navigation element are two content areas, side by side, with equal widths and heights.

    Make sure you write the most efficient CSS possible.

  4. Nested Grid:Use this CodePen. You can do the exercise in the CodePen or copy and paste the starter code into your own project.

    Add the CSS to create a CSS grid that looks exactly like the image below:

    a grid of 6 boxes, labeled A to F
    What your grid should look like

    Row 1 contains equally-sized box A and box B. Row 2 begins with larger box C, followed by a nested grid. The nested grid takes up two rows. The first row contains box D, and the second row contains box E and F, equally sized, side by side.

    The rows of the grid should size automatically to fit the height of their contents. There is a bit of space between rows and columns in the grid (I used 4% of the font size).

  5. Combining Flex and Grid:Use this CodePen. You can do the exercise in the CodePen or copy and paste the starter code into your own project.

    Add the CSS to create a layout that looks exactly like the image below:

    a blog page with a sidebar
    What your page should look like

    The header and footer span across the page. The header shows the menu items on the left and the Log In button on the right. The sidebar contains a list of recent posts, and it sits between the header and footer on the left side. The main article on the page also sits between the header and footer, to the right of the sidebar. The sidebar is about one quarter width of the article area.

    This uses a combination of flex box and grid. There are likely multiple solutions.