building layouts with css

66
Building layouts with CSS @bpapillard @bpapillard

Upload: boris-paillard

Post on 21-Jan-2018

1.164 views

Category:

Education


1 download

TRANSCRIPT

Page 1: Building Layouts with CSS

Building layouts with CSS

@bpapillard@bpapillard

Page 2: Building Layouts with CSS

1. What’s a layout 🤔?

2. Real-life examples 📖

3. Row layout, the easy one

4. Column layout with flexbox

5. Grid layout with CSS grids

Page 3: Building Layouts with CSS

0. Let’s setup ⚙

github.com/lewagon/layouts-101Download starting boilerplate

Page 4: Building Layouts with CSS

1.What’s a layout 🤔?

Page 5: Building Layouts with CSS

Components = Elementary blocks of UI

Page 6: Building Layouts with CSS

Layout = Global structure of your page 📐

Page 7: Building Layouts with CSS

The layout is the page’s skeleton

Page 8: Building Layouts with CSS

tabs

cards

navbar

The layout is the page’s skeletonin which you inject components

Page 9: Building Layouts with CSS

2. Real-life examples 📖

Page 10: Building Layouts with CSS

What examples of layouts do you know 🤔?

Page 11: Building Layouts with CSS

Row layouts

Page 12: Building Layouts with CSS

Example - Homepage

Page 13: Building Layouts with CSS

Example - Homepage

Page 14: Building Layouts with CSS

Example - Blogpost

Page 15: Building Layouts with CSS

Example - Blogpost

Page 16: Building Layouts with CSS

Column layouts

Page 17: Building Layouts with CSS

Example - Map with results

Page 18: Building Layouts with CSS

Example - Map with results

Page 19: Building Layouts with CSS

Example - Inbox

Page 20: Building Layouts with CSS

Example - Inbox

Page 21: Building Layouts with CSS

Example - Social feed

Page 22: Building Layouts with CSS

Example - Social feed

Page 23: Building Layouts with CSS

Example - SaaS app

Page 24: Building Layouts with CSS

Example - SaaS app

Page 25: Building Layouts with CSS

Grid layoutsboth merged rows & columns

Page 26: Building Layouts with CSS

Example - Newspapers

Page 27: Building Layouts with CSS

Example - Newspapers

Page 28: Building Layouts with CSS

Example - Analytics Dashboard

Page 29: Building Layouts with CSS

Example - Analytics Dashboard

Page 30: Building Layouts with CSS

3. Row layouts

Page 31: Building Layouts with CSS

Let’s code a blogpost

Page 32: Building Layouts with CSS

using containersLet’s code a blogpost

Page 33: Building Layouts with CSS

<body> <div class=“banner”> <div class=“container”> <!-- title & subtitle --> </div> </div> <div class=“container”>

<!-- content --> </div> </body>

Very simple layout 😊

Page 34: Building Layouts with CSS

Dumb container

.container { width: 900px; margin: 0 auto;}

Page 35: Building Layouts with CSS

@media(max-width: 992px) { .container { width: 700px; }}@media(max-width: 768px) { .container { width: 500px; }}@media(max-width: 480px) { .container { width: 350px; }}

Responsive container

Page 36: Building Layouts with CSS

Let’s code it 💻

Page 37: Building Layouts with CSS

4. Column layouts

Page 38: Building Layouts with CSS

Column layouts

=

99% of layouts

Page 39: Building Layouts with CSS

Easy with flexbox 🔥we need to rehearse flexbox

Page 40: Building Layouts with CSS

Flexbox - Vocabulary

flexbox flex items

Page 41: Building Layouts with CSS

In a flexbox, items are naturally placed by column

.flexbox { display: flex;}

Page 42: Building Layouts with CSS

Then, you can distribute space around or between items using justify-content

.flexbox { justify-content: space-around;}

Page 43: Building Layouts with CSS

Then, you can distribute space around or between items using justify-content

.flexbox { justify-content: space-between;}

Page 44: Building Layouts with CSS

You can center items vertically using align-items

.flexbox { align-items: center;}

Page 45: Building Layouts with CSS

You can set the with of an item killing flex-grow and flex-shrink

.fixed-item { flex: 0 0 25%;}

Page 46: Building Layouts with CSS

You can allow items to grow with a flex-grow

.growing-item { flex-grow: 1;}

Page 47: Building Layouts with CSS

You can allow items to go to the next line with flex-wrap

.flexbox { flex-wrap: wrap;}

Page 48: Building Layouts with CSS

Let’s code a map with results

Page 49: Building Layouts with CSS

Identify the main flexbox

flex item

flexbox

flex item

Page 50: Building Layouts with CSS

Identify fixed and growing items

fixedgrowing

Page 51: Building Layouts with CSS

Set the height of the map to 100vh

Page 52: Building Layouts with CSS

Apply position sticky magic ✨

Map full height Sticking to the top

Page 53: Building Layouts with CSS

Use flex-wrap for the grid of cards

The cards container is also a flexbox containing cards

Page 54: Building Layouts with CSS

Let’s code it 💻

Page 55: Building Layouts with CSS

Let’s code Slack

Page 56: Building Layouts with CSS

Identify main flexboxflexbox

flex item flex item flex item

Page 57: Building Layouts with CSS

fixed fixedgrowing

Identify fixed and growing items

Page 58: Building Layouts with CSS

Let’s code it 💻

Page 59: Building Layouts with CSS

5. Grid layouts

Page 60: Building Layouts with CSS

Easy with CSS grid 🔥we need to rehearse CSS grid

Page 61: Building Layouts with CSS

First, define your grid

Page 62: Building Layouts with CSS

Then, define each element behavior

“ I start row 1 and take 1 row I start column 1 and take 2 columns “

Page 63: Building Layouts with CSS

Then, define each element behavior

“ I start row 1 and take 3 rows I start column 3 and take 1 column “

Page 64: Building Layouts with CSS

Let’s code a dashboard

Page 65: Building Layouts with CSS

Recap 🔥Row layouts: center content with container

Column layouts: flexbox is your friend

Grid layouts: define your CSS grid, that’s it!

Page 66: Building Layouts with CSS

Want to go further? 🚀lewagon.com/apply