Grid 栅格化
通过基础的 24 分栏,迅速简便地创建布局。
基础布局
通过 row
和 col
组件,并通过 col
组件的 span
属性我们就可以自由地组合布局。
查看代码
vue
<template>
<demo-container class="demo-gov-grid-row">
<gov-row>
<gov-col :span="24"></gov-col>
</gov-row>
<gov-row>
<gov-col :span="12"></gov-col>
<gov-col :span="12"></gov-col>
</gov-row>
<gov-row>
<gov-col :span="8"></gov-col>
<gov-col :span="8"></gov-col>
<gov-col :span="8"></gov-col>
</gov-row>
<gov-row>
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
</gov-row>
</demo-container>
</template>
分栏间隔
Row 组件 提供 gutter
属性来指定每一栏之间的间隔,默认间隔为 0。
查看代码
vue
<template>
<demo-container class="demo-gov-grid-row">
<gov-row :gutter="20">
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
</gov-row>
</demo-container>
</template>
混合布局
查看代码
vue
<template>
<demo-container class="demo-gov-grid-row">
<gov-row :gutter="20">
<gov-col :span="16"></gov-col>
<gov-col :span="8"></gov-col>
</gov-row>
<gov-row :gutter="20">
<gov-col :span="8"></gov-col>
<gov-col :span="8"></gov-col>
<gov-col :span="4"></gov-col>
<gov-col :span="4"></gov-col>
</gov-row>
<gov-row :gutter="20">
<gov-col :span="4"></gov-col>
<gov-col :span="16"></gov-col>
<gov-col :span="4"></gov-col>
</gov-row>
</demo-container>
</template>
分栏偏移
支持偏移指定的栏数。
查看代码
vue
<template>
<demo-container class="demo-gov-grid-row">
<gov-row :gutter="20">
<gov-col :span="6"></gov-col>
<gov-col :span="6" :offset="6"></gov-col>
</gov-row>
<gov-row :gutter="20">
<gov-col :span="6" :offset="6"></gov-col>
<gov-col :span="6" :offset="6"></gov-col>
</gov-row>
<gov-row :gutter="20">
<gov-col :span="12" :offset="6"></gov-col>
</gov-row>
</demo-container>
</template>
对齐方式
当设置align
属性和 justify
属性,会自动开启 flex 布局模式。
justify
属性可设置为 start, center, end, space-between, space-around
align
属性可设置为flex-start, center, flex-end, stretch
。
查看代码
vue
<template>
<demo-container class="demo-gov-grid-row">
<gov-row>
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
</gov-row>
<gov-row justify="center">
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
</gov-row>
<gov-row justify="end">
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
</gov-row>
<gov-row justify="space-between">
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
</gov-row>
<gov-row justify="space-around">
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
<gov-col :span="6"></gov-col>
</gov-row>
</demo-container>
</template>
Row Attributes
参数 | 说明 | 类型 / 示例 | 默认值 |
---|---|---|---|
width | 行宽度,单位 px | string | number | auto |
gutter | 栅格间隔,见 Gutter 示例。 | number | object | array | 0 |
wrap | 是否自动换行 | boolean | false |
align | 垂直对齐方式,对应 css 的 align-item 的值 | string | flex-start |
justify | 水平排列方式,对应 css 的 justify-content 的值 | string | start |
Gutter 示例
vue
<template>
<!--示例 1:基本水平间隔-->
<gov-row :gutter="16"> </gov-row>
<!--示例 2:响应式水平间隔-->
<gov-row :gutter="{ xs: 8, sm: 16, md: 24 }"> </gov-row>
<!--示例 3:水平和垂直间隔-->
<gov-row :gutter="[16, 24]"> </gov-row>
<!--示例 4:水平间隔和响应式垂直间隔-->
<gov-row :gutter="[16, { xs: 8, sm: 16, md: 24 }]"> </gov-row>
<!--示例 5:响应式水平间隔和垂直间隔-->
<gov-row :gutter="[{ xs: 8, sm: 16 }, 24]"> </gov-row>
</template>
名称 | 说明 | 类型 | 默认值 |
---|---|---|---|
xs | <576px 响应式栅格 | number | undefined |
sm | ≥576px 响应式栅格 | number | undefined |
md | ≥768px 响应式栅格 | number | undefined |
lg | ≥992px 响应式栅格 | number | undefined |
xl | ≥1200px 响应式栅格 | number | undefined |
xxl | ≥1600px 响应式栅格 | number | undefined |
Col Attributes
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
span | 栅格占位格数,取 0,1,2...24 ,为 0 时相当于 display: none ,优先级低于 xs , sm , md , lg , xl , xxl | number | undefined |
offset | 栅格左侧的间隔格数,取 0,1,2...24 | number | 0 |
flex | flex 布局填充 | string | number | undefined |
order | 栅格顺序,取 0,1,2... | number | 0 |
xs | <576px 响应式栅格 | number | {span?: number, offset?: number} | undefined |
sm | ≥576px 响应式栅格 | number | {span?: number, offset?: number} | undefined |
md | ≥768px 响应式栅格 | number | {span?: number, offset?: number} | undefined |
lg | ≥992px 响应式栅格 | number | {span?: number, offset?: number} | undefined |
xl | ≥1200px 响应式栅格 | number | {span?: number, offset?: number} | undefined |
xxl | ≥1600px 响应式栅格 | number | {span?: number, offset?: number} | undefined |