大漠 伪前端, 就职于淘宝

Similar documents
5-1 nav css 5-2

XHTML width/height bdo a code href object charset codebase hreflang archive lang type alt dir name name xml:lang rel/rev align shape/coords hspace/vsp

(Microsoft Word - 11\244T\246\342\277\337\260l\302\334.doc)

coverage2.ppt

Microsoft Word TW.doc

7. 小 星 星 一 閃 一 閃 亮 晶 晶, 滿 天 都 是 小 星 星 ; 掛 在 天 空 放 光 明, 好 像 許 多 小 眼 睛 ; 一 閃 一 閃 亮 晶 晶, 滿 天 都 是 小 星 星

2015年全国射箭冠军赛.xls

CH15.indd

Chapter V.S. PC

Microsoft PowerPoint ShengYang Presentation Slides_240609

Chapter 位元素04 定放棄在網頁版面中使用表格, 是 Web 標準的關鍵之一 其實表格使用的目的不在此, 它應該是用來顯示格狀資料, 就如同 Excel 的工作表一樣 不過, 在 CSS 發展以前, 我們習慣用表格來建立一個有格狀的網頁, 讓元素有組織的排列在上, 而且使用一些像間隔圖片 (

2014年大学生村官考试公共基础知识:社会革命和社会改革

领导,我不想写CSS代码.key

第 1 列 的 按 鈕 從 Albatross ~ Duck 1, 第 2 列 按 鈕 從 Eagle ~ Hawk 2, 第 3 行 按 鈕 從 Ibis ~ Lark 3, 而 只 有 第 3 列 按 鈕 多 設 定 span 元 素 ( 理 由 後 面 會 詳 細 說 明 ) html 具 h

HTML5 & CSS3 色彩 背景與漸層屬性 12-1 (color property) CSS 3 color HTML opacity HTML CSS Color Module Level 3 W3C CSS

付宝容器 jsapi 档 册 PDF 版本 本版本为实验版本, 为线下独 查看使, 受制于 成 PDF 程序的限制, 样式问题还没有很好的解决, 例如分 切图 代码 亮 推荐使 在线版本, 便实时查看 jsapi 运 效果 如需搜索, 使 阅读 PDF 软件 带功能即可 更多细节样式调整和 录索引探

RUN_PC連載_8_.doc

untitled

上海浦~1

Microsoft Word - 中耳的主要疾病~中耳炎.doc

互動網頁技術系列課程 HTML與CSS網站基礎設計 [12pt]

Improved Preimage Attacks on AES-like Hash Functions: Applications to Whirlpool and Grøstl

week06.key

管道建模基础.ppt

架 支 持 情 境 模 擬 等, 掌 握 這 些 功 能 並 結 合 教 目 標, 就 能 設 計 出 有 助 於 生 習 的 教 遊 戲 本 文 以 下 分 析 並 列 舉 可 以 發 揮 這 些 功 能 的 典 型 案 例 一 提 高 習 興 趣 眾 所 周 知, 遊 戲 一 定 帶 有 趣 味

1. 2. Flex Adobe 3.

《linux从入门到精通》实验指导第三讲:文件及目录操作

5B_sasaki.pdf

C/C++程序设计 - 字符串与格式化输入/输出

2013 C 1 #include <stdio.h> 2 int main(void) 3 { 4 int cases, i; 5 long long a, b; 6 scanf("%d", &cases); 7 for (i = 0; i < cases; i++) 8 { 9 scanf("%

A-1 HTML A-1-1 HTML 1 HTML JSP HTML HTML HTML JSP A HTML HTML HTML HTML HTML HTML HTML HTML.htm.html HTML Windows NotePad HTML IE [ / ] NotePad A-2

2015年莆田一青会射箭资格赛.xls

x-New Royal-TWN-03.indd

软件测试设计

《linux从入门到精通》实验指导第三讲:文件及目录操作

Microsoft Word - template.doc

Bus Hound 5

Microsoft Word - Chinese-Traditional_ M_A4-Booklet.docx

06 01 action JavaScript action jquery jquery AJAX CSS jquery CSS jquery HTML CSS jquery.css() getter setter.css('backgroundcolor') jquery CSS b

区 域 活 动 进 入 中 班 我 们 区 域 的 设 置 和 活 动 材 料 都 有 所 变 化, 同 时 也 吸 引 孩 子 们 积 极 的 参 与 学 习 操 作 区 的 新 材 料 他 们 最 喜 欢, 孩 子 们 用 立 方 块 进 行 推 理 操 作 用 扑 克 牌 进 行 接 龙 游

Microsoft Word - 3. Vitroefication_using_EMGP.docx

IsPostBack 2


Bootstrap 1 % (WWW) APP ios Android AppStore GooglePlay APP RWD ( Respon

可 Web 编程的NativeUI 设计与实现

PowerPoint 簡報

Epson

认定编号

网 页 设 计 实 训 教 程 1.4 实 现 过 程 任 务 1: 制 作 诗 词 欣 赏 页 面 步 骤 1: 打 开 编 辑 环 境, 创 建 HTML 文 档 1 1.html, 保 存 到 指 定 位 置, 在 文 档 中 输 入 HTML 文 档 的 基 本 结 构, 代 码 如 下 :

untitled

2016 年 全 省 一 般 公 共 预 算 收 入 表 ( 代 编 ) 项 目 2016 年 预 算 数 单 位 : 亿 元 2015 年 快 报 数 预 算 数 增 减 % 一 税 收 收 入 增 值 税 ( 含 改 征 增 值 税 )

东北证券股份有限公司关于推荐北京双杰电气股份有限公司

罗 4:12 又 作 受 割 礼 之 人 的 父, 就 是 那 些 不 但 受 割 礼, 并 且 照 我 们 祖 宗 亚 伯 拉 罕, 未 受 割 礼 时 之 信 的 脚 踪 而 行 的 人 一 罗 得 错 误 的 离 别 亚 伯 拉 罕, 渐 渐 挪 移 帐 棚, 直 到 所 多 玛 ( 创 十

Microsoft Word - ch02.doc

四川省普通高等学校

Microsoft Word - AEL020000_CH04_Final.doc

普 卡 : 賠 償 金 額 實 支 實 付 最 高 以 新 台 幣 柒 仟 元 整 為 限 ( 持 卡 人 及 家 屬 實 支 實 付 合 計 最 高 以 新 台 幣 壹 萬 肆 仟 元 整 為 限 ) 2. 行 李 延 誤 ( 六 ~ 二 十 四 小 時 ) 被 保 險 人 於 其 所 搭 乘 之

基于UML建模的管理管理信息系统项目案例导航——VB篇

Business Objects 5.1 Windows BusinessObjects 1

街街街街街街街街

SDS 1.3

Chapter 9: Objects and Classes

新竹高中105學年度第1學期第2次教師甄選簡章

1 1 大概思路 创建 WebAPI 创建 CrossMainController 并编写 Nuget 安装 microsoft.aspnet.webapi.cors 跨域设置路由 编写 Jquery EasyUI 界面 运行效果 2 创建 WebAPI 创建 WebAPI, 新建 -> 项目 ->

Transcription:

CSS Grid Layout 2016-12-17 @ 大漠. #CSSConf https://www.flickr.com/photos/19139526@n00/8331063530/

大漠 伪前端, 就职于淘宝

古老的 table 布局

现代 Web 布局 Float inline-block display: table position (absolute 或 relative) Frameworks( 很多 Frameworks)

希望的 Web 布局 Flexbox (https://drafts.csswg.org/css-flexbox) CSS Grid Layout (https://drafts.csswg.org/css-grid) Box Alignment (https://drafts.csswg.org/css-align)

CSS Grid System

http://960.gs/

Grid System

Grid 计算公式 固定网格计算 cs = 1 => cw = (scw * cs) + (m * (cs 1)) = 80 * 1 + 20 * (1-1) = 80 scw = ( 容器宽度 (m * (mc 1))) / mc cw = (scw * cs) + (m * (cs 1)) scw: 指的是单列宽度 m: 指的是列间距 mc: cw 最大列数 = (scw(* 一般是 cs) + 12) (m * (cs 1)) cw: 列宽度 网格容器总宽度 1180 cs = 2 => cw = (scw * cs) + (m * (cs 1)) = 80 * 2 + 20 * (2-1) = 180 网格间距 m = 20 cs = 3 => cw = (scw * cs) + (m * (cs 1)) = 80 * 3 + 20 * (3-1) = 280 网格列数 mc = 12 cs = 4 => cw = (scw * cs) + (m * (cs 1)) = 80 * 4 + 20 * (4-1) = 380 cs = 5 => cw = (scw * cs) + (m * (cs 1)) = 80 * 5 + 20 * (5-1) = 480 cs = 6 => cw = (scw * cs) + (m * (cs 1)) = 80 * 6 + 20 * (6-1) = 580 cs = 7 => cw = (scw * = cs) ( 容器宽度 + (m * (cs (m * 1)) (mc = 801))) * 7 + / 20 mc* (7-1) = 680 cs = 8 => cw = (scw * = cs) (1180 + (m- *(20 (cs* (12 1)) - 1))) = 80 /* 12 8 + 20 * (8-1) = 780 cs = 9 => cw = (scw * = cs) 80 + (m * (cs 1)) = 80 * 9 + 20 * (9-1) = 880 cs = 10 => cw = (scw * cs) + (m * (cs 1)) = 80 * 10 + 20 * (10-1) = 980 cs = 11 => cw = (scw * cs) + (m * (cs 1)) = 80 * 11 + 20 * (11-1) = 1080 cs = 12 => cw = (scw * cs) + (m * (cs 1)) = 80 * 12 + 20 * (12-1) = 1180 cs: 列数 (1~12)

[class*="m--"]{ padding-right: $gutter; padding-left: $gutter; @for $i from 1 through 12 { &.m--#{$i { width: (80 * $i + 20 * ($i - 1)) * 1px; http://codepen.io/airen/full/rmeggr/

Grid 计算公式 流体网格计算 cs = 1 => cw = (scw * cs) + (m * (cs 1)) = 6.86667% * 1 + 1.6% * (1-1) = 6.86667% 网格容器总宽度 100% cs = 2 => cw = (scw * cs) + (m * (cs 1)) = 6.86667% * 2 + 1.6% * (2-1) = 15.33333% 网格间距 m = 1.6% scw = (100% (m * (mc 1))) / mc 网格列数 mc = 12 cs = 3 => cw = (scw * cs) + (m * (cs 1)) = 6.86667% * 3 + 1.6% * (3-1) = 23.8% cs = 4 => cw = (scw * cs) + (m * (cs 1)) = 6.86667% * 4 + 1.6% * (4-1) = 32.26667% cs = 5 => cw = (scw * cs) + (m * (cs 1)) = 6.86667% * 5 + 1.6% * (5-1) = 40.73333% cw = (scw * cs) + (m * (cs 1)) cs = 6 => cw = (scw * cs) + (m * (cs 1)) = 6.86667% * 6 + 1.6% * (6-1) = 49.2% cs = 7 => cw = (scw * cs) + (m * (cs 1)) = 6.86667% * 7 + 1.6% * (7-1) = 57.66667% cs = 8 => cw = (scw * cs) + (m * (cs 1)) = 6.86667% * 8 + 1.6% * (8-1) = 66.13333% scw: 指的是单列宽度 scw = ( 容器宽度 (m * (mc 1))) / mc cs = 9 => cw = (scw * cs) + (m * (cs 1)) = 6.86667% * 9 + 1.6% * (9-1) = 74.6% scw = (100% - (1.6% * (12-1))) / 12 m: 指的是列间距 (1.6%) cs = 10 => cw = (scw * cs) + (m * (cs 1)) = 6.86667% * 10 + 1.6% * (10-1) = 83.06667% scw = 6.86666666667% cs = 11 => cw = (scw * cs) + (m * (cs 1)) = 6.86667% * 11 + 1.6% * (11-1) = 91.53333% mc: 最大列数 ( 一般是 12) cw = (scw * cs) + (m * (cs 1)) cw: 列宽度 cs = 12 => cw = (scw * cs) + (m * (cs 1)) = 6.86667% * 12 + 1.6% * (12-1) = 100% cs: 列数 (1~12)

[class*="m--"]{ &:not(:first-child){ margin-left: $gutter; @for $i from 1 through 12 { &.m--#{$i { width: (6.86666666667 / 100 * $i + 1.6 / 100 * ($i - 1)) * 100%; http://codepen.io/airen/full/dpbbyx/

CSS 变量创建 Grid.container { max-width: 1140px; margin: 3em auto; padding: var(--gutter); :root{.row{ display: flex; flex-wrap: wrap; --color: #0C3934; --bg: #F8EBEE; margin: 0 calc(var(--gutter) - ( var(--gutter) * 2) ) 20px; [class*="m--"]{ /* Grid */ padding-right: calc(var(--gutter)); padding-left: calc(var(--gutter)); --gutter: 10px; /* 列间距 */ flex-basis: calc((100% / var(--columns)) * var(--column-width)); --columns: 12; /* 列数 */ @for $i from 1 through 12 { &.m--#{$i { --column-width: $i;

http://www.w3cplus.com/css3/create-css-grid-system-with-css-variables.html http://codepen.io/airen/full/jmjvon/

Grid Frameworks Susy 960gs BootStrap Grid Zen Grids

CSS Grid Layout

CSS Grid Layout 发展过程 2010 年由微软提出, 最早在 IE10 实施 2011 年 4 月首次公开草案 2015 年 3 月 2 日 Chrome 支持 2016 年 9 月 29 日成为 W3C 候选标准

Grid 术语

网格容器和网格项目 display: grid inline-grid a <div class="container"> <div class="item item-1"></div> 网格项目 </div> <div class="item item-2"></div> <div class="item item-3"></div>

网格线 grid-template-columns: 300px 200px 100px; grid-template-rows: 100px 50px;

网格轨道

网格单元格

网格区域

网格间距

定义网格

grid-template-columns: 300px 200px 100px; grid-template-rows: 100px 50px;

.cards { display: grid; http://codepen.io/airen/full/woyoxz/

.cards { display: grid; grid-template-columns: 33.33% 33.33% 33.33%; grid-template-rows: 200px 200px 200px; http://codepen.io/airen/full/mbqbqq/

.cards { display: grid; grid-template-columns: 33.33% 33.33% 33.33%; grid-template-rows: 200px 200px 200px; grid-gap: 20px; http://codepen.io/airen/full/glvlzr/

.cards { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 200px 200px 200px; grid-gap: 20px; http://codepen.io/airen/full/woyozj/

.cards { display: grid; grid-template-columns: 500px 1fr 2fr; grid-template-rows: 200px 200px 200px; grid-gap: 20px; http://codepen.io/airen/full/nbybvg/

.cards { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 200px 200px 200px; grid-gap: 20px; http://codepen.io/airen/full/woyozj/

.cards { display: grid; grid-template-columns: repeat(3, 1fr) ; grid-template-rows: 200px 200px 200px; grid-gap: 20px; http://codepen.io/airen/full/gnqnbz/

.cards { display: grid; grid-template-columns: repeat(3, 1fr) ; grid-template-rows: 200px 200px 200px; grid-gap: 20px; http://codepen.io/airen/full/ypepmx/

.cards { display: grid; grid-template-columns: repeat(3, 1fr) ; grid-auto-rows: 200px; grid-gap: 20px; http://codepen.io/airen/full/abqpbx/

.cards { display: grid; grid-template-columns: repeat(auto-fill, 200px) ; grid-gap: 20px; http://codepen.io/airen/full/abqpbx/

.cards { display: grid; grid-template-columns: repeat(auto-fill, 200px) ; grid-gap: 20px; http://codepen.io/airen/full/abqpbx/

http://codepen.io/airen/full/abqpbx/

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)) ; grid-gap: 20px; http://codepen.io/airen/full/obqwnm/

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)) ; grid-gap: 20px; http://codepen.io/airen/full/obqwnm/

http://codepen.io/airen/full/obqwnm/

.card:nth-child(1) { grid-column-start: 2; grid-column-end: 4; grid-row-start: 1; grid-row-end: 3; http://codepen.io/airen/full/nbydjy/

.card:nth-child(1) { grid-column: 2 / 4; grid-row: 1 / 3; http://codepen.io/airen/full/lbqxjp/

.card:nth-child(1) { grid-area: 1 / 2 / 3 / 4; /*grid-area: grid-row-start / grid-column-start / grid-row-end / grid- columnend*/ http://codepen.io/airen/full/womrej/

.cards { display: grid; grid-template-columns: [side-start] 1fr [main-start] 1fr 1fr [main-end];.card:nth-child(1) { grid-column: main-start / main-end; grid-row: main-start / main-end; grid-template-rows: [main-start] 200px 200px [main-end]; grid-gap: 20px; http://codepen.io/airen/full/zbrlap/

.cards { display: grid; grid-template-columns:.card:nth-child(1) { grid-area: main; [side-start] 1fr [main-start] 1fr 1fr [main-end]; grid-template-rows: [main-start] 200px 200px [main-end]; grid-gap: 20px; http://codepen.io/airen/full/enqzlx/

.cards { display: grid; grid-template-columns: repeat(3, 1fr);.card:nth-child(1) { grid-area: main;.card:nth-child(4) { grid-template-rows: 200px 200px; grid-template-areas: grid-area: side1; side1 main main side2 main main ; grid-gap: 20px;.card:nth-child(8) { grid-area: side2; http://codepen.io/airen/full/mbqjgx/

A 12 column, flexible grid

<div class="col-xs-6 col-md-4">.col-xs-6.col-md-4</div> </div> <!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop --> <div class="row"> <div class="col-xs-6 col-md-4">.col-xs-6.col-md-4</div> <div class="col-xs-6 col-md-4">.col-xs-6.col-md-4</div> <div class="col-xs-6 col-md-4">.col-xs-6.col-md-4</div> </div> <!-- Columns are always 50% wide, on mobile and desktop --> <div class="row"> BootStrap Grid: http://getbootstrap.com/css/#grid

BootStrap Grid: http://getbootstrap.com/css/#grid

.wrapper { display: grid; http://codepen.io/airen/full/bblgoj/

.wrapper { display: grid; grid-template-columns: repeat(12, [col] 1fr); grid-template-rows: repeat(5, [row] auto); grid-column-gap: 1em; grid-row-gap: 15px; http://codepen.io/airen/full/abqpxd/

.header { grid-column: col / span 12; grid-row: 1;.box1 { grid-column: col / span 4; grid-row: row 2; http://codepen.io/airen/full/knqaye/

.box1 { grid-column: col / span 4; grid-row: row 2 / span 2;.box2 { grid-column: col 5 / span 4; grid-row: row 2 / span 3; http://codepen.io/airen/full/womrvl/

.container { display: grid; grid-template-columns: repeat(12, [col] 1fr); grid-column-gap: 1em; grid-row-gap: 15px; [class*= col ]:nth-of-type(n+1):nth-of-type(-n+12){ grid-column: span; [class*= col ]:nth-of-type(n+13):nth-of-type(-n+18){ grid-column: span 2; http://codepen.io/airen/full/mbqpkw/

Grid and Box Alignment Module

.wrapper { display: flex;.wrapper li { min-width: 1%; flex: 1 0 25%;.wrapper li:nth-child(2) { align-self: center;.wrapper li:nth-child(3) { align-self: flex-start;.wrapper li:nth-child(4) { align-self: flex-end; http://codepen.io/airen/full/pbqpmy/

.wrapper { display: grid; grid-template-columns: repeat(4, fr);.wrapper li:nth-child(2) { align-self: center;.wrapper li:nth-child(3) { align-self: start;.wrapper li:nth-child(4) { align-self: end; http://codepen.io/airen/full/nbypvv/

Flexbox Layout Or Grid Layout?

Flexbox Layout 定义一个维度, 行或者列 Grid Layout 定义两个维度, 行和列

http://www.w3cplus.com/css3/solving-problems-with-css-grid-and-flexbox-the-card-ui.html http://codepen.io/airen/full/qqxrxp/

待续...

相关资料 Grid 规范 : https://www.w3.org/tr/css-grid-1 Box Alignment 规范 :https://www.w3.org/tr/css-align-3 Flexbox 规范 : https://www.w3.org/tr/css-flexbox-1 Flexbox 教程 :http://www.w3cplus.com/blog/tags/157.html Grid 教程 :http://www.w3cplus.com/blog/tags/355.html Grid 案例 :http://codepen.io/collection/xmzonw Github:https://github.com/airen/grid-layout Grid 更多资源 :http://gridbyexample.com/

THANK YOU