非常教程

iView UI参考手册

组件布局

Grid 栅格

概述

Grid 栅格

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

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

  • 使用row在水平方向创建一行
  • 将一组col插入在row
  • 在每个col中,键入自己的内容
  • 通过设置colspan参数,指定跨越的范围,其范围是1到24
  • 每个row中的col总和应该为24

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

代码示例

Grid 栅格

Grid 栅格

Grid 栅格

<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>

Grid 栅格

<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>

Grid 栅格

<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>

Grid 栅格

<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>

Grid 栅格

<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>

Grid 栅格

<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>

Grid 栅格

<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,左右平分

Number

0

type

布局模式,可选值为flex或不选,在现代浏览器下有效

String

-

align

flex 布局下的垂直对齐方式,可选值为top、middle、bottom

String

-

justify

flex 布局下的水平排列方式,可选值为start、end、center、space-around、space-between

String

-

class-name

自定义的class名称

String

-

Col props

属性

说明

类型

默认值

span

栅格的占位格数,可选值为0~24的整数,为 0 时,相当于display:none

Number | 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

-

iView UI

iView 是一套基于 Vue.js 的开源 UI 组件库,主要服务于 PC 界面的中后台产品

iView UI目录

1.指南
2.组件
3.组件基础
4.组件布局