Session 06 - CSS, Part 4, including Grid

Harvard Extension School  
Spring 2022

Course Web Site: https://cscie12.dce.harvard.edu/

Topics

  1. Announcements
  2. CSS Flexbox and Grid
  3. CSS Grid
  4. Responsive Page Layouts
  5. Responsive Page Layouts

Session 06 - CSS, Part 4, including Grid, slide1
Announcements, slide2
CSS Flexbox and Grid, slide3
CSS Grid, slide4
Grid Examples..., slide5
Responsive Page Layouts, slide6
Classic Responsive Design Example, slide7
Breakpoints and CSS Media Queries, slide8
What about breakpoints?, slide9
Responsive Page Layouts, slide10
CSS Custom Properties, slide11
Custom Properties, slide12

Presentation contains 12 slides

Announcements

The Month of March

CSS Flexbox and Grid

Grid

Flexbox

CSS Grid

Grid Terms - Lines, Cells, Areas

Lines
grid line

Cells
grid cell

Areas
grid area


Column and Row Line Numbers
grid line numbers

Grid Examples...

grid layout

Responsive Page Layouts

Site is "responsive" to different devices.

devices

Classic Responsive Design Example

responsive wide screen

responsive medium screen

responsive small screen

Breakpoints and CSS Media Queries

@media CSS Media Query


/* rules for small screens and all screens */
body {
  background-color: #005bbb;
  color: #ffd500;
  font-family: helvetica, sans-serif
}
h1 { text-align: center; font-size: 3rem;}
/* only for widths of 768px and wider
   yes, we could have used 48em as a unit
*/
@media (min-width: 768px) {
  /* specific rules go here */
  body {
    background-color: #ffd500;
    color: #005bbb;
  }
}

Code Pen Example of Media Query

See the Pen First @media query by David Heitmeyer (@dpheitmeyer) on CodePen.

What about breakpoints?

With that said....

Common breakpoints that you see are: 576px, 768px, 992px, and 1200px

Responsive Page Layouts

CSS media query:


/* Small screens; no query needed */
/*



*/

/* Larger phone/tablet screens */
@media (min-width: 576px) { /* specific rules go here */ }

/* Medium screens */
@media (min-width: 768px) { /* specific rules go here */ }

/* Larger screens */
@media (min-width: 992px) { /* specific rules go here */ }

/* Extra large screens */
@media (min-width: 1200px) { /* specific rules go here */ }

CSS Custom Properties

The problem: keeping "DRY" (don't repeat yourself) in CSS can be hard impossible.

CSS Custom Properties provides a way forward!

section {
    --spacing: 1.2rem;
    padding: var(--spacing);
    margin-bottom: var(--spacing);
}

Steps:

Custom Properties

Properties cascade too -- so properties defined in "html" will be available throughout, but they can be overriden by redefining at another level (e.g. "footer")

Sometimes you see ":root" selector used for global custom properties, but that is essentially the same as "html"

See the Pen First @media query by David Heitmeyer (@dpheitmeyer) on CodePen.