Grid 栅格

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

安装方法

  1. 在命令行中执行以下命令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, 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-

代码示例

多列垂直方向对齐方式

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

Grid 栅格 - 图1

查看源码在线预览

  1. import { Grid } from "@icedesign/base";
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="demo">
  5. <div className="demo-title">顶部对齐</div>
  6. <Row className="demo-row" align="top">
  7. <Col span="8">
  8. <div
  9. className="demo-col-inset"
  10. style={{ height: "100px", lineHeight: "100px" }}
  11. >
  12. col-8
  13. </div>
  14. </Col>
  15. <Col span="8">
  16. <div
  17. className="demo-col-inset"
  18. style={{ height: "50px", lineHeight: "50px" }}
  19. >
  20. col-8
  21. </div>
  22. </Col>
  23. <Col span="8">
  24. <div
  25. className="demo-col-inset"
  26. style={{ height: "150px", lineHeight: "150px" }}
  27. >
  28. col-8
  29. </div>
  30. </Col>
  31. </Row>
  32. <div className="demo-title">居中对齐</div>
  33. <Row className="demo-row" align="center">
  34. <Col span="8">
  35. <div
  36. className="demo-col-inset"
  37. style={{ height: "100px", lineHeight: "100px" }}
  38. >
  39. col-8
  40. </div>
  41. </Col>
  42. <Col span="8">
  43. <div
  44. className="demo-col-inset"
  45. style={{ height: "50px", lineHeight: "50px" }}
  46. >
  47. col-8
  48. </div>
  49. </Col>
  50. <Col span="8">
  51. <div
  52. className="demo-col-inset"
  53. style={{ height: "150px", lineHeight: "150px" }}
  54. >
  55. col-8
  56. </div>
  57. </Col>
  58. </Row>
  59. <div className="demo-title">底部对齐</div>
  60. <Row className="demo-row" align="bottom">
  61. <Col span="8">
  62. <div
  63. className="demo-col-inset"
  64. style={{ height: "100px", lineHeight: "100px" }}
  65. >
  66. col-8
  67. </div>
  68. </Col>
  69. <Col span="8">
  70. <div
  71. className="demo-col-inset"
  72. style={{ height: "50px", lineHeight: "50px" }}
  73. >
  74. col-8
  75. </div>
  76. </Col>
  77. <Col span="8">
  78. <div
  79. className="demo-col-inset"
  80. style={{ height: "150px", lineHeight: "150px" }}
  81. >
  82. col-8
  83. </div>
  84. </Col>
  85. </Row>
  86. <div className="demo-title">第一行文字基线对齐</div>
  87. <Row className="demo-row" align="baseline">
  88. <Col span="8">
  89. <div
  90. className="demo-col-inset"
  91. style={{ height: "100px", paddingTop: "20px", fontSize: "30px" }}
  92. >
  93. col-8
  94. </div>
  95. </Col>
  96. <Col span="8">
  97. <div
  98. className="demo-col-inset"
  99. style={{ height: "50px", paddingTop: "20px", fontSize: "20px" }}
  100. >
  101. col-8
  102. </div>
  103. </Col>
  104. <Col span="8">
  105. <div
  106. className="demo-col-inset"
  107. style={{ height: "150px", paddingTop: "20px", fontSize: "40px" }}
  108. >
  109. col-8
  110. </div>
  111. </Col>
  112. </Row>
  113. <div className="demo-title">
  114. 占满整个容器的高度(需要将width设置为100%)
  115. </div>
  116. <Row className="demo-row" align="stretch">
  117. <Col span="8">
  118. <div className="demo-col-inset" style={{ width: "100%" }}>
  119. col-8
  120. </div>
  121. </Col>
  122. <Col span="8">
  123. <div className="demo-col-inset" style={{ width: "100%" }}>
  124. col-8
  125. </div>
  126. </Col>
  127. <Col span="8">
  128. <div className="demo-col-inset" style={{ width: "100%" }}>
  129. col-8
  130. </div>
  131. </Col>
  132. </Row>
  133. <div className="demo-title">单独设置列对齐方式</div>
  134. <Row className="demo-row" align="top">
  135. <Col span="8">
  136. <div
  137. className="demo-col-inset"
  138. style={{ height: "100px", lineHeight: "100px" }}
  139. >
  140. col-8
  141. </div>
  142. </Col>
  143. <Col span="8" align="bottom">
  144. <div
  145. className="demo-col-inset"
  146. style={{ height: "50px", lineHeight: "50px" }}
  147. >
  148. col-8
  149. </div>
  150. </Col>
  151. <Col span="8">
  152. <div
  153. className="demo-col-inset"
  154. style={{ height: "150px", lineHeight: "150px" }}
  155. >
  156. col-8
  157. </div>
  158. </Col>
  159. </Row>
  160. </div>,
  161. mountNode
  162. );
  1. .demo {
  2. padding-top: 10px;
  3. border: 1px solid #e9e9e9;
  4. border-radius: 6px;
  5. }
  6. .demo-title {
  7. margin-left: 20px;
  8. }
  9. .demo-row {
  10. margin: 10px 0;
  11. }
  12. .demo-col-inset {
  13. min-height: 30px;
  14. border:1px solid #CCC;
  15. border-radius: 3px;
  16. background-color:#ECECEC;
  17. line-height: 30px;
  18. text-align: center;
  19. }

基础布局

默认使用flex实现,IE9及其以下版本使用display:table;实现。通过Colspan属性指定该列占24分之几的空间。Row为栅格系统的最外层容器(行),里面包括多个Col(列)。

Grid 栅格 - 图2

查看源码在线预览

  1. import { Grid } from "@icedesign/base";
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="demo">
  5. <div className="demo-title">单列</div>
  6. <Row className="demo-row">
  7. <Col span="24">
  8. <div className="demo-col-inset">col-24</div>
  9. </Col>
  10. </Row>
  11. <div className="demo-title">两列</div>
  12. <Row className="demo-row">
  13. <Col span="12">
  14. <div className="demo-col-inset">col-12</div>
  15. </Col>
  16. <Col span="12">
  17. <div className="demo-col-inset">col-12</div>
  18. </Col>
  19. </Row>
  20. <div className="demo-title">三列</div>
  21. <Row className="demo-row">
  22. <Col span="8">
  23. <div className="demo-col-inset">col-8</div>
  24. </Col>
  25. <Col span="8">
  26. <div className="demo-col-inset">col-8</div>
  27. </Col>
  28. <Col span="8">
  29. <div className="demo-col-inset">col-8</div>
  30. </Col>
  31. </Row>
  32. <div className="demo-title">四列</div>
  33. <Row className="demo-row">
  34. <Col span="6">
  35. <div className="demo-col-inset">col-6</div>
  36. </Col>
  37. <Col span="6">
  38. <div className="demo-col-inset">col-6</div>
  39. </Col>
  40. <Col span="6">
  41. <div className="demo-col-inset">col-6</div>
  42. </Col>
  43. <Col span="6">
  44. <div className="demo-col-inset">col-6</div>
  45. </Col>
  46. </Row>
  47. <div className="demo-title">五列</div>
  48. <Row className="demo-row">
  49. <Col span="1p5">
  50. <div className="demo-col-inset">col-1p5</div>
  51. </Col>
  52. <Col span="1p5">
  53. <div className="demo-col-inset">col-1p5</div>
  54. </Col>
  55. <Col span="1p5">
  56. <div className="demo-col-inset">col-1p5</div>
  57. </Col>
  58. <Col span="1p5">
  59. <div className="demo-col-inset">col-1p5</div>
  60. </Col>
  61. <Col span="1p5">
  62. <div className="demo-col-inset">col-1p5</div>
  63. </Col>
  64. </Row>
  65. <div className="demo-title">六列</div>
  66. <Row className="demo-row">
  67. <Col span="4">
  68. <div className="demo-col-inset">col-4</div>
  69. </Col>
  70. <Col span="4">
  71. <div className="demo-col-inset">col-4</div>
  72. </Col>
  73. <Col span="4">
  74. <div className="demo-col-inset">col-4</div>
  75. </Col>
  76. <Col span="4">
  77. <div className="demo-col-inset">col-4</div>
  78. </Col>
  79. <Col span="4">
  80. <div className="demo-col-inset">col-4</div>
  81. </Col>
  82. <Col span="4">
  83. <div className="demo-col-inset">col-4</div>
  84. </Col>
  85. </Row>
  86. </div>,
  87. mountNode
  88. );
  1. .demo {
  2. padding-top: 10px;
  3. border: 1px solid #e9e9e9;
  4. border-radius: 6px;
  5. }
  6. .demo-title {
  7. margin-left: 20px;
  8. }
  9. .demo-row {
  10. margin: 10px 0;
  11. }
  12. .demo-col-inset {
  13. min-height: 30px;
  14. border:1px solid #CCC;
  15. border-radius: 3px;
  16. background-color:#ECECEC;
  17. line-height: 30px;
  18. text-align: center;
  19. }

响应式布局

提示类似Bootstrap的响应式设计,预设6个响应尺寸:xxs(320px), xs(480px), s(720px), m(990px), l(1200px), xl(1500px)。

Grid 栅格 - 图3

查看源码在线预览

  1. import { Grid, dom } from "@icedesign/base";
  2. const { Row, Col } = Grid;
  3. const { events } = dom;
  4. const spans = [
  5. { xs: 12, s: 8, m: 6 },
  6. { xs: 6, s: 8, m: 6 },
  7. { xs: 6, s: 8, m: 12 }
  8. ];
  9. const breakpoints = {
  10. xs: 480,
  11. s: 720,
  12. m: 990
  13. };
  14. class Demo extends React.Component {
  15. componentDidMount() {
  16. const row = ReactDOM.findDOMNode(this.refs.row);
  17. const cols = [];
  18. for (let i = 0; i < row.children.length; i++) {
  19. cols.push(row.children[i]);
  20. }
  21. this.handleResize = () => {
  22. let point = "";
  23. const innerWidth =
  24. window.innerWidth ||
  25. document.documentElement.clientWidth ||
  26. document.body.clientWidth;
  27. const keys = Object.keys(breakpoints);
  28. for (let i = 0; i < keys.length; i++) {
  29. const width = breakpoints[keys[i]];
  30. const nextWidth = breakpoints[keys[i + 1]];
  31. if (innerWidth > width && (innerWidth < nextWidth || !nextWidth)) {
  32. point = keys[i];
  33. break;
  34. }
  35. }
  36. if (point) {
  37. cols.forEach((col, index) => {
  38. const colInset = col.children[0];
  39. colInset.innerHTML = `col-${spans[index][point]}`;
  40. });
  41. }
  42. };
  43. events.on(window, "resize", this.handleResize);
  44. this.handleResize();
  45. }
  46. componentWillUnmount() {
  47. events.off(window, "resize", this.handleResize);
  48. }
  49. render() {
  50. return (
  51. <div className="demo">
  52. <div className="demo-title">调整浏览器宽度查看各列所占栅格数变化</div>
  53. <Row ref="row" className="demo-row">
  54. {spans.map((span, index) => (
  55. <Col key={index} {...span}>
  56. <div className="demo-col-inset" />
  57. </Col>
  58. ))}
  59. </Row>
  60. </div>
  61. );
  62. }
  63. }
  64. ReactDOM.render(<Demo />, mountNode);
  1. .demo {
  2. padding-top: 10px;
  3. border: 1px solid #e9e9e9;
  4. border-radius: 6px;
  5. }
  6. .demo-title {
  7. margin-left: 20px;
  8. }
  9. .demo-row {
  10. margin: 10px 0;
  11. }
  12. .demo-col-inset {
  13. min-height: 30px;
  14. border:1px solid #CCC;
  15. border-radius: 3px;
  16. background-color:#ECECEC;
  17. line-height: 30px;
  18. text-align: center;
  19. }

指定列宽(固定栅格))

基础栅格宽度为20px,可用栅格为1到30,其宽度值为20 * 栅格数。

Grid 栅格 - 图4

查看源码在线预览

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

显示与隐藏

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

Grid 栅格 - 图5

查看源码在线预览

  1. import { Grid } from "@icedesign/base";
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="demo">
  5. <div className="demo-title">
  6. 在所有断点下隐藏列,调整浏览器宽度查看各列隐藏还是显示
  7. </div>
  8. <Row className="demo-row">
  9. <Col span="8" hidden>
  10. <div className="demo-col-inset">col-8</div>
  11. </Col>
  12. <Col span="16" hidden>
  13. <div className="demo-col-inset">col-16</div>
  14. </Col>
  15. </Row>
  16. <div className="demo-title">
  17. 在某断点下(m)隐藏列,调整浏览器宽度查看各列隐藏还是显示
  18. </div>
  19. <Row className="demo-row">
  20. <Col span="8" hidden="m">
  21. <div className="demo-col-inset">col-8</div>
  22. </Col>
  23. <Col span="16" hidden="m">
  24. <div className="demo-col-inset">col-16</div>
  25. </Col>
  26. </Row>
  27. <div className="demo-title">
  28. 在部分断点下(m, l, xl)隐藏列,调整浏览器宽度查看各列隐藏还是显示
  29. </div>
  30. <Row className="demo-row">
  31. <Col span="8" hidden={["m", "l", "xl"]}>
  32. <div className="demo-col-inset">col-8</div>
  33. </Col>
  34. <Col span="16" hidden={["m", "l", "xl"]}>
  35. <div className="demo-col-inset">col-16</div>
  36. </Col>
  37. </Row>
  38. </div>,
  39. mountNode
  40. );
  1. .demo {
  2. padding-top: 10px;
  3. border: 1px solid #e9e9e9;
  4. border-radius: 6px;
  5. }
  6. .demo-title {
  7. margin-left: 20px;
  8. }
  9. .demo-row {
  10. margin: 10px 0;
  11. }
  12. .demo-col-inset {
  13. min-height: 30px;
  14. border:1px solid #CCC;
  15. border-radius: 3px;
  16. background-color:#ECECEC;
  17. line-height: 30px;
  18. text-align: center;
  19. }

多列水平方向对齐方式

(不支持IE9及以下浏览器)使用Flex的justify-content属性实现行内多列水平方向对齐方式:start(左对齐,默认),center(居中对齐),end(右对齐),space-between(两端对齐,项目之间的间隔都相),space-around(两侧的间隔相等,列之间的间隔比列与边框的间隔大一倍)。

Grid 栅格 - 图6

查看源码在线预览

  1. import { Grid } from "@icedesign/base";
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="demo">
  5. <div className="demo-title">左对齐</div>
  6. <Row className="demo-row" justify="start">
  7. <Col span="4">
  8. <div className="demo-col-inset">col-4</div>
  9. </Col>
  10. <Col span="4">
  11. <div className="demo-col-inset">col-4</div>
  12. </Col>
  13. <Col span="4">
  14. <div className="demo-col-inset">col-4</div>
  15. </Col>
  16. </Row>
  17. <div className="demo-title">居中对齐</div>
  18. <Row className="demo-row" justify="center">
  19. <Col span="4">
  20. <div className="demo-col-inset">col-4</div>
  21. </Col>
  22. <Col span="4">
  23. <div className="demo-col-inset">col-4</div>
  24. </Col>
  25. <Col span="4">
  26. <div className="demo-col-inset">col-4</div>
  27. </Col>
  28. </Row>
  29. <div className="demo-title">右对齐</div>
  30. <Row className="demo-row" justify="end">
  31. <Col span="4">
  32. <div className="demo-col-inset">col-4</div>
  33. </Col>
  34. <Col span="4">
  35. <div className="demo-col-inset">col-4</div>
  36. </Col>
  37. <Col span="4">
  38. <div className="demo-col-inset">col-4</div>
  39. </Col>
  40. </Row>
  41. <div className="demo-title">两端对齐,列之间的间隔都相等</div>
  42. <Row className="demo-row" justify="space-between">
  43. <Col span="4">
  44. <div className="demo-col-inset">col-4</div>
  45. </Col>
  46. <Col span="4">
  47. <div className="demo-col-inset">col-4</div>
  48. </Col>
  49. <Col span="4">
  50. <div className="demo-col-inset">col-4</div>
  51. </Col>
  52. </Row>
  53. <div className="demo-title">
  54. 列两侧的间隔相等,列之间的间隔比列与边框的间隔大一倍
  55. </div>
  56. <Row className="demo-row" justify="space-around">
  57. <Col span="4">
  58. <div className="demo-col-inset">col-4</div>
  59. </Col>
  60. <Col span="4">
  61. <div className="demo-col-inset">col-4</div>
  62. </Col>
  63. <Col span="4">
  64. <div className="demo-col-inset">col-4</div>
  65. </Col>
  66. </Row>
  67. </div>,
  68. mountNode
  69. );
  1. .demo {
  2. padding-top: 10px;
  3. border: 1px solid #e9e9e9;
  4. border-radius: 6px;
  5. }
  6. .demo-title {
  7. margin-left: 20px;
  8. }
  9. .demo-row {
  10. margin: 10px 0;
  11. }
  12. .demo-col-inset {
  13. min-height: 30px;
  14. border:1px solid #CCC;
  15. border-radius: 3px;
  16. background-color:#ECECEC;
  17. line-height: 30px;
  18. text-align: center;
  19. }

流式栅格和固定栅格混用

Grid 栅格 - 图7

查看源码在线预览

  1. import { Grid } from "@icedesign/base";
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="demo">
  5. <div className="demo-title">两列布局,左列固定,右列自适应</div>
  6. <Row className="demo-row">
  7. <Col fixedSpan="16">
  8. <div className="demo-col-inset">col-fixed-16</div>
  9. </Col>
  10. <Col>
  11. <div className="demo-col-inset">col</div>
  12. </Col>
  13. </Row>
  14. <div className="demo-title">两列布局,右列固定,左列自适应</div>
  15. <Row className="demo-row">
  16. <Col>
  17. <div className="demo-col-inset">col</div>
  18. </Col>
  19. <Col fixedSpan="16">
  20. <div className="demo-col-inset">col-fixed-16</div>
  21. </Col>
  22. </Row>
  23. <div className="demo-title">三列布局,左列右列固定,中间自适应</div>
  24. <Row className="demo-row">
  25. <Col fixedSpan="8">
  26. <div className="demo-col-inset">col-fixed-8</div>
  27. </Col>
  28. <Col>
  29. <div className="demo-col-inset">col</div>
  30. </Col>
  31. <Col fixedSpan="8">
  32. <div className="demo-col-inset">col-fixed-8</div>
  33. </Col>
  34. </Row>
  35. </div>,
  36. mountNode
  37. );
  1. .demo {
  2. padding-top: 10px;
  3. border: 1px solid #e9e9e9;
  4. border-radius: 6px;
  5. }
  6. .demo-title {
  7. margin-left: 20px;
  8. }
  9. .demo-row {
  10. margin: 10px 0;
  11. }
  12. .demo-col-inset {
  13. min-height: 30px;
  14. border:1px solid #CCC;
  15. border-radius: 3px;
  16. background-color:#ECECEC;
  17. line-height: 30px;
  18. text-align: center;
  19. }

嵌套布局

Col下也可嵌套Row,以完成更细致的布局,如果想保持不同嵌套的Row下的Col间间距相等,请设置Rowtypeacross,即通栏模式,或自己设置样式,将Row的左右padding设置为0。

Grid 栅格 - 图8

查看源码在线预览

  1. import { Grid } from "@icedesign/base";
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="demo">
  5. <Row className="demo-row">
  6. <Col span="10">
  7. <Row type="across">
  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 type="across">
  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>,
  28. mountNode
  29. );
  1. .demo {
  2. padding-top: 10px;
  3. border: 1px solid #e9e9e9;
  4. border-radius: 6px;
  5. }
  6. .demo-title {
  7. margin-left: 20px;
  8. }
  9. .demo-row {
  10. margin: 10px 0;
  11. }
  12. .demo-col-inset {
  13. min-height: 30px;
  14. border:1px solid #CCC;
  15. border-radius: 3px;
  16. background-color:#ECECEC;
  17. line-height: 30px;
  18. text-align: center;
  19. }

偏移(固定栅格))

(不支持IE9及以下浏览器)列可以向右偏移一定的列数, 偏移的列数和固定栅格列数定义相同.

Grid 栅格 - 图9

查看源码在线预览

  1. import { Grid } from "@icedesign/base";
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="demo">
  5. <div className="demo-title">常规偏移,可设置offset的值从023</div>
  6. <Row className="demo-row">
  7. <Col fixedOffset="0">
  8. <div className="demo-col-inset">offset-fixed-0</div>
  9. </Col>
  10. </Row>
  11. <Row className="demo-row">
  12. <Col fixedOffset="4">
  13. <div className="demo-col-inset">offset-fixed-4</div>
  14. </Col>
  15. </Row>
  16. <Row className="demo-row">
  17. <Col fixedOffset="8">
  18. <div className="demo-col-inset">offset-fixed-8</div>
  19. </Col>
  20. </Row>
  21. <Row className="demo-row">
  22. <Col fixedOffset="12">
  23. <div className="demo-col-inset">offset-fixed-12</div>
  24. </Col>
  25. </Row>
  26. <div className="demo-title">自适应偏移</div>
  27. <Row className="demo-row">
  28. <Col>
  29. <div className="demo-col-inset">col</div>
  30. </Col>
  31. <Col fixedOffset="12">
  32. <div className="demo-col-inset">offset-fixed-12</div>
  33. </Col>
  34. </Row>
  35. </div>,
  36. mountNode
  37. );
  1. .demo {
  2. padding-top: 10px;
  3. border: 1px solid #e9e9e9;
  4. border-radius: 6px;
  5. }
  6. .demo-title {
  7. margin-left: 20px;
  8. }
  9. .demo-row {
  10. margin: 10px 0;
  11. }
  12. .demo-col-inset {
  13. min-height: 30px;
  14. border:1px solid #CCC;
  15. border-radius: 3px;
  16. background-color:#ECECEC;
  17. line-height: 30px;
  18. text-align: center;
  19. }

偏移(流式栅格))

(不支持IE9及以下浏览器)列可以向右偏移一定的列数,偏移的列数和流式布局栅格列数定义相同。

Grid 栅格 - 图10

查看源码在线预览

  1. import { Grid } from "@icedesign/base";
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="demo">
  5. <div className="demo-title">常规偏移,可设置offset的值从030</div>
  6. <Row className="demo-row">
  7. <Col offset="0">
  8. <div className="demo-col-inset">offset-fixed-0</div>
  9. </Col>
  10. </Row>
  11. <Row className="demo-row">
  12. <Col offset="4">
  13. <div className="demo-col-inset">offset-fixed-4</div>
  14. </Col>
  15. </Row>
  16. <Row className="demo-row">
  17. <Col offset="8">
  18. <div className="demo-col-inset">offset-fixed-8</div>
  19. </Col>
  20. </Row>
  21. <Row className="demo-row">
  22. <Col offset="12">
  23. <div className="demo-col-inset">offset-fixed-12</div>
  24. </Col>
  25. </Row>
  26. <div className="demo-title">自适应偏移</div>
  27. <Row className="demo-row">
  28. <Col>
  29. <div className="demo-col-inset">col</div>
  30. </Col>
  31. <Col offset="12">
  32. <div className="demo-col-inset">offset-12</div>
  33. </Col>
  34. </Row>
  35. </div>,
  36. mountNode
  37. );
  1. .demo {
  2. padding-top: 10px;
  3. border: 1px solid #e9e9e9;
  4. border-radius: 6px;
  5. }
  6. .demo-title {
  7. margin-left: 20px;
  8. }
  9. .demo-row {
  10. margin: 10px 0;
  11. }
  12. .demo-col-inset {
  13. min-height: 30px;
  14. border:1px solid #CCC;
  15. border-radius: 3px;
  16. background-color:#ECECEC;
  17. line-height: 30px;
  18. text-align: center;
  19. }

布局方式

Note: 未来的@alife/grid@1.x中的默认布局即是fluid布局,并且去除最大宽度为1500px的限制。across为通拦模式,行边距为0。no-padding行边距以及所有列间距都为0。no-wrap为单行模式, 列在行中宽度溢出后不换行。(IE9及以下版本不支持)wrap为单行模式, 列在行中宽度溢出后换行。(IE9及以下版本不支持)fixed为固定宽度布局,宽度为各断点值,两侧根据分辨率情况自动留白。fluid也为流式布局,行的最大宽度随浏览器宽度变化而变化,直到最大宽度1500px。默认布局为流式布局,行的最大宽度随浏览器宽度变化而变化。

Grid 栅格 - 图11

查看源码在线预览

  1. import { Grid } from "@icedesign/base";
  2. const { Row, Col } = Grid;
  3. ReactDOM.render(
  4. <div className="demo">
  5. <div className="demo-title">默认布局</div>
  6. <Row className="demo-row">
  7. <Col span="8">
  8. <div className="demo-col-inset" />
  9. </Col>
  10. <Col span="8">
  11. <div className="demo-col-inset" />
  12. </Col>
  13. <Col span="8">
  14. <div className="demo-col-inset" />
  15. </Col>
  16. </Row>
  17. <div className="demo-title">流式布局(fluid)</div>
  18. <Row type="fluid" className="demo-row">
  19. <Col span="8">
  20. <div className="demo-col-inset" />
  21. </Col>
  22. <Col span="8">
  23. <div className="demo-col-inset" />
  24. </Col>
  25. <Col span="8">
  26. <div className="demo-col-inset" />
  27. </Col>
  28. </Row>
  29. <div className="demo-title">固定宽度布局(fixed)</div>
  30. <Row type="fixed" className="demo-row">
  31. <Col span="8">
  32. <div className="demo-col-inset" />
  33. </Col>
  34. <Col span="8">
  35. <div className="demo-col-inset" />
  36. </Col>
  37. <Col span="8">
  38. <div className="demo-col-inset" />
  39. </Col>
  40. </Row>
  41. <div className="demo-title">固定宽度布局(fixed),指定固定宽度</div>
  42. <Row type="fixed" fixedWidth="s" className="demo-row">
  43. <Col>
  44. <div className="demo-col-inset">720px</div>
  45. </Col>
  46. <Col>
  47. <div className="demo-col-inset">720px</div>
  48. </Col>
  49. <Col>
  50. <div className="demo-col-inset">720px</div>
  51. </Col>
  52. </Row>
  53. <div className="demo-title">单行模式(wrap),列在行中宽度溢出后换行</div>
  54. <Row type="wrap" className="demo-row">
  55. <Col span="10">
  56. <div className="demo-col-inset">col-10</div>
  57. </Col>
  58. <Col span="10">
  59. <div className="demo-col-inset">col-10</div>
  60. </Col>
  61. <Col span="6">
  62. <div className="demo-col-inset">col-6</div>
  63. </Col>
  64. </Row>
  65. <div className="demo-title">
  66. 单行模式(no-wrap),列在行中宽度溢出后不换行
  67. </div>
  68. <Row type="no-wrap" className="demo-row">
  69. <Col span="10">
  70. <div className="demo-col-inset">col-10</div>
  71. </Col>
  72. <Col span="10">
  73. <div className="demo-col-inset">col-10</div>
  74. </Col>
  75. <Col span="6">
  76. <div className="demo-col-inset">col-6</div>
  77. </Col>
  78. </Row>
  79. <div className="demo-title">无间距布局(no-padding)</div>
  80. <Row type="no-padding" className="demo-row">
  81. <Col span="10">
  82. <div className="demo-col-inset">col-10</div>
  83. </Col>
  84. <Col span="8">
  85. <div className="demo-col-inset">col-8</div>
  86. </Col>
  87. <Col span="6">
  88. <div className="demo-col-inset">col-6</div>
  89. </Col>
  90. </Row>
  91. <div className="demo-title">通栏布局(across)</div>
  92. <Row type="across" className="demo-row">
  93. <Col span="10">
  94. <div className="demo-col-inset">col-10</div>
  95. </Col>
  96. <Col span="8">
  97. <div className="demo-col-inset">col-8</div>
  98. </Col>
  99. <Col span="6">
  100. <div className="demo-col-inset">col-6</div>
  101. </Col>
  102. </Row>
  103. <div className="demo-title">多种布局模式组合使用(fixed, no-padding)</div>
  104. <Row type={["fixed", "no-padding"]} fixedWidth="s" className="demo-row">
  105. <Col span="12">
  106. <div className="demo-col-inset">col-12</div>
  107. </Col>
  108. <Col span="6">
  109. <div className="demo-col-inset">col-6</div>
  110. </Col>
  111. <Col span="6">
  112. <div className="demo-col-inset">col-6</div>
  113. </Col>
  114. </Row>
  115. <div className="demo-title">
  116. 多种布局模式组合使用(fluid, no-wrap, no-padding)
  117. </div>
  118. <Row type={["fluid", "no-wrap", "no-padding"]} className="demo-row">
  119. <Col span="12">
  120. <div className="demo-col-inset">col-12</div>
  121. </Col>
  122. <Col span="8">
  123. <div className="demo-col-inset">col-8</div>
  124. </Col>
  125. <Col span="6">
  126. <div className="demo-col-inset">col-6</div>
  127. </Col>
  128. </Row>
  129. </div>,
  130. mountNode
  131. );
  1. .demo {
  2. padding-top: 10px;
  3. border: 1px solid #e9e9e9;
  4. border-radius: 6px;
  5. }
  6. .demo-title {
  7. margin-left: 20px;
  8. }
  9. .demo-row {
  10. margin: 10px 0;
  11. }
  12. .demo-col-inset {
  13. min-height: 30px;
  14. border:1px solid #CCC;
  15. border-radius: 3px;
  16. background-color:#ECECEC;
  17. line-height: 30px;
  18. text-align: center;
  19. }

相关区块

Grid 栅格 - 图12

暂无相关区块