Responsive CSS Basics

This deck does not cover:

That's "Introduction to CSS", a Collegiate Web Developers Group talk.

This file also does not cover

See other files within this presentation and The 2016 CWDG Intermediate CSS talk.

How to follow along

benlk.github.io/talk-wordcamp-columbus-2016

Go here in your browser now!

Once you have that open in your browser, open your browser's dev tools:

Units

The root CSS unit is the pixel, px. It's equal to one pixel on your device, unless you've got a high-Dots-Per-Inch device like an iPhone or a 4K laptop or a Macbook or really any high-end device made in the last two years.

From the CSS pixel are built the units of absolute length, which usually don't change while the page is loaded:

Remember, those aren't physical units. They're based on the ideal of 1in = 96px. You're probably not going to use them unless you're doing CSS for print stylesheets.

There are units that scale with the font size:

Then there are the units that scale with the size of the browser's viewport:

Those don't have the best IE support.

If you're not sure what to use, it's safe to stick to px.

If you're not sure if the unit is supported on a device, check here.


And then there's this funky character:
%

% is not a unit

.narrow { width: 30%; } 

When you use percent for the value of a property, it references the parent element's property value.

If the parent element's property is a percent, then the parent needs to have a width that isn't a percent.

If it's percents all the way up to the root element, then you're probably good.

If it's percents all the way up to an element with a fixed value, you're good.

If it's percents up to an element that doesn't have a fixed value, it's an invalid property and your browser will ignore it. This breaks the rule.

Grids

What do you get when you combine margins, padding, widths and floats?

Grid systems!

Media Queries

Some resources:

Two ways to do media queries:

In the HTML


<link rel="stylesheet" media="screen and (min-device-width: 800px)" href="800.css" />

In the CSS

Media queries aren't limited to browser width

Using Media Queries for Resposive Web Design

In general:

Where can you go from here?

Learning resources:

What's the best way to learn?

Resize your browser.

Play around with things on your own. Build a portfolio site. Use your browser's inspector tools to see how other people build their sites. See if you can reproduce that style.