Grid 栅格

如果项目中使用的是 0.x 版本的基础组件(@icedesign/base, @ali/ice, @alife/next),请在左侧导航顶部切换组件版本。

安装方法

  1. 在命令行中执行以下命令npm install @alifd/next@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)。 API 和 DEMO 的说明)。

无障碍

默认 <Row><Col> 会加上 role="row"role="gridcell", 但是为了完美的无障碍实现, 开发者还应该在外部容器加上 role="grid"。示例代码如下:

  1. <div role="grid">
  2. <Row><Col span={6}>1</Col><Col span={6}>2</Col><Col span={6}>3</Col><Col span={6}>4</Col></Row>
  3. <Row><Col span={6} offset={6}>1</Col><Col span={6} offset={6}>2</Col></Row>
  4. </div>

API

Grid.Row

参数说明类型默认值
children行内容ReactNode-
gutter列间隔String/Number0
wrap列在行中宽度溢出后是否换行Booleanfalse
fixed行在某一断点下宽度是否保持不变(默认行宽度随视口变化而变化)Booleanfalse
fixedWidth固定行的宽度为某一断点的宽度,不受视口影响而变动可选值:'xxs'(320px)'xs'(480px)'s'(720px)'m'(990px)'l'(1200px)'xl'(1500px)Enum-
align(不支持IE9浏览器)多列垂直方向对齐方式可选值:'top'(顶部对齐)'center'(居中对齐)'bottom'(底部对齐)'baseline'(按第一行文字基线对齐)'stretch'(未设置高度或设为 auto,将占满整个容器的高度)Enum-
justify(不支持IE9浏览器)行内具有多余空间时的布局方式可选值:'start'(左对齐)'center'(居中对齐)'end'(右对齐)'space-between'(两端对齐,列之间间距相等)'space-around'(每列具有相同的左右间距,行两端间距是列间距的二分之一)Enum-
hidden行在不同断点下的显示与隐藏可选值:true(在所有断点下隐藏)false(在所有断点下显示)'xs'(在 xs 断点下隐藏)'xxs', 'xs', 's', 'm', 'l', 'xl'(在 xxs, xs, s, m, l, xl 断点下隐藏)Boolean/String/Array-
component指定以何种元素渲染该节点- 默认为 'div'String/Function'div'

Grid.Col

参数说明类型默认值
children列内容ReactNode-
span列宽度可选值:1, 2, 3, …, 22, 23, 24String/Number-
fixedSpan固定列宽度,宽度值为20 栅格数可选值:1, 2, 3, …, 28, 29, 30String/Number-
offset(不支持IE9浏览器)列偏移可选值:1, 2, 3, …, 22, 23, 24String/Number-
fixedOffset(不支持IE9浏览器)固定列偏移,宽度值为20 栅格数可选值:1, 2, 3, …, 28, 29, 30String/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-
component指定以何种元素渲染该节点,默认为 'div'String/Function'div'

代码示例

基础布局

通过 Colspan 属性指定该列宽度占整行宽度24分之几或5分之几。

Grid 栅格 - 图1

查看源码在线预览

  1. import { Grid } from '@alifd/next';
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="basic-demo">
  5. <div className="demo-title">One</div>
  6. <Row>
  7. <Col span="24">col-24</Col>
  8. </Row>
  9. <div className="demo-title">Two</div>
  10. <Row>
  11. <Col span="12">col-12</Col>
  12. <Col span="12">col-12</Col>
  13. </Row>
  14. <div className="demo-title">Three</div>
  15. <Row>
  16. <Col span="8">col-8</Col>
  17. <Col span="8">col-8</Col>
  18. <Col span="8">col-8</Col>
  19. </Row>
  20. <div className="demo-title">Four</div>
  21. <Row>
  22. <Col span="6">col-6</Col>
  23. <Col span="6">col-6</Col>
  24. <Col span="6">col-6</Col>
  25. <Col span="6">col-6</Col>
  26. </Row>
  27. <div className="demo-title">Five</div>
  28. <Row>
  29. <Col span="1p5">col-1p5</Col>
  30. <Col span="1p5">col-1p5</Col>
  31. <Col span="1p5">col-1p5</Col>
  32. <Col span="1p5">col-1p5</Col>
  33. <Col span="1p5">col-1p5</Col>
  34. </Row>
  35. <div className="demo-title">Six</div>
  36. <Row>
  37. <Col span="4">col-4</Col>
  38. <Col span="4">col-4</Col>
  39. <Col span="4">col-4</Col>
  40. <Col span="4">col-4</Col>
  41. <Col span="4">col-4</Col>
  42. <Col span="4">col-4</Col>
  43. </Row>
  44. </div>, mountNode);
  1. .basic-demo .demo-title {
  2. margin-left: 20px;
  3. }
  4. .basic-demo .next-row {
  5. margin: 10px 0;
  6. }
  7. .basic-demo .next-col {
  8. border:1px solid #CCC;
  9. border-radius: 3px;
  10. background-color:#ECECEC;
  11. height: 30px;
  12. line-height: 30px;
  13. text-align: center;
  14. }

固定宽度列

通过 ColfixedSpan 属性来指定某列为固定宽度列,其宽度的计算方式为 20 * fixedSpan。

Grid 栅格 - 图2

查看源码在线预览

  1. import { Grid } from '@alifd/next';
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="mixin-demo">
  5. <div className="demo-title">Two-column layout, left column fixed, right column adaptive</div>
  6. <Row>
  7. <Col fixedSpan="16">col-fixed-16</Col>
  8. <Col>col</Col>
  9. </Row>
  10. <div className="demo-title">Two-column layout, right column fixed, left column adaptive</div>
  11. <Row>
  12. <Col>col</Col>
  13. <Col fixedSpan="16">col-fixed-16</Col>
  14. </Row>
  15. <div className="demo-title">Three-column layout, left column and right column fixed, middle column adaptive</div>
  16. <Row>
  17. <Col fixedSpan="8">col-fixed-8</Col>
  18. <Col>col</Col>
  19. <Col fixedSpan="8">col-fixed-8</Col>
  20. </Row>
  21. </div>, mountNode);
  1. .mixin-demo .demo-title {
  2. margin-left: 20px;
  3. }
  4. .mixin-demo .next-row {
  5. margin: 10px 0;
  6. }
  7. .mixin-demo .next-col {
  8. border:1px solid #CCC;
  9. border-radius: 3px;
  10. background-color:#ECECEC;
  11. height: 30px;
  12. line-height: 30px;
  13. text-align: center;
  14. }

列间距

列与列间距默认为0,可以通过设置 Rowgutter 属性来改变列间距。

Grid 栅格 - 图3

查看源码在线预览

  1. import { Range, Grid } from '@alifd/next';
  2. const { Row, Col } = Grid;
  3. class Demo extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. this.state = {
  7. gutter: 0
  8. };
  9. this.handleChange = this.handleChange.bind(this);
  10. }
  11. handleChange(gutter) {
  12. this.setState({
  13. gutter
  14. });
  15. }
  16. render() {
  17. const { gutter } = this.state;
  18. return (
  19. <div className="gutter-demo">
  20. <Range value={gutter} onChange={this.handleChange} marks={4} step={4} max={16} hasTip={false} style={{ width: '400px', marginLeft: '20px', marginTop: '30px' }} />
  21. <Row gutter={gutter}>
  22. <Col span="6"><div className="demo-col-inset">col-6</div></Col>
  23. <Col span="6"><div className="demo-col-inset">col-6</div></Col>
  24. <Col span="6"><div className="demo-col-inset">col-6</div></Col>
  25. <Col span="6"><div className="demo-col-inset">col-6</div></Col>
  26. </Row>
  27. </div>
  28. );
  29. }
  30. }
  31. ReactDOM.render(<Demo />, mountNode);
  1. .gutter-demo .demo-title {
  2. margin-left: 20px;
  3. }
  4. .gutter-demo .next-row {
  5. margin: 10px 0;
  6. }
  7. .gutter-demo .demo-col-inset {
  8. border:1px solid #CCC;
  9. border-radius: 3px;
  10. background-color:#ECECEC;
  11. height: 30px;
  12. line-height: 30px;
  13. text-align: center;
  14. }

溢出后是否换行

(不支持 IE9 浏览器)默认列在行中宽度溢出后不会换行,如果想自动换行,请为 Row 设置 wrap 为 true。

Grid 栅格 - 图4

查看源码在线预览

  1. import { Grid } from '@alifd/next';
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="wrap-demo">
  5. <div className="demo-title">No wrap</div>
  6. <Row>
  7. <Col span="6">col-6</Col>
  8. <Col span="6">col-6</Col>
  9. <Col span="6">col-6</Col>
  10. <Col span="8">col-8</Col>
  11. </Row>
  12. <div className="demo-title">Wrap</div>
  13. <Row wrap>
  14. <Col span="6">col-6</Col>
  15. <Col span="6">col-6</Col>
  16. <Col span="6">col-6</Col>
  17. <Col span="8">col-8</Col>
  18. </Row>
  19. </div>, mountNode);
  1. .wrap-demo .demo-title {
  2. margin-left: 20px;
  3. }
  4. .wrap-demo .next-row {
  5. margin: 10px 0;
  6. }
  7. .wrap-demo .next-col {
  8. border:1px solid #CCC;
  9. border-radius: 3px;
  10. background-color:#ECECEC;
  11. height: 30px;
  12. line-height: 30px;
  13. text-align: center;
  14. }

嵌套布局

Col 下也可嵌套 Row,以完成更细致的布局。

Grid 栅格 - 图5

查看源码在线预览

  1. import { Grid } from '@alifd/next';
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="nest-demo">
  5. <Row className="demo-row">
  6. <Col span="10">
  7. <Row>
  8. <Col span="6">
  9. <div className="demo-col-inset">col-10-6</div>
  10. </Col>
  11. <Col span="18">
  12. <div className="demo-col-inset">col-10-18</div>
  13. </Col>
  14. </Row>
  15. </Col>
  16. <Col span="14">
  17. <Row>
  18. <Col span="18">
  19. <div className="demo-col-inset">col-14-18</div>
  20. </Col>
  21. <Col span="6">
  22. <div className="demo-col-inset">col-14-6</div>
  23. </Col>
  24. </Row>
  25. </Col>
  26. </Row>
  27. </div>, mountNode);
  1. .nest-demo .demo-title {
  2. margin-left: 20px;
  3. }
  4. .nest-demo .demo-row {
  5. margin: 10px 0;
  6. }
  7. .nest-demo .demo-col-inset {
  8. border:1px solid #CCC;
  9. border-radius: 3px;
  10. background-color:#ECECEC;
  11. height: 30px;
  12. line-height: 30px;
  13. text-align: center;
  14. }

响应式布局

Grid 栅格 - 图6

查看源码在线预览

  1. import { Grid } from '@alifd/next';
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="breakpoint-demo">
  5. <div className="demo-title">Resize browser to see how each column changes</div>
  6. <Row >
  7. <Col xs={12} s={8} m={6}>Col</Col>
  8. <Col xs={6} s={8} m={6}>Col</Col>
  9. <Col xs={6} s={8} m={12}>Col</Col>
  10. </Row>
  11. </div>, mountNode);
  1. .breakpoint-demo .demo-title {
  2. margin-left: 20px;
  3. }
  4. .breakpoint-demo .next-row {
  5. margin: 10px 0;
  6. }
  7. .breakpoint-demo .next-col {
  8. border:1px solid #CCC;
  9. border-radius: 3px;
  10. background-color:#ECECEC;
  11. height: 30px;
  12. line-height: 30px;
  13. text-align: center;
  14. }

显示与隐藏

提供了强大的响应式的显示与隐藏功能,支持在不同断点下的显示与隐藏。

Grid 栅格 - 图7

查看源码在线预览

  1. import { Grid } from '@alifd/next';
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="hidden-demo">
  5. <div className="demo-title">Hide columns under all breakpoints, resize browser to see if the second column is hidden or shown</div>
  6. <Row>
  7. <Col span="8">col-8</Col>
  8. <Col span="16" hidden>col-16</Col>
  9. </Row>
  10. <div className="demo-title">Hide columns under a breakpoint such as xs, resize browser to see if the second column is hidden or shown</div>
  11. <Row>
  12. <Col span="8">col-8</Col>
  13. <Col span="16" hidden="xs">col-16</Col>
  14. </Row>
  15. <div className="demo-title">Hide columns under some breakpoints such as xs and s, resize browser to see if the second column is hidden or shown</div>
  16. <Row>
  17. <Col span="8">col-8</Col>
  18. <Col span="16" hidden={['xs', 's']}>col-16</Col>
  19. </Row>
  20. </div>, mountNode);
  1. .hidden-demo .demo-title {
  2. margin-left: 20px;
  3. }
  4. .hidden-demo .next-row {
  5. margin: 10px 0;
  6. }
  7. .hidden-demo .next-col {
  8. border:1px solid #CCC;
  9. border-radius: 3px;
  10. background-color:#ECECEC;
  11. height: 30px;
  12. line-height: 30px;
  13. text-align: center;
  14. }

设置行的宽度

默认 Row 的宽度被设置为100%,可以通过设置 fixed 属性为 true,来让 Row 的宽度不立刻随着是视口大小变动而变动,而是在某个断点下维持固定的宽度,也可以通过设置 fixedWidth 属性为某一断点值,从而固定 Row 的宽度,不再随着视口大小变动而变动。

Grid 栅格 - 图8

查看源码在线预览

  1. import { Grid } from '@alifd/next';
  2. const { Row, Col } = Grid;
  3. const breakpoints = {
  4. xxs: 320,
  5. xs: 480,
  6. s: 720,
  7. m: 990,
  8. l: 1200,
  9. xl: 1500
  10. };
  11. class Demo extends React.Component {
  12. componentDidMount() {
  13. const row = ReactDOM.findDOMNode(this.refs.fixCol);
  14. this.handleResize = () => {
  15. let point = '';
  16. const innerWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  17. const keys = Object.keys(breakpoints);
  18. for (let i = 0; i < keys.length; i++) {
  19. const width = breakpoints[keys[i]];
  20. const nextWidth = breakpoints[keys[i + 1]];
  21. if (innerWidth > width && (innerWidth < nextWidth || !nextWidth)) {
  22. point = keys[i];
  23. break;
  24. }
  25. }
  26. if (point) {
  27. row.innerHTML = `${breakpoints[point]}px`;
  28. }
  29. };
  30. window.addEventListener('resize', this.handleResize);
  31. this.handleResize();
  32. }
  33. componentWillUnmount() {
  34. window.removeListener('resize', this.handleResize);
  35. }
  36. render() {
  37. return (
  38. <div className="type-demo">
  39. <div className="demo-title">Default</div>
  40. <Row>
  41. <Col>100%</Col>
  42. </Row>
  43. <div className="demo-title">Set fixed to true</div>
  44. <Row ref="fixedRow" fixed>
  45. <Col ref="fixCol" />
  46. </Row>
  47. <div className="demo-title">Set fixedWidth to 's'</div>
  48. <Row fixedWidth="s">
  49. <Col>720px</Col>
  50. </Row>
  51. </div>
  52. );
  53. }
  54. }
  55. ReactDOM.render(<Demo />, mountNode);
  1. .type-demo .demo-title {
  2. margin-left: 20px;
  3. }
  4. .type-demo .next-row {
  5. margin: 10px 0;
  6. }
  7. .type-demo .next-col {
  8. border:1px solid #CCC;
  9. border-radius: 3px;
  10. background-color:#ECECEC;
  11. height: 30px;
  12. line-height: 30px;
  13. text-align: center;
  14. }

偏移

(不支持 IE9 浏览器)列可以向右偏移一定距离,该距离的计算方式和列所占宽度计算方式相同。

Grid 栅格 - 图9

查看源码在线预览

  1. import { Grid } from '@alifd/next';
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="offset-demo">
  5. <div className="demo-title">Normal offset, set offset from 1 to 24</div>
  6. <Row>
  7. <Col offset="0">offset-0</Col>
  8. </Row>
  9. <Row>
  10. <Col offset="4">offset-4</Col>
  11. </Row>
  12. <Row>
  13. <Col offset="8">offset-8</Col>
  14. </Row>
  15. <Row>
  16. <Col offset="12">offset-12</Col>
  17. </Row>
  18. <div className="demo-title">Adaptive offset</div>
  19. <Row>
  20. <Col>col</Col>
  21. <Col offset="12">offset-12</Col>
  22. </Row>
  23. </div>,
  24. mountNode
  25. );
  1. .offset-demo .demo-title {
  2. margin-left: 20px;
  3. }
  4. .offset-demo .next-row {
  5. margin: 10px 0;
  6. }
  7. .offset-demo .next-col {
  8. border:1px solid #CCC;
  9. border-radius: 3px;
  10. background-color:#ECECEC;
  11. height: 30px;
  12. line-height: 30px;
  13. text-align: center;
  14. }

固定宽度偏移

(不支持 IE9 浏览器)列可以向右偏移一定距离,该距离的计算方式和固定宽度列的宽度相同。

Grid 栅格 - 图10

查看源码在线预览

  1. import { Grid } from '@alifd/next';
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="offset-fixed-demo">
  5. <div className="demo-title">Normal offset, set offset from 1 to 30</div>
  6. <Row>
  7. <Col fixedOffset="0">offset-fixed-0</Col>
  8. </Row>
  9. <Row>
  10. <Col fixedOffset="4">offset-fixed-4</Col>
  11. </Row>
  12. <Row>
  13. <Col fixedOffset="8">offset-fixed-8</Col>
  14. </Row>
  15. <Row>
  16. <Col fixedOffset="12">offset-fixed-12</Col>
  17. </Row>
  18. <div className="demo-title">Adaptive offset</div>
  19. <Row>
  20. <Col>col</Col>
  21. <Col fixedOffset="12">offset-fixed-12</Col>
  22. </Row>
  23. </div>, mountNode
  24. );
  1. .offset-fixed-demo .demo-title {
  2. margin-left: 20px;
  3. }
  4. .offset-fixed-demo .next-row {
  5. margin: 10px 0;
  6. }
  7. .offset-fixed-demo .next-col {
  8. border:1px solid #CCC;
  9. border-radius: 3px;
  10. background-color:#ECECEC;
  11. height: 30px;
  12. line-height: 30px;
  13. text-align: center;
  14. }

多列垂直方向对齐方式

(不支持 IE9 浏览器)基于 Flex 的 align-items 和 align-self 属性实现,在 Row 上设置 align 属性,即可控制 Row 下面所有 Col 的垂直方向对齐方式:top(顶部对齐,默认),center(居中对齐),bottom(底部对齐),baseline(第一行文字的基线对齐),stretch(如果未设置高度或设为 auto,将占满整个容器的高度);在 Col 上设置 align 属性,可允许它与其它列不一样的对齐方式,覆盖 Rowalign 属性。

Grid 栅格 - 图11

查看源码在线预览

import { Grid } from '@alifd/next';

const { Row, Col } = Grid;

ReactDOM.render(
    <div className="align-demo">
        <div className="demo-title">top</div>
        <Row align="top">
            <Col span="8" style={{ height: '100px', lineHeight: '100px' }}>col-8</Col>
            <Col span="8" style={{ height: '50px', lineHeight: '50px' }}>col-8</Col>
            <Col span="8" style={{ height: '150px', lineHeight: '150px' }}>col-8</Col>
        </Row>

        <div className="demo-title">center</div>
        <Row align="center">
            <Col span="8" style={{ height: '100px', lineHeight: '100px' }}>col-8</Col>
            <Col span="8" style={{ height: '50px', lineHeight: '50px' }}>col-8</Col>
            <Col span="8" style={{ height: '150px', lineHeight: '150px' }}>col-8</Col>
        </Row>

        <div className="demo-title">bottom</div>
        <Row align="bottom">
            <Col span="8" style={{ height: '100px', lineHeight: '100px' }}>col-8</Col>
            <Col span="8" style={{ height: '50px', lineHeight: '50px' }}>col-8</Col>
            <Col span="8" style={{ height: '150px', lineHeight: '150px' }}>col-8</Col>
        </Row>

        <div className="demo-title">baseline</div>
        <Row align="baseline">
            <Col span="8" style={{ height: '100px', paddingTop: '20px', fontSize: '30px' }}>col-8</Col>
            <Col span="8" style={{ height: '50px', paddingTop: '20px', fontSize: '20px' }}>col-8</Col>
            <Col span="8" style={{ height: '150px', paddingTop: '20px', fontSize: '40px' }}>col-8</Col>
        </Row>

        <div className="demo-title">stretch</div>
        <Row align="stretch" style={{ height: '150px' }}>
            <Col span="8">col-8</Col>
            <Col span="8">col-8</Col>
            <Col span="8">col-8</Col>
        </Row>

        <div className="demo-title">override</div>
        <Row align="top">
            <Col align="bottom" span="8" style={{ height: '100px', lineHeight: '100px' }}>col-8</Col>
            <Col span="8" style={{ height: '50px', lineHeight: '50px' }}>col-8</Col>
            <Col span="8" style={{ height: '150px', lineHeight: '150px' }}>col-8</Col>
        </Row>
    </div>, mountNode);
.align-demo .demo-title {
    margin-left: 20px;
}

.align-demo .next-row {
    margin: 10px 0;
}

.align-demo .next-col {
    border:1px solid #CCC;
    border-radius: 3px;
    background-color:#ECECEC;
    line-height: 30px;
    text-align: center;
}

多列水平方向对齐方式

(不支持 IE9 浏览器)基于 Flex 的 justify-content 属性实现,在 Row 上设置 justify 属性,即可行内多列水平方向对齐方式:start(左对齐,默认),center(居中对齐),end(右对齐),space-between(两端对齐,项目之间的间隔都相),space-around(两侧的间隔相等,列之间的间隔比列与左右两端的间隔大一倍)。

Grid 栅格 - 图12

查看源码在线预览

import { Grid } from '@alifd/next';

const { Row, Col } = Grid;

ReactDOM.render(
    <div className="justify-demo">
        <div className="demo-title">start</div>
        <Row justify="start">
            <Col span="4">col-4</Col>
            <Col span="4">col-4</Col>
            <Col span="4">col-4</Col>
        </Row>

        <div className="demo-title">center</div>
        <Row justify="center">
            <Col span="4">col-4</Col>
            <Col span="4">col-4</Col>
            <Col span="4">col-4</Col>
        </Row>

        <div className="demo-title">end</div>
        <Row justify="end">
            <Col span="4">col-4</Col>
            <Col span="4">col-4</Col>
            <Col span="4">col-4</Col>
        </Row>

        <div className="demo-title">space-between</div>
        <Row justify="space-between">
            <Col span="4">col-4</Col>
            <Col span="4">col-4</Col>
            <Col span="4">col-4</Col>
        </Row>

        <div className="demo-title">space-around</div>
        <Row justify="space-around">
            <Col span="4">col-4</Col>
            <Col span="4">col-4</Col>
            <Col span="4">col-4</Col>
        </Row>
    </div>, mountNode);
.justify-demo  .demo-title {
    margin-left: 20px;
}

.justify-demo  .next-row {
    margin: 10px 0;
}

.justify-demo .next-col {
    border:1px solid #CCC;
    border-radius: 3px;
    background-color:#ECECEC;
    height: 30px;
    line-height: 30px;
    text-align: center;
}

自定义元素渲染类型

使用 component 来指定需要渲染的元素类型,默认为 div

Grid 栅格 - 图13

查看源码在线预览

import { Grid } from '@alifd/next';

const { Row, Col } = Grid;

ReactDOM.render(
    <div className="basic-demo">
        <div className="demo-title">Rendered as `ul` and `li`</div>
        <Row component="ul">
            <Col span="12" component="li">col-12</Col>
            <Col span="12" component="li">col-12</Col>
        </Row>
    </div>, mountNode);
.basic-demo ul {
    list-style: none;
    padding: 0;
}

.basic-demo .demo-title {
    margin-left: 20px;
}

.basic-demo .next-row {
    margin: 10px 0;
}

.basic-demo .next-col {
    border:1px solid #CCC;
    border-radius: 3px;
    background-color:#ECECEC;
    height: 30px;
    line-height: 30px;
    text-align: center;
}

相关区块

Grid 栅格 - 图14

暂无相关区块