Skip to content

Responsive Design

The web long predated the myriad devices that we now use to access information on the internet. To accommodate the proliferation of different devices and screens, the CSS spec introduced a feature known as a media query to address screens of different resolutions. As Bryce Watson and Michael Woo remind us:

Perhaps creating a responsive app is not high on your team’s priority list right now. But one day it will be — and the conversion time frame might be very tight when that day comes.

Ideally, all you need to do is add media query CSS and everything just works. But the only way that can happen is if the code readily adapts to responsive changes.

Mobile First - A Retrospective
  1. Apply HTML, CSS, Markdown, and basic Javascript to develop well-structured, responsive World Wide Web Consortium (W3C) standards-compliant web sites.
  2. Evaluate and implement web accessibility measures consistent with the Web Content Accessibility Guidelines (WCAG) version 2 specification.
  3. Design front-end user experiences using accepted web design patterns, methods, and information structures.
  4. Identify and use strategies of successful visual rhetoric for the web.
  5. Compare and select web technologies such as static site generators or frameworks as appropriate candidates for building web sites. Course Resources
The Coding Workbook, “Getting Started with CSS”

Responsive Design

Section titled “”

a web design approach to make web pages render well on all screen sizes and resolutions while ensuring good usability.

MDN, “Responsive Web Design”

By itself, HTML is responsive as long as the page can determine the viewport width. However, choices that a browser may make can be surprising or unhelpful. CSS helps ensure uniformity between device types, but only if HTML can establish the viewport

<head>
...
<!-- This line ensures the browser can determine the viewport -->
<meta name="viewport" content="width=device-width" />
</head>

Keep in mind that responsive design is not a separate technology: it is a method. Responsive design uses CSS with appropriate semantic HTML groups to effect designs that work across devices such as phones and even watches.

CSS achieves responsiveness through media query directives. For example, the WebCo site uses:

@media screen and (max-width: 767px) {
nav {
grid-column: span 2;
}
.full__three_column, .full__four_column {
display: flex;
flex: 1;
flex-direction: column;
row-gap: 3rem;
column-gap: 0;
}
.article__border_right:not(:last-of-type) {
border-right: none;
}
#search {
display: none;
}
}

This query sets the following restrictions:

  • media type must be a screen
  • the viewport must attain a max-width of 767px

The and between the media type (screen) and the pixel-denoted width means that both of these must be true.

At one time, more media types existed, but these have been deprecated and the available media types list is now:

Media typeMeaning
screenAll devices that aren’t requesting print
printDevices requesting print layouts
allAll media regargless of requests

Note that the and operator exists. Developers may also use:

  • not
  • only
  • or

While we’re going to focus on usability via design elements, know that media queries can cover much more.

Grids are great for 2-dimensional layouts that need to control both horizontal and vertical layouts. However, what happens when we want to do a layout in only one direction? Let’s return to our WebCo layout.

There are a number of different positioning strategies, particularly the effect of:

.full__three_column, .full__four_column {
display: flex;
flex: 1;
flex-direction: column;
row-gap: 3rem;
column-gap: 0;
}
WebCo layout
WebCo layout

In the above, we overrule the display: grid set at the desktop level and substitute in display: flex with an additional 2 parameters: flex-direction: column and flex: 1, letting the browser know to flex vertically taking up 1 column.

This is what it means to cascade in a style sheet: more specific rules add to or replace less specific ones (namely in order of selector specificity or even order in the stylesheet).

To add a stick wicket to the proceedings, the way that we position items relative to each other plays in to creating usable design. CSS accommodates a number of postiions:

Position valueMeaning
absoluteElement supercedes the normal document flow, attaching to the closest positioned ancestor
relativeElement positioned as listed in hierarchy, but is then offset against itself
staticElement is positioned exactly in the document hierarchy as written
fixedElement is removed from the document flow, then positioned against the viewport
stickyElement positions itself in the document flow, but “sticks” to its nearest ancestor with scrollable properties (usually the viewport