设计内在的布局

A presentation at 设计内在的布局 in May 2021 in by w3cplus

Slide 1

Slide 1

设计内在的布局 2021-05-26 @⼤漠 . #中国.杭州

Slide 2

Slide 2

⼤漠 伪前端 F(x) TEAM

Slide 3

Slide 3

Web布局前世与今⽣

Slide 4

Slide 4

Web布局前世与今⽣

Slide 5

Slide 5

Web布局前世与今⽣ https://www.w3cplus.com/css/web-layout-the-evolution-of-web-layouts.html

Slide 6

Slide 6

Web现代主流布局

Slide 7

Slide 7

设计内在的布局(⽬标)

Slide 8

Slide 8

语义化HTML模板

Slide 9

Slide 9

语义化HTML模板

Slide 10

Slide 10

Flow Layout (NO Layout)

Slide 11

Slide 11

Basic CSS

Slide 12

Slide 12

Float Layout

Slide 13

Slide 13

Float Layout https://codepen.io/airen/full/qBrmVyQ

Slide 14

Slide 14

Float Layout 浮动容器塌陷 https://codepen.io/airen/full/qBrmVyQ

Slide 15

Slide 15

Clear Float Header {display: ow-root;} fl https://codepen.io/airen/full/yLMbpjR

Slide 16

Slide 16

浮动容器可⽤空间不⾜ Header {display: ow-root;} fl https://codepen.io/airen/full/yLMbpjR

Slide 17

Slide 17

Float Layout CSS 浮动很糟糕

Slide 18

Slide 18

Flexbox Layout

Slide 19

Slide 19

Flexbox Layout

Slide 20

Slide 20

Flexbox Layout

Slide 21

Slide 21

CSS Grid Layout

Slide 22

Slide 22

CSS Grid Layout https://codepen.io/airen/full/OJpmqGM

Slide 23

Slide 23

CSS Grid Layout https://codepen.io/airen/full/OJpmqGM

Slide 24

Slide 24

CSS Grid Layout https://codepen.io/airen/full/OJpmqGM

Slide 25

Slide 25

CSS Grid Layout 百分⽐会让⽹格项⽬撑破⽹格容器(示例中有 gap: 14px) https://codepen.io/airen/full/JjWNVMg

Slide 26

Slide 26

CSS Grid Layout https://codepen.io/airen/full/WNpjWgz

Slide 27

Slide 27

CSS Grid Layout https://codepen.io/airen/full/dyvWBoe

Slide 28

Slide 28

CSS Grid Layout https://codepen.io/airen/full/dyvWBoe

Slide 29

Slide 29

CSS Grid Layout 如何更合理的处理空间(⽹格轨道根据内容来决定) https://codepen.io/airen/full/dyvWBoe

Slide 30

Slide 30

CSS Grid Layout ? https://codepen.io/airen/full/VwpbJMV

Slide 31

Slide 31

CSS Grid Layout https://codepen.io/airen/full/QWpvXzG

Slide 32

Slide 32

CSS Grid Layout https://codepen.io/airen/full/QWpvXzG

Slide 33

Slide 33

CSS Grid Layout https://codepen.io/airen/full/dyvWBoe https://codepen.io/airen/full/QWpvXzG

Slide 34

Slide 34

外在尺⼨ vs 内在尺⼨

Slide 35

Slide 35

外在尺⼨ vs 内在尺⼨ 由元素内部内容来决定: ① min-content ② max-content ③ fit-content

Slide 36

Slide 36

外在尺⼨ vs 内在尺⼨ https://codepen.io/airen/full/zYZvGrY

Slide 37

Slide 37

外在尺⼨ vs 内在尺⼨ https://codepen.io/airen/full/zYZvGrY

Slide 38

Slide 38

外在尺⼨ vs 内在尺⼨ https://codepen.io/airen/full/zYZvGrY

Slide 39

Slide 39

外在尺⼨ vs 内在尺⼨ https://codepen.io/airen/full/zYZvNaP

Slide 40

Slide 40

外在尺⼨ vs 内在尺⼨ fit-content 相当于mincontent 和 max-content,其取 值: ① 如果元素的可⽤空间(Available)充⾜,fitcontent 将使⽤ max-content ② 如果元素的可⽤空间(Available)不够充⾜, 比 max-content ⼩点,那就是⽤可⽤空间的值, 不会导致内容溢出 ③ 如果元素的可⽤空间(Available)很⼩,比 min-content还⼩,那就使⽤ min-content https://ishadeed.com/article/intrinsic-sizing-in-css/

Slide 41

Slide 41

外在尺⼨ vs 内在尺⼨ https://www.w3cplus.com/css/grid-layout-part-4.html

Slide 42

Slide 42

外在尺⼨ vs 内在尺⼨ min/max/fit-content使⽤: ① min/max/fit-content ⽤于 flex-basis ⽆效 ② fit-content ⽤于设置⽹格轨道尺⼨的属性上⽆效 ③ ⽹格项⽬或Flex项⽬上显式设置width:fit-content也⽆效,因为它们的默认宽度是mincontent ④ 最好不要在 min-width 或 max-width 上使⽤ fit-content,易造成混乱,建议在 width 上使⽤fit-content

Slide 43

Slide 43

t-content != t-content() ① fit-content 相当于min-content 和 max-content ② fit-content(<length-percentage>) = max(minimum, min(limit, maxcontent)) ③ fit-content(<length-percentage>) = min(min(max-content, vaailablesize), max(min-content, <length-percentage>)) fi fi 外在尺⼨ vs 内在尺⼨

Slide 44

Slide 44

外在尺⼨ vs 内在尺⼨ header {grid-template-columns: max-content t-content(480px) auto;} fi https://codepen.io/airen/full/MWpogJM

Slide 45

Slide 45

fi 外在尺⼨ vs 内在尺⼨ t-content(480px): ① ⽹格第2列(h1)宽度不会超过 480px,即使字号调⼤,内容宽⼤于 480px时,内容会换⾏ ② ⽹格第2列(h1)在内容较短时,可以缩减到⽐ 480px,⽐如字号调⼩,该列宽度也会调⼩ ③ ⽹格容器⽆可⽤空间时,⽹格第2列宽度会⼩到 min-content https://codepen.io/airen/full/MWpogJM

Slide 46

Slide 46

fi 外在尺⼨ vs 内在尺⼨ t-content(480px) = min(max-content, max(min-content, 480px)) ① max(min-content, 480px) 函数会返回两个参数中较⼤的值 ② min() 函数返回参数中较⼩的值,max()返回的值放到 min()函数中,变成其第⼆个参数 https://www.w3cplus.com/css/grid-layout-part-4.html

Slide 47

Slide 47

CSS Grid Layout

Slide 48

Slide 48

CSS Grid Layout

Slide 49

Slide 49

Grid & Flexbox Layout https://codepen.io/airen/full/ZEeyEZa

Slide 50

Slide 50

Grid & Flexbox Layout 虽然在Flexbox容器上显式设置了 ex-wrap: wrap, 但Flexbox容器 ⽆⾜够空间也不会断⾏。这是⽹格轨道(max-content)引起的。 fl https://codepen.io/airen/full/ZEeyEZa

Slide 51

Slide 51

CSS Grid Layout 第三列⽹格轨道是 auto 时, Flex项⽬在没有⾜够空间时会换 ⾏显式,但有空间时右侧会有较多空间多出,菜单项未右对⻬ https://codepen.io/airen/full/bGqRNza

Slide 52

Slide 52

CSS Grid Layout 请记住 Flexbox 容器 和 Flex 项⽬的变化 https://codepen.io/airen/full/eYvRNYa

Slide 53

Slide 53

CSS Grid Layout https://codepen.io/airen/full/BaWZjqd

Slide 54

Slide 54

CSS Grid Layout https://codepen.io/airen/full/LYWLGwG

Slide 55

Slide 55

CSS Grid Layout https://codepen.io/airen/full/LYWLGwG

Slide 56

Slide 56

CSS Grid Layout https://codepen.io/airen/full/WNpOwPB

Slide 57

Slide 57

CSS Grid Layout Flexbox https://codepen.io/airen/full/eYvRNYa Grid https://codepen.io/airen/full/WNpOwPB

Slide 58

Slide 58

CSS Grid Layout https://codepen.io/airen/full/bGqReZp

Slide 59

Slide 59

杂乱⽆章⽂字(disjointed text)

Slide 60

Slide 60

CSS Grid Layout https://codepen.io/airen/full/KKWqgbe

Slide 61

Slide 61

CSS Grid Layout https://codepen.io/airen/full/JjWJbaE

Slide 62

Slide 62

CSS Grid Layout https://codepen.io/airen/full/JjWJbaE

Slide 63

Slide 63

CSS Grid Layout

Slide 64

Slide 64

CSS Grid Layout

Slide 65

Slide 65

CSS Grid Layout

Slide 66

Slide 66

CSS Grid Layout https://codepen.io/andybarefoot/full/PBPrex

Slide 67

Slide 67

CSS Grid Layout https://www.w3cplus.com/css/highlights-from-building-a-magazine-layout.html

Slide 68

Slide 68

CSS Grid Layout https://www.smashingmagazine.com/2019/04/art-direction-for-the-web-using-css-shapes/ https://www.w3cplus.com/css/highlights-from-building-a-magazine-layout.html

Slide 69

Slide 69

CSS Grid Layout https://codepen.io/andybarefoot/full/oNjxYYG https://codepen.io/andybarefoot/full/wvKJweJ https://www.w3cplus.com/css/responsive-grid-layout.html

Slide 70

Slide 70

CSS Grid Layout https://labs.jensimmons.com/

Slide 71

Slide 71

CSS Layout Patterns https://csslayout.io/

Slide 72

Slide 72

New Responsive Layout https://youtu.be/jUQ2-C5ZNRc https://web.dev/new-responsive/

Slide 73

Slide 73

New Responsive Layout https://codepen.io/una/full/mdOgyVL https://web.dev/new-responsive/

Slide 74

Slide 74

Design To Code: imgcook.com

Slide 75

Slide 75

THANK YOU