learning css in 2020. · slides & resources learning css in 2020. rachel andrew

98
Slides & resources https://noti.st/rachelandrew Learning CSS in 2020. Rachel Andrew

Upload: others

Post on 29-Sep-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Learning CSS in 2020.Rachel Andrew

Page 2: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Doing things on the web since 1996

Co-founder Perch CMS & Notist. Editor in Chief Smashing Magazine. Writer of many books. CSS Working Group

Member representing Fronteers. Spec editor Multicol and Page Floats. MDN tech writer.

Page 3: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

I learn a thing.I write it down.

I share it.

Page 4: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

I thought that I had teaching CSS layout all

figured out

Page 5: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Talking about CSS as a layout system

Page 6: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Talking about CSS as a layout system

Page 7: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

As students today you have a massive advantage.

Page 8: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

You can learn CSS in the same structured way as you learn

any other language.

Page 9: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

• Flow Layout• Changing the value of display• Out of flow elements• Block Formatting Contexts• Writing Modes• Logical, flow-relative properties and values• Alignment• Sizing• Media & Feature Queries

Page 10: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Understanding display

Page 11: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Normal FlowBlock and Inline Layout

Page 12: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Page 13: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

CSS is doing work for us, before we write any CSS.

Page 14: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Page 15: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {display: flex;

}

Page 16: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {display: grid;grid-template-columns: 1fr 1fr 1fr;

}

Page 17: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Changing the value of display changes that element and its

direct children.

Page 18: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Page 19: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

The two values of display

Page 20: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {display: block grid;grid-template-columns: 1fr 1fr 1fr;

}

Page 21: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {display: inline grid;grid-template-columns: 1fr 1fr 1fr;

}

Page 22: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

The outer display typeHow the box behaves in the layout - block or inline

Page 23: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

The inner display typeThe formatting context of the direct children – grid, flex etc.

Page 24: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Busting out of flow

Page 25: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

position

Page 26: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.position {position: absolute;

}

Page 27: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

float

Page 28: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.box {background-color: rgb(43,91,128);

}

Page 29: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

display: flow-root

Page 30: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Creating a new Block Formatting Context

Page 31: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.box {background-color: rgb(43,91,128);display: flow-root;

}

Page 32: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Writing Modes

Page 33: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Block Dimension

writing-mode: horizontal-tb;

Inline Dimension

Page 34: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Inline Dimension

writing-mode: vertical-rl;

Block Dimension

Page 35: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Block Start

Block Start

Block End

Block EndBlock E

nd

Page 36: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Inline Start

Inline End

Inline Start

Inline End

Page 37: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Web layout was tied to physical dimensions

We think in top, right, bottom, left. Or width & height.

Page 38: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {width: 600px;height: 300px;

}

Page 39: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Logical Properties & Values

Page 40: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {inline-size: 600px;block-size: 300px;

}

Page 41: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

block-size =

height

inline-size = width

Page 42: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

inline-size = heig

ht

block-size = width

Page 43: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {padding-top: 10px;padding-right: 2em;margin-bottom: 2em;

}

.example {padding-block-start: 10px;padding-inline-end: 2em;margin-block-end: 2em;margin-inline: 1em;

}

Physical v. Logical

Page 44: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {border-start-start-radius: 20px;border-start-end-radius: 3em;border-end-start-radius: 2em 4em;border-end-end-radius: 5px;

}

Page 45: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Understand this flow-relative, logical world.

Page 46: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Box Alignmenthttps://drafts.csswg.org/css-align/

Page 47: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Aligning things in the blockand inline dimensions.

Page 48: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Distribution of space and alignment of items within

their space.

Page 49: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Block Start

Inline Start

Page 50: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

justify-contentIn Grid, inline dimension space distribution between tracks

Page 51: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {justify-content: space-between;

}

Page 52: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

align-contentIn Grid, block dimension space distribution between tracks

Page 53: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {align-content: end;

}

Page 54: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

In flexbox, we justify on the main axis and

align on the cross axis

Page 55: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

justify-contentIn Flex, main axis space distribution between flex items

Page 56: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {justify-content: flex-end;

}

Page 57: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

align-contentIn Flex, cross axis space distribution between flex lines

Page 58: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {align-content: space-around;

}

Page 59: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

For –content properties to do anything, you must have spare

space to distribute!

Page 60: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Page 61: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.item {justify-self: end;align-self: end;

}

Page 62: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {justify-items: end;align-items: end;

}

Page 63: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

“[justify-content] does not apply to flex items, because there is more than one item in the main axis.”

Page 64: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.item {align-self: center;

}

Page 65: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

“Prior to alignment via justify-content and align-self, any positive free space is distributed to auto margins in that dimension.”

Page 66: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example div:last-child {margin-left: auto;

}

Page 67: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Let’s stop calling stuff that is in the spec a CSS ‘hack’

Page 68: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Safe and Unsafe alignment

Avoiding CSS data loss

Page 69: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {display: flex;flex-direction: column;align-items: center;

}

Page 70: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {display: flex;flex-direction: column;align-items: safe center;

}

Page 71: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Box Sizinghttps://drafts.csswg.org/css-sizing-3/

Page 72: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

What about the Box Model?

Page 73: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

When we had to control the size of each item in a layout,

the Box Model was key.

Page 74: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Page 75: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

500px

Page 76: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

30px + 500px + 30px

Page 77: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

5px + 30px + 500px + 30px + 5px

Page 78: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

40px + 5px + 30px + 500px + 30px + 5px + 40px

Page 79: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

What is the inline-size or width of the box?

By default, the content-box

Page 80: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

If you want the specified width to include padding

and borderSet the box-sizing property to border-box.

Page 81: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {box-sizing: border-box;

}

Page 82: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

How big is that box?

Page 83: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

In the past everything was a length or a percentage.

Page 84: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

What is the minimum and maximum size of this thing?

Page 85: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {grid-template-columns: min-content max-content;

}

Page 86: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Any content-based sizing is worked out based on these min and max content sizes.

Page 87: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example {display: flex;

}

Page 88: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example > * {flex: auto;

}

Page 89: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example > * {flex: auto;

}

Page 90: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

.example > * {flex: 1;

}

Page 91: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Old browsers. They exist.

Page 92: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

We have a specification. Some of it isn’t implemented yet.

Page 93: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Lack of support is very different to the buggy

support of the past.

Page 94: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Media & Feature QueriesHow big is my viewport? Is this a touchscreen? Does this browser support Grid? Respond based on the answers.

Page 95: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Avoid resources describing CSS as a weird and quirky

thing.

Page 96: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

CSS is unlike other languages because it serves

environments like no other.

Page 97: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Learn CSS as it is today.

Page 98: Learning CSS in 2020. · Slides & resources  Learning CSS in 2020. Rachel Andrew

Slides & resources https://noti.st/rachelandrew

Thank you!@rachelandrew