SlideShare a Scribd company logo
[Modern Web] CSS3 Grid Layout
[Modern Web] CSS3 Grid Layout
consectetur adipisicing elit, sed do
eiusmod tempor incididunt
consectetur adipisicing elit,
sed do eiusmod tempor
incididunt dolor in
reprehenderit in voluptate
eiusmod
sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt
mollit anim id est laborum.
[Modern Web] CSS3 Grid Layout
yourcompany
• 六⾓角學院講師

⾼高雄前端社群核⼼心成員
• 專長:
• CSS、Sass
• 視覺設計
• Personal Blog: http://wcc723.github.io/
• Facebook: https://fb.com/wccCasper
• 快速了解 Grid Layout
• 案例說明
• 他是⼀個新的 CSS 屬性,直到今年才有比較多的
瀏覽器⽀援。

Chrome 57, Firefox 52, Safari 10.1…
• CSS Grid Layout 可以處理⼆維排版 (欄與列)

Flex 僅能處理 欄或列
• CSS Grid 與 Flex 可以共⽤
[Modern Web] CSS3 Grid Layout
[Modern Web] CSS3 Grid Layout
[Modern Web] CSS3 Grid Layout
yourcompany
[Modern Web] CSS3 Grid Layout
[Modern Web] CSS3 Grid Layout
• display
• grid-template
• grid-template-columns
• grid-template-rows
• grid-template-areas
• grid-gap
• grid-column-gap
• grid-row-gap
• justify-items (內部元件)
• align-items (內部元件)
• justify-content (整體元件)
• align-content (整體元件)
• grid-auto-columns
• grid-auto-rows
• grid-auto-flow
必要
排版屬性
欄欄列列間隔
對⿑齊屬性
簡易易⾃自動屬性
• grid-column
• grid-column-start
• grid-column-end
• grid-row
• grid-row-start
• grid-row-end
• grid-area
• justify-self
• align-self
欄欄位起迄
列列位起迄
Area 定義
對⿑齊屬性
[Modern Web] CSS3 Grid Layout
.container {
}
50px 200px auto
100px
auto
… …
gap
display: grid;
grid-template-columns: 50px 200px auto 200px 50px;
grid-gap: 10px 15px;
grid-template-rows: 100px auto 100px ;
.container {
display: grid;
grid-template-columns: 50px 200px auto 200px 50px;
grid-template-rows: 100px auto 100px ;
grid-gap: 10px 15px;
}
50px 200px auto
1 2 3 4 5 6
1
2
3
4
100px
auto
… …
.item-xxx{
grid-column: start / end;
grid-row: start / end;
}
50px 200px auto
1 2 3 4 5 6
1
2
3
4
100px
auto
… …
grid-column: 1 / 3;
grid-row: 2 / 3;
grid-column: 1 / 3;
grid-row: 2 / 3;
.item-xxx{
grid-column: start / end;
grid-row: start / end;
}
50px 200px auto
1 2 3 4 5 6
1
2
3
4
100px
auto
… …
grid-column: 1 / 6;
grid-row: 1 / 2;
grid-column: 1 / 3;
grid-row: 2 / 3;
grid-column: 3 / 6;
grid-row: 3 / 4;
[Modern Web] CSS3 Grid Layout
Navbar
Header
Content
Menu
Content
Header
Navbar
Menu
Navbar
Header
Content
Menu
300px auto
Content
Header
Navbar
Menu
1
2
3
4
1 2 3
5
範例 網⾴

https://codepen.io/Wcc723/full/EvWZgo/
[Modern Web] CSS3 Grid Layout
auto50px 200px … …
auto50px 200px … …
justify-content (整體元件⽔平對齊)
auto50px 200px … …
justify-content: flex-end
auto50px 200px … …
justify-content: flex-start
auto50px 200px … …
justify-content: center
justify-content: space-between
auto50px 200px … …
auto
50px 200px … …
align-content: (整體元件垂直對齊)
align-content: flex-start;
auto
50px 200px … …
auto
50px 200px … …
• justify-items: center (內部元件⽔平位置)
• align-items: center (內部元件垂直位置)
auto
50px 200px … …
• justify-items: center (內部元件⽔平位置)
• align-items: center (內部元件垂直位置)
• justify-self: flex-end;
• align-self: flex-start;
外層 justify-content
外層 align-content
外層 justify-items
外層 align-items
內層 justify-self
內層 align-self
• 對齊排版
• http://wcc723.github.io/WorkShop-gh-pages/
cssGridDisplay/
略懂了
.container {
display: grid;
grid-template-columns: 

repeat(16, 45px);
grid-template-rows: 

repeat(16, 45px);
}
grid-column: 3 / 11;
grid-row: 3 / 11;
.container {
display: grid;
grid-template-columns: 

repeat(16, 45px);
grid-template-rows: 

repeat(16, 45px);
}
蒙德⾥安範例

https://goo.gl/erWkg6
[Modern Web] CSS3 Grid Layout
[Modern Web] CSS3 Grid Layout
貪食蛇例

http://wcc723.github.io/WorkShop-gh-pages/snakesnake/
[Modern Web] CSS3 Grid Layout
[Modern Web] CSS3 Grid Layout
[Modern Web] CSS3 Grid Layout
[Modern Web] CSS3 Grid Layout
.grid {
transform: skewY(-12deg);
}
參考說明

https://goo.gl/A7ufbs
Stripe 網⾴

https://stripe.com/connect
Grid Layout 平⾯風格網⾴

https://goo.gl/vkbNrZ
[Modern Web] CSS3 Grid Layout
優點
• 可以做出類似平⾯設計風格的網⾴
• 排版模式又多了⼀種選擇
缺點
• ⽬前⽀援度還不⾜
• 很多坑⽤過才會體會
範例
• https://codepen.io/Kseso/pen/xqNdmO
• https://stripe.com/connect
• https://goo.gl/vkbNrZ
參考⽂件
• https://css-tricks.com/snippets/css/complete-guide-grid/
• https://developer.mozilla.org/en-US/docs/Web/CSS/
CSS_Grid_Layout
Q and A

More Related Content

PDF
Bootstrap 4 超詳盡解析
PPT
Javascript
PPTX
JavaScript Basic
PPTX
Bootstrap 5 whats new
KEY
Implementing CATiledLayer
PDF
Bootstrap 5 basic
PPTX
Bootstrap 3
Bootstrap 4 超詳盡解析
Javascript
JavaScript Basic
Bootstrap 5 whats new
Implementing CATiledLayer
Bootstrap 5 basic
Bootstrap 3

What's hot (20)

PPTX
AEM and Sling
PPTX
ASP.NET Core MVC + Web API with Overview
PDF
Front-End Frameworks: a quick overview
PPTX
Html5 and-css3-overview
PDF
Flexbox and Grid Layout
PPTX
如何運用Bootstrap 切版?
PDF
BEM It! for Brandwatch
PDF
Introducing CSS Grid Layout
PPTX
SASS - CSS with Superpower
PPT
JavaScript - An Introduction
PDF
CSS - OOCSS, SMACSS and more
PDF
Basic-CSS-tutorial
PDF
Introduction to CSS3
PDF
CSS3 Layout
PDF
Javascript basics
PPTX
Responsive web designing ppt(1)
PPTX
Java script
PPTX
Tailwind CSS.11.pptx
PDF
JavaScript Basics and Best Practices - CC FE & UX
PPTX
Responsive web design ppt
AEM and Sling
ASP.NET Core MVC + Web API with Overview
Front-End Frameworks: a quick overview
Html5 and-css3-overview
Flexbox and Grid Layout
如何運用Bootstrap 切版?
BEM It! for Brandwatch
Introducing CSS Grid Layout
SASS - CSS with Superpower
JavaScript - An Introduction
CSS - OOCSS, SMACSS and more
Basic-CSS-tutorial
Introduction to CSS3
CSS3 Layout
Javascript basics
Responsive web designing ppt(1)
Java script
Tailwind CSS.11.pptx
JavaScript Basics and Best Practices - CC FE & UX
Responsive web design ppt
Ad

More from Chih-cheng Wang (11)

PDF
六角學院 - 從社群到公司
PDF
網址管理與 DNS 託管全攻略
PDF
高雄前端社群 Web 開發讀書會 - 網頁設計規劃
PDF
Bootstrap4 與他的好搭檔
PDF
Sass 基礎教學 - 高雄前端社群(CSS 讀書會)
PDF
專業前端 都如何管理 CSS
PDF
響應式網頁實作坊
PDF
建立 Sass 環境,透過 Node sass
PDF
CSS 讀書會 - 1 (Grid system)
PDF
Slack 基本功能介紹
PDF
Google design
六角學院 - 從社群到公司
網址管理與 DNS 託管全攻略
高雄前端社群 Web 開發讀書會 - 網頁設計規劃
Bootstrap4 與他的好搭檔
Sass 基礎教學 - 高雄前端社群(CSS 讀書會)
專業前端 都如何管理 CSS
響應式網頁實作坊
建立 Sass 環境,透過 Node sass
CSS 讀書會 - 1 (Grid system)
Slack 基本功能介紹
Google design
Ad

[Modern Web] CSS3 Grid Layout