Grid 栅格

Grid 栅格

概述

我们采用了24栅格系统,将区域进行24等分,这样可以轻松应对大部分布局问题。使用栅格系统进行网页布局,可以使页面排版美观、舒适。

我们定义了两个概念,行row和列col,具体使用方法如下:

  • 使用row在水平方向创建一行

注意:非 template/render 模式下,需使用 i-col。

代码示例

<template> <Row type="flex"> <Col span="6" order="4">1 | order-4</Col> <Col span="6" order="3">2 | order-3</Col> <Col span="6" order="2">3 | order-2</Col> <Col span="6" order="1">4 | order-1</Col> </Row> </template> <script> export default { } </script>

<template> <Row> <Col span="18" push="6">col-18 | push-6</Col> <Col span="6" pull="18">col-6 | pull-18</Col> </Row> </template> <script> export default { } </script>

<template> <Row> <Col span="8">col-8</Col> <Col span="8" offset="8">col-8 | offset-8</Col> </Row> <br> <Row> <Col span="6" offset="8">col-6 | offset-8</Col> <Col span="6" offset="4">col-6 | offset-4</Col> </Row> <br> <Row> <Col span="12" offset="8">col-12 | offset-8</Col> </Row> </template> <script> export default { } </script>

<template> <p>子元素向左排列</p> <Row type="flex" justify="start" class="code-row-bg"> <Col span="4">col-4</Col> <Col span="4">col-4</Col> <Col span="4">col-4</Col> <Col span="4">col-4</Col> </Row> <p>子元素向右排列</p> <Row type="flex" justify="end" class="code-row-bg"> <Col span="4">col-4</Col> <Col span="4">col-4</Col> <Col span="4">col-4</Col> <Col span="4">col-4</Col> </Row> <p>子元素居中排列</p> <Row type="flex" justify="center" class="code-row-bg"> <Col span="4">col-4</Col> <Col span="4">col-4</Col> <Col span="4">col-4</Col> <Col span="4">col-4</Col> </Row> <p>子元素等宽排列</p> <Row type="flex" justify="space-between" class="code-row-bg"> <Col span="4">col-4</Col> <Col span="4">col-4</Col> <Col span="4">col-4</Col> <Col span="4">col-4</Col> </Row> <p>子元素分散排列</p> <Row type="flex" justify="space-around" class="code-row-bg"> <Col span="4">col-4</Col> <Col span="4">col-4</Col> <Col span="4">col-4</Col> <Col span="4">col-4</Col> </Row> </template> <script> export default { } </script>

<template> <p>顶部对齐</p> <Row type="flex" justify="center" align="top" class="code-row-bg"> <Col span="4"><p style="height: 80px">col-4</p></Col> <Col span="4"><p style="height: 30px">col-4</p></Col> <Col span="4"><p style="height: 100px">col-4</p></Col> <Col span="4"><p style="height: 60px">col-4</p></Col> </Row> <p>底部对齐</p> <Row type="flex" justify="center" align="bottom" class="code-row-bg"> <Col span="4"><p style="height: 80px">col-4</p></Col> <Col span="4"><p style="height: 30px">col-4</p></Col> <Col span="4"><p style="height: 100px">col-4</p></Col> <Col span="4"><p style="height: 60px">col-4</p></Col> </Row> <p>居中对齐</p> <Row type="flex" justify="center" align="middle" class="code-row-bg"> <Col span="4"><p style="height: 80px">col-4</p></Col> <Col span="4"><p style="height: 30px">col-4</p></Col> <Col span="4"><p style="height: 100px">col-4</p></Col> <Col span="4"><p style="height: 60px">col-4</p></Col> </Row> </template> <script> export default { } </script>

<template> <Row> <Col :xs="2" :sm="4" :md="6" :lg="8">Col</Col> <Col :xs="20" :sm="16" :md="12" :lg="8">Col</Col> <Col :xs="2" :sm="4" :md="6" :lg="8">Col</Col> </Row> </template> <script> export default { } </script>

<template> <Row> <Col :xs="{ span: 5, offset: 1 }" :lg="{ span: 6, offset: 2 }">Col</Col> <Col :xs="{ span: 11, offset: 1 }" :lg="{ span: 6, offset: 2 }">Col</Col> <Col :xs="{ span: 5, offset: 1 }" :lg="{ span: 6, offset: 2 }">Col</Col> </Row> </template> <script> export default { } </script>

API

Row props

属性说明类型默认值
gutter栅格间距,单位 px,左右平分Number0
type布局模式,可选值为flex或不选,在现代浏览器下有效String-
alignflex 布局下的垂直对齐方式,可选值为top、middle、bottomString-
justifyflex 布局下的水平排列方式,可选值为start、end、center、space-around、space-betweenString-
class-name自定义的class名称String-

Col props

属性说明类型默认值
span栅格的占位格数,可选值为0~24的整数,为 0 时,相当于display:noneNumber | String-
order栅格的顺序,在flex布局模式下有效Number | String-
offset栅格左侧的间隔格数,间隔内不可以有栅格Number | String-
push栅格向右移动格数Number | String-
pull栅格向左移动格数Number | String-
class-name自定义的class名称String-
xs<768px 响应式栅格,可为栅格数或一个包含其他属性的对象Number | Object-
sm≥768px 响应式栅格,可为栅格数或一个包含其他属性的对象Number | Object-
md≥992px 响应式栅格,可为栅格数或一个包含其他属性的对象Number | Object-
lg≥1200px 响应式栅格,可为栅格数或一个包含其他属性的对象Number | Object-