Grid 栅格
如果项目中使用的是 1.x 版本的基础组件(@alifd/next),请在左侧导航顶部切换组件版本。
安装方法
- 在命令行中执行以下命令
npm install @icedesign/base@latest -S
开发指南
基本使用
此栅格系统提供了320,480,720, 990,1200,1500等几乎所有主流分辨率场景的响应规则。响应式栅格采用24列栅格体系和5分比实现,以满足2,3,4,5,6分比布局等多种情况。固定栅格采用20px宽度作为单位栅格, 推荐使用9,10,12,14,16,18,24,但同时也提供了从1到30的所有栅格,也可根据需求定制固定栅格列。响应式断点阈值为:xss(320px), xs(480px), s(720px), m(990px), l(1200px), xl(1500px)。主要使用Flex实现,对IE9-的兼容通过display:table;
实现,但IE9-下仅支持基本的响应式布局(详情请参考API和DEMO的说明)。
Grid.Row
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
prefix | 样式类名的品牌前缀 | String | 'next-' |
className | 自定义类名 | String | - |
style | 自定义内联样式 | Object | - |
children | 行内容 | ReactNode | - |
type | 布局方式 可选值:'fluid'(流体布局,仅设置最大宽度,宽度为各断点值,两侧根据分辨率情况自动留白)'fixed'(固定宽度布局)'wrap'(单行模式,列在行中宽度溢出后换行)'no-wrap'(单行模式,列在行中宽度溢出后不换行)'no-padding'(行边距以及所有列间距都为0)'across'(通栏模式, 行边距为0)'fixed'/'fluid', 'wrap'/'no-wrap', 'no-padding', 'across'可组合使用,例如: 'fixed', 'wrap', 'no-padding', 'across' | String/Array<String> | 默认布局方式为 display:flex;width:100%;,两侧有边距留白。 |
fixedWidth | 固定宽度布局,指定固定宽度值后不再受断点值影响而变动可选值:'xxs'(320px)'xs'(480px)'s'(720px)'m'(990px)'l'(1200px)'xl'(1500px) | Enum | - |
align | (不支持IE9及以下浏览器)多列垂直方向对齐方式可选值:'top'(顶部对齐)'center'(居中对齐)'bottom'(底部对齐)'baseline'(第一行文字基线对齐)'stretch'(未设置高度或设为auto,将占满整个容器的高度,另还需手动设置 width:100%) | Enum | 'stretch' |
justify | (不支持IE9及以下浏览器)行内具有多余空间时的布局方式可选值:'start'(左对齐)'center'(居中对齐)'end'(右对齐)'space-between'(两端对齐,列之间间距相等)'space-around'(每列具有相同的左右间距,行两端间距是列间距的二分之一) | Enum | 'start' |
Grid.Col
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
prefix | 样式类名的品牌前缀 | String | 'next-' |
className | 自定义类名 | String | - |
style | 自定义内联样式 | Object | - |
children | 列内容 | ReactNode | - |
span | 列宽度可选值:1, 2, 3, …, 22, 23, 24 | String/Number | - |
fixedSpan | 固定列宽度,宽度值为20 栅格数可选值:1, 2, 3, …, 28, 29, 30 | String/Number | - |
offset | (不支持IE9及以下浏览器)列偏移可选值:1, 2, 3, …, 22, 23, 24 | String/Number | - |
fixedOffset | (不支持IE9及以下浏览器)固定列偏移,宽度值为20 栅格数可选值:1, 2, 3, …, 28, 29, 30 | String/Number | - |
align | (不支持IE9及以下浏览器)多列垂直方向对齐方式,可覆盖Row的align属性可选值:'top', 'center', 'bottom', 'baseline', 'stretch' | Enum | - |
hidden | 列在不同断点下的显示与隐藏可选值:true(在所有断点下隐藏)false(在所有断点下显示)'xs'(在 xs 断点下隐藏)'xxs', 'xs', 's', 'm', 'l', 'xl'(在 xxs, xs, s, m, l, xl 断点下隐藏) | Boolean/String/Array | - |
xxs | >=320px,响应式栅格,可为栅格数(span)或一个包含栅格数(span)和偏移栅格数(offset)对象 | String/Number/Object | - |
xs | >=480px,响应式栅格,可为栅格数(span)或一个包含栅格数(span)和偏移栅格数(offset)对象 | String/Number/Object | - |
s | >=720px,响应式栅格,可为栅格数(span)或一个包含栅格数(span)和偏移栅格数(offset)对象 | String/Number/Object | - |
m | >=990px,响应式栅格,可为栅格数(span)或一个包含栅格数(span)和偏移栅格数(offset)对象 | String/Number/Object | - |
l | >=1200px,响应式栅格,可为栅格数(span)或一个包含栅格数(span)和偏移栅格数(offset)对象 | String/Number/Object | - |
xl | >=1500px,响应式栅格,可为栅格数(span)或一个包含栅格数(span)和偏移栅格数(offset)对象 | String/Number/Object | - |
代码示例
(不支持IE9及以下浏览器)使用Flex的align-items
和align-self
属性实现,在Row
上设置align
属性,可控制Row
下面所有Col
的垂直方向对齐方式:start(顶部对齐,默认),center(居中对齐),end(底部对齐),baseline(第一行文字的基线对齐),stretch(如果未设置高度或设为auto,将占满整个容器的高度);在Col
上设置align
属性,可允许它与其它列不一样的对齐方式,可覆盖Row
的align
属性。
查看源码在线预览
import { Grid } from "@icedesign/base";
const { Row, Col } = Grid;
ReactDOM.render(
<div className="demo">
<div className="demo-title">顶部对齐</div>
<Row className="demo-row" align="top">
<Col span="8">
<div
className="demo-col-inset"
style={{ height: "100px", lineHeight: "100px" }}
>
col-8
</div>
</Col>
<Col span="8">
<div
className="demo-col-inset"
style={{ height: "50px", lineHeight: "50px" }}
>
col-8
</div>
</Col>
<Col span="8">
<div
className="demo-col-inset"
style={{ height: "150px", lineHeight: "150px" }}
>
col-8
</div>
</Col>
</Row>
<div className="demo-title">居中对齐</div>
<Row className="demo-row" align="center">
<Col span="8">
<div
className="demo-col-inset"
style={{ height: "100px", lineHeight: "100px" }}
>
col-8
</div>
</Col>
<Col span="8">
<div
className="demo-col-inset"
style={{ height: "50px", lineHeight: "50px" }}
>
col-8
</div>
</Col>
<Col span="8">
<div
className="demo-col-inset"
style={{ height: "150px", lineHeight: "150px" }}
>
col-8
</div>
</Col>
</Row>
<div className="demo-title">底部对齐</div>
<Row className="demo-row" align="bottom">
<Col span="8">
<div
className="demo-col-inset"
style={{ height: "100px", lineHeight: "100px" }}
>
col-8
</div>
</Col>
<Col span="8">
<div
className="demo-col-inset"
style={{ height: "50px", lineHeight: "50px" }}
>
col-8
</div>
</Col>
<Col span="8">
<div
className="demo-col-inset"
style={{ height: "150px", lineHeight: "150px" }}
>
col-8
</div>
</Col>
</Row>
<div className="demo-title">第一行文字基线对齐</div>
<Row className="demo-row" align="baseline">
<Col span="8">
<div
className="demo-col-inset"
style={{ height: "100px", paddingTop: "20px", fontSize: "30px" }}
>
col-8
</div>
</Col>
<Col span="8">
<div
className="demo-col-inset"
style={{ height: "50px", paddingTop: "20px", fontSize: "20px" }}
>
col-8
</div>
</Col>
<Col span="8">
<div
className="demo-col-inset"
style={{ height: "150px", paddingTop: "20px", fontSize: "40px" }}
>
col-8
</div>
</Col>
</Row>
<div className="demo-title">
占满整个容器的高度(需要将width设置为100%)
</div>
<Row className="demo-row" align="stretch">
<Col span="8">
<div className="demo-col-inset" style={{ width: "100%" }}>
col-8
</div>
</Col>
<Col span="8">
<div className="demo-col-inset" style={{ width: "100%" }}>
col-8
</div>
</Col>
<Col span="8">
<div className="demo-col-inset" style={{ width: "100%" }}>
col-8
</div>
</Col>
</Row>
<div className="demo-title">单独设置列对齐方式</div>
<Row className="demo-row" align="top">
<Col span="8">
<div
className="demo-col-inset"
style={{ height: "100px", lineHeight: "100px" }}
>
col-8
</div>
</Col>
<Col span="8" align="bottom">
<div
className="demo-col-inset"
style={{ height: "50px", lineHeight: "50px" }}
>
col-8
</div>
</Col>
<Col span="8">
<div
className="demo-col-inset"
style={{ height: "150px", lineHeight: "150px" }}
>
col-8
</div>
</Col>
</Row>
</div>,
mountNode
);
.demo {
padding-top: 10px;
border: 1px solid #e9e9e9;
border-radius: 6px;
}
.demo-title {
margin-left: 20px;
}
.demo-row {
margin: 10px 0;
}
.demo-col-inset {
min-height: 30px;
border:1px solid #CCC;
border-radius: 3px;
background-color:#ECECEC;
line-height: 30px;
text-align: center;
}
默认使用flex
实现,IE9及其以下版本使用display:table;
实现。通过Col
的span
属性指定该列占24分之几的空间。Row
为栅格系统的最外层容器(行),里面包括多个Col
(列)。
查看源码在线预览
import { Grid } from "@icedesign/base";
const { Row, Col } = Grid;
ReactDOM.render(
<div className="demo">
<div className="demo-title">单列</div>
<Row className="demo-row">
<Col span="24">
<div className="demo-col-inset">col-24</div>
</Col>
</Row>
<div className="demo-title">两列</div>
<Row className="demo-row">
<Col span="12">
<div className="demo-col-inset">col-12</div>
</Col>
<Col span="12">
<div className="demo-col-inset">col-12</div>
</Col>
</Row>
<div className="demo-title">三列</div>
<Row className="demo-row">
<Col span="8">
<div className="demo-col-inset">col-8</div>
</Col>
<Col span="8">
<div className="demo-col-inset">col-8</div>
</Col>
<Col span="8">
<div className="demo-col-inset">col-8</div>
</Col>
</Row>
<div className="demo-title">四列</div>
<Row className="demo-row">
<Col span="6">
<div className="demo-col-inset">col-6</div>
</Col>
<Col span="6">
<div className="demo-col-inset">col-6</div>
</Col>
<Col span="6">
<div className="demo-col-inset">col-6</div>
</Col>
<Col span="6">
<div className="demo-col-inset">col-6</div>
</Col>
</Row>
<div className="demo-title">五列</div>
<Row className="demo-row">
<Col span="1p5">
<div className="demo-col-inset">col-1p5</div>
</Col>
<Col span="1p5">
<div className="demo-col-inset">col-1p5</div>
</Col>
<Col span="1p5">
<div className="demo-col-inset">col-1p5</div>
</Col>
<Col span="1p5">
<div className="demo-col-inset">col-1p5</div>
</Col>
<Col span="1p5">
<div className="demo-col-inset">col-1p5</div>
</Col>
</Row>
<div className="demo-title">六列</div>
<Row className="demo-row">
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
</Row>
</div>,
mountNode
);
.demo {
padding-top: 10px;
border: 1px solid #e9e9e9;
border-radius: 6px;
}
.demo-title {
margin-left: 20px;
}
.demo-row {
margin: 10px 0;
}
.demo-col-inset {
min-height: 30px;
border:1px solid #CCC;
border-radius: 3px;
background-color:#ECECEC;
line-height: 30px;
text-align: center;
}
提示类似Bootstrap的响应式设计,预设6个响应尺寸:xxs(320px), xs(480px), s(720px), m(990px), l(1200px), xl(1500px)。
查看源码在线预览
import { Grid, dom } from "@icedesign/base";
const { Row, Col } = Grid;
const { events } = dom;
const spans = [
{ xs: 12, s: 8, m: 6 },
{ xs: 6, s: 8, m: 6 },
{ xs: 6, s: 8, m: 12 }
];
const breakpoints = {
xs: 480,
s: 720,
m: 990
};
class Demo extends React.Component {
componentDidMount() {
const row = ReactDOM.findDOMNode(this.refs.row);
const cols = [];
for (let i = 0; i < row.children.length; i++) {
cols.push(row.children[i]);
}
this.handleResize = () => {
let point = "";
const innerWidth =
window.innerWidth ||
document.documentElement.clientWidth ||
document.body.clientWidth;
const keys = Object.keys(breakpoints);
for (let i = 0; i < keys.length; i++) {
const width = breakpoints[keys[i]];
const nextWidth = breakpoints[keys[i + 1]];
if (innerWidth > width && (innerWidth < nextWidth || !nextWidth)) {
point = keys[i];
break;
}
}
if (point) {
cols.forEach((col, index) => {
const colInset = col.children[0];
colInset.innerHTML = `col-${spans[index][point]}`;
});
}
};
events.on(window, "resize", this.handleResize);
this.handleResize();
}
componentWillUnmount() {
events.off(window, "resize", this.handleResize);
}
render() {
return (
<div className="demo">
<div className="demo-title">调整浏览器宽度查看各列所占栅格数变化</div>
<Row ref="row" className="demo-row">
{spans.map((span, index) => (
<Col key={index} {...span}>
<div className="demo-col-inset" />
</Col>
))}
</Row>
</div>
);
}
}
ReactDOM.render(<Demo />, mountNode);
.demo {
padding-top: 10px;
border: 1px solid #e9e9e9;
border-radius: 6px;
}
.demo-title {
margin-left: 20px;
}
.demo-row {
margin: 10px 0;
}
.demo-col-inset {
min-height: 30px;
border:1px solid #CCC;
border-radius: 3px;
background-color:#ECECEC;
line-height: 30px;
text-align: center;
}
基础栅格宽度为20px
,可用栅格为1到30,其宽度值为20 * 栅格数。
查看源码在线预览
import { Grid } from "@icedesign/base";
const { Row, Col } = Grid;
ReactDOM.render(
<div className="demo">
<Row className="demo-row">
<Col fixedSpan="10">
<div className="demo-col-inset">col-fixed-10</div>
</Col>
<Col fixedSpan="18">
<div className="demo-col-inset">col-fixed-18</div>
</Col>
<Col>
<div className="demo-col-inset">col</div>
</Col>
</Row>
</div>,
mountNode
);
.demo {
padding-top: 10px;
border: 1px solid #e9e9e9;
border-radius: 6px;
}
.demo-title {
margin-left: 20px;
}
.demo-row {
margin: 10px 0;
}
.demo-col-inset {
min-height: 30px;
border:1px solid #CCC;
border-radius: 3px;
background-color:#ECECEC;
line-height: 30px;
text-align: center;
}
提供了强大的响应式的显示与隐藏功能,支持在不同断点下的显示与隐藏。
查看源码在线预览
import { Grid } from "@icedesign/base";
const { Row, Col } = Grid;
ReactDOM.render(
<div className="demo">
<div className="demo-title">
在所有断点下隐藏列,调整浏览器宽度查看各列隐藏还是显示
</div>
<Row className="demo-row">
<Col span="8" hidden>
<div className="demo-col-inset">col-8</div>
</Col>
<Col span="16" hidden>
<div className="demo-col-inset">col-16</div>
</Col>
</Row>
<div className="demo-title">
在某断点下(m)隐藏列,调整浏览器宽度查看各列隐藏还是显示
</div>
<Row className="demo-row">
<Col span="8" hidden="m">
<div className="demo-col-inset">col-8</div>
</Col>
<Col span="16" hidden="m">
<div className="demo-col-inset">col-16</div>
</Col>
</Row>
<div className="demo-title">
在部分断点下(m, l, xl)隐藏列,调整浏览器宽度查看各列隐藏还是显示
</div>
<Row className="demo-row">
<Col span="8" hidden={["m", "l", "xl"]}>
<div className="demo-col-inset">col-8</div>
</Col>
<Col span="16" hidden={["m", "l", "xl"]}>
<div className="demo-col-inset">col-16</div>
</Col>
</Row>
</div>,
mountNode
);
.demo {
padding-top: 10px;
border: 1px solid #e9e9e9;
border-radius: 6px;
}
.demo-title {
margin-left: 20px;
}
.demo-row {
margin: 10px 0;
}
.demo-col-inset {
min-height: 30px;
border:1px solid #CCC;
border-radius: 3px;
background-color:#ECECEC;
line-height: 30px;
text-align: center;
}
(不支持IE9及以下浏览器)使用Flex的justify-content
属性实现行内多列水平方向对齐方式:start(左对齐,默认),center(居中对齐),end(右对齐),space-between(两端对齐,项目之间的间隔都相),space-around(两侧的间隔相等,列之间的间隔比列与边框的间隔大一倍)。
查看源码在线预览
import { Grid } from "@icedesign/base";
const { Row, Col } = Grid;
ReactDOM.render(
<div className="demo">
<div className="demo-title">左对齐</div>
<Row className="demo-row" justify="start">
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
</Row>
<div className="demo-title">居中对齐</div>
<Row className="demo-row" justify="center">
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
</Row>
<div className="demo-title">右对齐</div>
<Row className="demo-row" justify="end">
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
</Row>
<div className="demo-title">两端对齐,列之间的间隔都相等</div>
<Row className="demo-row" justify="space-between">
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
</Row>
<div className="demo-title">
列两侧的间隔相等,列之间的间隔比列与边框的间隔大一倍
</div>
<Row className="demo-row" justify="space-around">
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
<Col span="4">
<div className="demo-col-inset">col-4</div>
</Col>
</Row>
</div>,
mountNode
);
.demo {
padding-top: 10px;
border: 1px solid #e9e9e9;
border-radius: 6px;
}
.demo-title {
margin-left: 20px;
}
.demo-row {
margin: 10px 0;
}
.demo-col-inset {
min-height: 30px;
border:1px solid #CCC;
border-radius: 3px;
background-color:#ECECEC;
line-height: 30px;
text-align: center;
}
查看源码在线预览
import { Grid } from "@icedesign/base";
const { Row, Col } = Grid;
ReactDOM.render(
<div className="demo">
<div className="demo-title">两列布局,左列固定,右列自适应</div>
<Row className="demo-row">
<Col fixedSpan="16">
<div className="demo-col-inset">col-fixed-16</div>
</Col>
<Col>
<div className="demo-col-inset">col</div>
</Col>
</Row>
<div className="demo-title">两列布局,右列固定,左列自适应</div>
<Row className="demo-row">
<Col>
<div className="demo-col-inset">col</div>
</Col>
<Col fixedSpan="16">
<div className="demo-col-inset">col-fixed-16</div>
</Col>
</Row>
<div className="demo-title">三列布局,左列右列固定,中间自适应</div>
<Row className="demo-row">
<Col fixedSpan="8">
<div className="demo-col-inset">col-fixed-8</div>
</Col>
<Col>
<div className="demo-col-inset">col</div>
</Col>
<Col fixedSpan="8">
<div className="demo-col-inset">col-fixed-8</div>
</Col>
</Row>
</div>,
mountNode
);
.demo {
padding-top: 10px;
border: 1px solid #e9e9e9;
border-radius: 6px;
}
.demo-title {
margin-left: 20px;
}
.demo-row {
margin: 10px 0;
}
.demo-col-inset {
min-height: 30px;
border:1px solid #CCC;
border-radius: 3px;
background-color:#ECECEC;
line-height: 30px;
text-align: center;
}
Col
下也可嵌套Row
,以完成更细致的布局,如果想保持不同嵌套的Row
下的Col
间间距相等,请设置Row
的type
为across
,即通栏模式,或自己设置样式,将Row
的左右padding设置为0。
查看源码在线预览
import { Grid } from "@icedesign/base";
const { Row, Col } = Grid;
ReactDOM.render(
<div className="demo">
<Row className="demo-row">
<Col span="10">
<Row type="across">
<Col span="6">
<div className="demo-col-inset">col-10-6</div>
</Col>
<Col span="18">
<div className="demo-col-inset">col-10-18</div>
</Col>
</Row>
</Col>
<Col span="14">
<Row type="across">
<Col span="18">
<div className="demo-col-inset">col-14-18</div>
</Col>
<Col span="6">
<div className="demo-col-inset">col-14-6</div>
</Col>
</Row>
</Col>
</Row>
</div>,
mountNode
);
.demo {
padding-top: 10px;
border: 1px solid #e9e9e9;
border-radius: 6px;
}
.demo-title {
margin-left: 20px;
}
.demo-row {
margin: 10px 0;
}
.demo-col-inset {
min-height: 30px;
border:1px solid #CCC;
border-radius: 3px;
background-color:#ECECEC;
line-height: 30px;
text-align: center;
}
(不支持IE9及以下浏览器)列可以向右偏移一定的列数, 偏移的列数和固定栅格列数定义相同.
查看源码在线预览
import { Grid } from "@icedesign/base";
const { Row, Col } = Grid;
ReactDOM.render(
<div className="demo">
<div className="demo-title">常规偏移,可设置offset的值从0到23</div>
<Row className="demo-row">
<Col fixedOffset="0">
<div className="demo-col-inset">offset-fixed-0</div>
</Col>
</Row>
<Row className="demo-row">
<Col fixedOffset="4">
<div className="demo-col-inset">offset-fixed-4</div>
</Col>
</Row>
<Row className="demo-row">
<Col fixedOffset="8">
<div className="demo-col-inset">offset-fixed-8</div>
</Col>
</Row>
<Row className="demo-row">
<Col fixedOffset="12">
<div className="demo-col-inset">offset-fixed-12</div>
</Col>
</Row>
<div className="demo-title">自适应偏移</div>
<Row className="demo-row">
<Col>
<div className="demo-col-inset">col</div>
</Col>
<Col fixedOffset="12">
<div className="demo-col-inset">offset-fixed-12</div>
</Col>
</Row>
</div>,
mountNode
);
.demo {
padding-top: 10px;
border: 1px solid #e9e9e9;
border-radius: 6px;
}
.demo-title {
margin-left: 20px;
}
.demo-row {
margin: 10px 0;
}
.demo-col-inset {
min-height: 30px;
border:1px solid #CCC;
border-radius: 3px;
background-color:#ECECEC;
line-height: 30px;
text-align: center;
}
(不支持IE9及以下浏览器)列可以向右偏移一定的列数,偏移的列数和流式布局栅格列数定义相同。
查看源码在线预览
import { Grid } from "@icedesign/base";
const { Row, Col } = Grid;
ReactDOM.render(
<div className="demo">
<div className="demo-title">常规偏移,可设置offset的值从0到30</div>
<Row className="demo-row">
<Col offset="0">
<div className="demo-col-inset">offset-fixed-0</div>
</Col>
</Row>
<Row className="demo-row">
<Col offset="4">
<div className="demo-col-inset">offset-fixed-4</div>
</Col>
</Row>
<Row className="demo-row">
<Col offset="8">
<div className="demo-col-inset">offset-fixed-8</div>
</Col>
</Row>
<Row className="demo-row">
<Col offset="12">
<div className="demo-col-inset">offset-fixed-12</div>
</Col>
</Row>
<div className="demo-title">自适应偏移</div>
<Row className="demo-row">
<Col>
<div className="demo-col-inset">col</div>
</Col>
<Col offset="12">
<div className="demo-col-inset">offset-12</div>
</Col>
</Row>
</div>,
mountNode
);
.demo {
padding-top: 10px;
border: 1px solid #e9e9e9;
border-radius: 6px;
}
.demo-title {
margin-left: 20px;
}
.demo-row {
margin: 10px 0;
}
.demo-col-inset {
min-height: 30px;
border:1px solid #CCC;
border-radius: 3px;
background-color:#ECECEC;
line-height: 30px;
text-align: center;
}
Note: 未来的@alife/grid@1.x
中的默认布局即是fluid
布局,并且去除最大宽度为1500px的限制。across
为通拦模式,行边距为0。no-padding
行边距以及所有列间距都为0。no-wrap
为单行模式, 列在行中宽度溢出后不换行。(IE9及以下版本不支持)wrap
为单行模式, 列在行中宽度溢出后换行。(IE9及以下版本不支持)fixed
为固定宽度布局,宽度为各断点值,两侧根据分辨率情况自动留白。fluid
也为流式布局,行的最大宽度随浏览器宽度变化而变化,直到最大宽度1500px。默认布局为流式布局,行的最大宽度随浏览器宽度变化而变化。
查看源码在线预览
import { Grid } from "@icedesign/base";
const { Row, Col } = Grid;
ReactDOM.render(
<div className="demo">
<div className="demo-title">默认布局</div>
<Row className="demo-row">
<Col span="8">
<div className="demo-col-inset" />
</Col>
<Col span="8">
<div className="demo-col-inset" />
</Col>
<Col span="8">
<div className="demo-col-inset" />
</Col>
</Row>
<div className="demo-title">流式布局(fluid)</div>
<Row type="fluid" className="demo-row">
<Col span="8">
<div className="demo-col-inset" />
</Col>
<Col span="8">
<div className="demo-col-inset" />
</Col>
<Col span="8">
<div className="demo-col-inset" />
</Col>
</Row>
<div className="demo-title">固定宽度布局(fixed)</div>
<Row type="fixed" className="demo-row">
<Col span="8">
<div className="demo-col-inset" />
</Col>
<Col span="8">
<div className="demo-col-inset" />
</Col>
<Col span="8">
<div className="demo-col-inset" />
</Col>
</Row>
<div className="demo-title">固定宽度布局(fixed),指定固定宽度</div>
<Row type="fixed" fixedWidth="s" className="demo-row">
<Col>
<div className="demo-col-inset">720px</div>
</Col>
<Col>
<div className="demo-col-inset">720px</div>
</Col>
<Col>
<div className="demo-col-inset">720px</div>
</Col>
</Row>
<div className="demo-title">单行模式(wrap),列在行中宽度溢出后换行</div>
<Row type="wrap" className="demo-row">
<Col span="10">
<div className="demo-col-inset">col-10</div>
</Col>
<Col span="10">
<div className="demo-col-inset">col-10</div>
</Col>
<Col span="6">
<div className="demo-col-inset">col-6</div>
</Col>
</Row>
<div className="demo-title">
单行模式(no-wrap),列在行中宽度溢出后不换行
</div>
<Row type="no-wrap" className="demo-row">
<Col span="10">
<div className="demo-col-inset">col-10</div>
</Col>
<Col span="10">
<div className="demo-col-inset">col-10</div>
</Col>
<Col span="6">
<div className="demo-col-inset">col-6</div>
</Col>
</Row>
<div className="demo-title">无间距布局(no-padding)</div>
<Row type="no-padding" className="demo-row">
<Col span="10">
<div className="demo-col-inset">col-10</div>
</Col>
<Col span="8">
<div className="demo-col-inset">col-8</div>
</Col>
<Col span="6">
<div className="demo-col-inset">col-6</div>
</Col>
</Row>
<div className="demo-title">通栏布局(across)</div>
<Row type="across" className="demo-row">
<Col span="10">
<div className="demo-col-inset">col-10</div>
</Col>
<Col span="8">
<div className="demo-col-inset">col-8</div>
</Col>
<Col span="6">
<div className="demo-col-inset">col-6</div>
</Col>
</Row>
<div className="demo-title">多种布局模式组合使用(fixed, no-padding)</div>
<Row type={["fixed", "no-padding"]} fixedWidth="s" className="demo-row">
<Col span="12">
<div className="demo-col-inset">col-12</div>
</Col>
<Col span="6">
<div className="demo-col-inset">col-6</div>
</Col>
<Col span="6">
<div className="demo-col-inset">col-6</div>
</Col>
</Row>
<div className="demo-title">
多种布局模式组合使用(fluid, no-wrap, no-padding)
</div>
<Row type={["fluid", "no-wrap", "no-padding"]} className="demo-row">
<Col span="12">
<div className="demo-col-inset">col-12</div>
</Col>
<Col span="8">
<div className="demo-col-inset">col-8</div>
</Col>
<Col span="6">
<div className="demo-col-inset">col-6</div>
</Col>
</Row>
</div>,
mountNode
);
.demo {
padding-top: 10px;
border: 1px solid #e9e9e9;
border-radius: 6px;
}
.demo-title {
margin-left: 20px;
}
.demo-row {
margin: 10px 0;
}
.demo-col-inset {
min-height: 30px;
border:1px solid #CCC;
border-radius: 3px;
background-color:#ECECEC;
line-height: 30px;
text-align: center;
}