Layout布局

协助进行页面级整体布局。

设计规则

尺寸

一级导航项偏左靠近 logo 放置,辅助菜单偏右放置。

  • 顶部导航(大部分系统):一级导航高度 64px,二级导航 48px

  • 顶部导航(展示类页面):一级导航高度 80px,二级导航 56px

  • 顶部导航高度的范围计算公式为:48+8n

  • 侧边导航宽度的范围计算公式:200+8n

交互

  • 一级导航和末级的导航需要在可视化的层面被强调出来;

  • 当前项应该在呈现上优先级最高;

  • 当导航收起的时候,当前项的样式自动赋予给它的上一个层级;

  • 左侧导航栏的收放交互同时支持手风琴和全展开的样式,根据业务的要求进行适当的选择。

视觉

导航样式上需要根据信息层级合理的选择样式:

  • 大色块强调

建议用于底色为深色系时,当前页面父级的导航项。

  • 高亮火柴棍

当导航栏底色为浅色系时使用,可用于当前页面对应导航项,建议尽量在导航路径的最终项使用。

  • 字体高亮变色

从可视化层面,字体高亮的视觉强化力度低于大色块,通常在当前项的上一级使用。

  • 字体放大

12px14px 是导航的标准字号,14 号字体用在一、二级导航中。字号可以考虑导航项的等级做相应选择。

组件概述

  • Layout:布局容器,其下可嵌套 Header Sider Content FooterLayout 本身,可以放在任何父容器中。

  • Header:顶部布局,自带默认样式,其下可嵌套任何元素,只能放在 Layout 中。

  • Sider:侧边栏,自带默认样式及基本功能,其下可嵌套任何元素,只能放在 Layout 中。

  • Content:内容部分,自带默认样式,其下可嵌套任何元素,只能放在 Layout 中。

  • Footer:底部布局,自带默认样式,其下可嵌套任何元素,只能放在 Layout 中。

注意:采用 flex 布局实现,请注意浏览器兼容性问题。

代码演示

Layout布局 - 图1

基本结构

典型的页面布局。

  1. import { Layout } from 'antd';
  2. const { Header, Footer, Sider, Content } = Layout;
  3. ReactDOM.render(
  4. <div>
  5. <Layout>
  6. <Header>Header</Header>
  7. <Content>Content</Content>
  8. <Footer>Footer</Footer>
  9. </Layout>
  10. <Layout>
  11. <Header>Header</Header>
  12. <Layout>
  13. <Sider>Sider</Sider>
  14. <Content>Content</Content>
  15. </Layout>
  16. <Footer>Footer</Footer>
  17. </Layout>
  18. <Layout>
  19. <Header>Header</Header>
  20. <Layout>
  21. <Content>Content</Content>
  22. <Sider>Sider</Sider>
  23. </Layout>
  24. <Footer>Footer</Footer>
  25. </Layout>
  26. <Layout>
  27. <Sider>Sider</Sider>
  28. <Layout>
  29. <Header>Header</Header>
  30. <Content>Content</Content>
  31. <Footer>Footer</Footer>
  32. </Layout>
  33. </Layout>
  34. </div>,
  35. mountNode,
  36. );

Layout布局 - 图2

上中下布局

最基本的『上-中-下』布局。

一般主导航放置于页面的顶端,从左自右依次为:logo、一级导航项、辅助菜单(用户、设置、通知等)。通常将内容放在固定尺寸(例如:1200px)内,整个页面排版稳定,不受用户终端显示器影响;上下级的结构符合用户上下浏览的习惯,也是较为经典的网站导航模式。页面上下切分的方式提高了主工作区域的信息展示效率,但在纵向空间上会有一些牺牲。此外,由于导航栏水平空间的限制,不适合那些一级导航项很多的信息结构。

  1. import { Layout, Menu, Breadcrumb } from 'antd';
  2. const { Header, Content, Footer } = Layout;
  3. ReactDOM.render(
  4. <Layout className="layout">
  5. <Header>
  6. <div className="logo" />
  7. <Menu theme="dark" mode="horizontal" defaultSelectedKeys={['2']}>
  8. <Menu.Item key="1">nav 1</Menu.Item>
  9. <Menu.Item key="2">nav 2</Menu.Item>
  10. <Menu.Item key="3">nav 3</Menu.Item>
  11. </Menu>
  12. </Header>
  13. <Content style={{ padding: '0 50px' }}>
  14. <Breadcrumb style={{ margin: '16px 0' }}>
  15. <Breadcrumb.Item>Home</Breadcrumb.Item>
  16. <Breadcrumb.Item>List</Breadcrumb.Item>
  17. <Breadcrumb.Item>App</Breadcrumb.Item>
  18. </Breadcrumb>
  19. <div className="site-layout-content">Content</div>
  20. </Content>
  21. <Footer style={{ textAlign: 'center' }}>Ant Design ©2018 Created by Ant UED</Footer>
  22. </Layout>,
  23. mountNode,
  24. );
  1. .site-layout-content {
  2. background: #fff;
  3. padding: 24px;
  4. min-height: 280px;
  5. }
  6. #components-layout-demo-top .logo {
  7. width: 120px;
  8. height: 31px;
  9. background: rgba(255, 255, 255, 0.2);
  10. margin: 16px 24px 16px 0;
  11. float: left;
  12. }

Layout布局 - 图3

顶部-侧边布局-通栏

同样拥有顶部导航及侧边栏,区别是两边未留边距,多用于应用型的网站。

  1. import { Layout, Menu, Breadcrumb } from 'antd';
  2. import { UserOutlined, LaptopOutlined, NotificationOutlined } from '@ant-design/icons';
  3. const { SubMenu } = Menu;
  4. const { Header, Content, Sider } = Layout;
  5. ReactDOM.render(
  6. <Layout>
  7. <Header className="header">
  8. <div className="logo" />
  9. <Menu theme="dark" mode="horizontal" defaultSelectedKeys={['2']}>
  10. <Menu.Item key="1">nav 1</Menu.Item>
  11. <Menu.Item key="2">nav 2</Menu.Item>
  12. <Menu.Item key="3">nav 3</Menu.Item>
  13. </Menu>
  14. </Header>
  15. <Layout>
  16. <Sider width={200} className="site-layout-background">
  17. <Menu
  18. mode="inline"
  19. defaultSelectedKeys={['1']}
  20. defaultOpenKeys={['sub1']}
  21. style={{ height: '100%', borderRight: 0 }}
  22. >
  23. <SubMenu
  24. key="sub1"
  25. title={
  26. <span>
  27. <UserOutlined />
  28. subnav 1
  29. </span>
  30. }
  31. >
  32. <Menu.Item key="1">option1</Menu.Item>
  33. <Menu.Item key="2">option2</Menu.Item>
  34. <Menu.Item key="3">option3</Menu.Item>
  35. <Menu.Item key="4">option4</Menu.Item>
  36. </SubMenu>
  37. <SubMenu
  38. key="sub2"
  39. title={
  40. <span>
  41. <LaptopOutlined />
  42. subnav 2
  43. </span>
  44. }
  45. >
  46. <Menu.Item key="5">option5</Menu.Item>
  47. <Menu.Item key="6">option6</Menu.Item>
  48. <Menu.Item key="7">option7</Menu.Item>
  49. <Menu.Item key="8">option8</Menu.Item>
  50. </SubMenu>
  51. <SubMenu
  52. key="sub3"
  53. title={
  54. <span>
  55. <NotificationOutlined />
  56. subnav 3
  57. </span>
  58. }
  59. >
  60. <Menu.Item key="9">option9</Menu.Item>
  61. <Menu.Item key="10">option10</Menu.Item>
  62. <Menu.Item key="11">option11</Menu.Item>
  63. <Menu.Item key="12">option12</Menu.Item>
  64. </SubMenu>
  65. </Menu>
  66. </Sider>
  67. <Layout style={{ padding: '0 24px 24px' }}>
  68. <Breadcrumb style={{ margin: '16px 0' }}>
  69. <Breadcrumb.Item>Home</Breadcrumb.Item>
  70. <Breadcrumb.Item>List</Breadcrumb.Item>
  71. <Breadcrumb.Item>App</Breadcrumb.Item>
  72. </Breadcrumb>
  73. <Content
  74. className="site-layout-background"
  75. style={{
  76. padding: 24,
  77. margin: 0,
  78. minHeight: 280,
  79. }}
  80. >
  81. Content
  82. </Content>
  83. </Layout>
  84. </Layout>
  85. </Layout>,
  86. mountNode,
  87. );
  1. #components-layout-demo-top-side-2 .logo {
  2. width: 120px;
  3. height: 31px;
  4. background: rgba(255, 255, 255, 0.2);
  5. margin: 16px 28px 16px 0;
  6. float: left;
  7. }
  8. .site-layout-background {
  9. background: #fff;
  10. }

Layout布局 - 图4

顶部-侧边布局

拥有顶部导航及侧边栏的页面,多用于展示类网站。

  1. import { Layout, Menu, Breadcrumb } from 'antd';
  2. import { UserOutlined, LaptopOutlined, NotificationOutlined } from '@ant-design/icons';
  3. const { SubMenu } = Menu;
  4. const { Header, Content, Footer, Sider } = Layout;
  5. ReactDOM.render(
  6. <Layout>
  7. <Header className="header">
  8. <div className="logo" />
  9. <Menu theme="dark" mode="horizontal" defaultSelectedKeys={['2']}>
  10. <Menu.Item key="1">nav 1</Menu.Item>
  11. <Menu.Item key="2">nav 2</Menu.Item>
  12. <Menu.Item key="3">nav 3</Menu.Item>
  13. </Menu>
  14. </Header>
  15. <Content style={{ padding: '0 50px' }}>
  16. <Breadcrumb style={{ margin: '16px 0' }}>
  17. <Breadcrumb.Item>Home</Breadcrumb.Item>
  18. <Breadcrumb.Item>List</Breadcrumb.Item>
  19. <Breadcrumb.Item>App</Breadcrumb.Item>
  20. </Breadcrumb>
  21. <Layout className="site-layout-background" style={{ padding: '24px 0' }}>
  22. <Sider className="site-layout-background" width={200}>
  23. <Menu
  24. mode="inline"
  25. defaultSelectedKeys={['1']}
  26. defaultOpenKeys={['sub1']}
  27. style={{ height: '100%' }}
  28. >
  29. <SubMenu
  30. key="sub1"
  31. title={
  32. <span>
  33. <UserOutlined />
  34. subnav 1
  35. </span>
  36. }
  37. >
  38. <Menu.Item key="1">option1</Menu.Item>
  39. <Menu.Item key="2">option2</Menu.Item>
  40. <Menu.Item key="3">option3</Menu.Item>
  41. <Menu.Item key="4">option4</Menu.Item>
  42. </SubMenu>
  43. <SubMenu
  44. key="sub2"
  45. title={
  46. <span>
  47. <LaptopOutlined />
  48. subnav 2
  49. </span>
  50. }
  51. >
  52. <Menu.Item key="5">option5</Menu.Item>
  53. <Menu.Item key="6">option6</Menu.Item>
  54. <Menu.Item key="7">option7</Menu.Item>
  55. <Menu.Item key="8">option8</Menu.Item>
  56. </SubMenu>
  57. <SubMenu
  58. key="sub3"
  59. title={
  60. <span>
  61. <NotificationOutlined />
  62. subnav 3
  63. </span>
  64. }
  65. >
  66. <Menu.Item key="9">option9</Menu.Item>
  67. <Menu.Item key="10">option10</Menu.Item>
  68. <Menu.Item key="11">option11</Menu.Item>
  69. <Menu.Item key="12">option12</Menu.Item>
  70. </SubMenu>
  71. </Menu>
  72. </Sider>
  73. <Content style={{ padding: '0 24px', minHeight: 280 }}>Content</Content>
  74. </Layout>
  75. </Content>
  76. <Footer style={{ textAlign: 'center' }}>Ant Design ©2018 Created by Ant UED</Footer>
  77. </Layout>,
  78. mountNode,
  79. );
  1. #components-layout-demo-top-side .logo {
  2. width: 120px;
  3. height: 31px;
  4. background: rgba(255, 255, 255, 0.2);
  5. margin: 16px 28px 16px 0;
  6. float: left;
  7. }
  8. .site-layout-background {
  9. background: #fff;
  10. }

Layout布局 - 图5

侧边布局

侧边两列式布局。页面横向空间有限时,侧边导航可收起。

侧边导航在页面布局上采用的是左右的结构,一般主导航放置于页面的左侧固定位置,辅助菜单放置于工作区顶部。内容根据浏览器终端进行自适应,能提高横向空间的使用率,但是整个页面排版不稳定。侧边导航的模式层级扩展性强,一、二、三级导航项目可以更为顺畅且具关联性的被展示,同时侧边导航可以固定,使得用户在操作和浏览中可以快速的定位和切换当前位置,有很高的操作效率。但这类导航横向页面内容的空间会被牺牲一部分。

  1. import { Layout, Menu, Breadcrumb } from 'antd';
  2. import {
  3. DesktopOutlined,
  4. PieChartOutlined,
  5. FileOutlined,
  6. TeamOutlined,
  7. UserOutlined,
  8. } from '@ant-design/icons';
  9. const { Header, Content, Footer, Sider } = Layout;
  10. const { SubMenu } = Menu;
  11. class SiderDemo extends React.Component {
  12. state = {
  13. collapsed: false,
  14. };
  15. onCollapse = collapsed => {
  16. console.log(collapsed);
  17. this.setState({ collapsed });
  18. };
  19. render() {
  20. return (
  21. <Layout style={{ minHeight: '100vh' }}>
  22. <Sider collapsible collapsed={this.state.collapsed} onCollapse={this.onCollapse}>
  23. <div className="logo" />
  24. <Menu theme="dark" defaultSelectedKeys={['1']} mode="inline">
  25. <Menu.Item key="1">
  26. <PieChartOutlined />
  27. <span>Option 1</span>
  28. </Menu.Item>
  29. <Menu.Item key="2">
  30. <DesktopOutlined />
  31. <span>Option 2</span>
  32. </Menu.Item>
  33. <SubMenu
  34. key="sub1"
  35. title={
  36. <span>
  37. <UserOutlined />
  38. <span>User</span>
  39. </span>
  40. }
  41. >
  42. <Menu.Item key="3">Tom</Menu.Item>
  43. <Menu.Item key="4">Bill</Menu.Item>
  44. <Menu.Item key="5">Alex</Menu.Item>
  45. </SubMenu>
  46. <SubMenu
  47. key="sub2"
  48. title={
  49. <span>
  50. <TeamOutlined />
  51. <span>Team</span>
  52. </span>
  53. }
  54. >
  55. <Menu.Item key="6">Team 1</Menu.Item>
  56. <Menu.Item key="8">Team 2</Menu.Item>
  57. </SubMenu>
  58. <Menu.Item key="9">
  59. <FileOutlined />
  60. </Menu.Item>
  61. </Menu>
  62. </Sider>
  63. <Layout className="site-layout">
  64. <Header className="site-layout-background" style={{ padding: 0 }} />
  65. <Content style={{ margin: '0 16px' }}>
  66. <Breadcrumb style={{ margin: '16px 0' }}>
  67. <Breadcrumb.Item>User</Breadcrumb.Item>
  68. <Breadcrumb.Item>Bill</Breadcrumb.Item>
  69. </Breadcrumb>
  70. <div className="site-layout-background" style={{ padding: 24, minHeight: 360 }}>
  71. Bill is a cat.
  72. </div>
  73. </Content>
  74. <Footer style={{ textAlign: 'center' }}>Ant Design ©2018 Created by Ant UED</Footer>
  75. </Layout>
  76. </Layout>
  77. );
  78. }
  79. }
  80. ReactDOM.render(<SiderDemo />, mountNode);
  1. #components-layout-demo-side .logo {
  2. height: 32px;
  3. background: rgba(255, 255, 255, 0.2);
  4. margin: 16px;
  5. }
  6. .site-layout .site-layout-background {
  7. background: #fff;
  8. }

Layout布局 - 图6

自定义触发器

要使用自定义触发器,可以设置 trigger={null} 来隐藏默认设定。

  1. import { Layout, Menu } from 'antd';
  2. import {
  3. MenuUnfoldOutlined,
  4. MenuFoldOutlined,
  5. UserOutlined,
  6. VideoCameraOutlined,
  7. UploadOutlined,
  8. } from '@ant-design/icons';
  9. const { Header, Sider, Content } = Layout;
  10. class SiderDemo extends React.Component {
  11. state = {
  12. collapsed: false,
  13. };
  14. toggle = () => {
  15. this.setState({
  16. collapsed: !this.state.collapsed,
  17. });
  18. };
  19. render() {
  20. return (
  21. <Layout>
  22. <Sider trigger={null} collapsible collapsed={this.state.collapsed}>
  23. <div className="logo" />
  24. <Menu theme="dark" mode="inline" defaultSelectedKeys={['1']}>
  25. <Menu.Item key="1">
  26. <UserOutlined />
  27. <span>nav 1</span>
  28. </Menu.Item>
  29. <Menu.Item key="2">
  30. <VideoCameraOutlined />
  31. <span>nav 2</span>
  32. </Menu.Item>
  33. <Menu.Item key="3">
  34. <UploadOutlined />
  35. <span>nav 3</span>
  36. </Menu.Item>
  37. </Menu>
  38. </Sider>
  39. <Layout className="site-layout">
  40. <Header className="site-layout-background" style={{ padding: 0 }}>
  41. {React.createElement(this.state.collapsed ? MenuUnfoldOutlined : MenuFoldOutlined, {
  42. className: 'trigger',
  43. onClick: this.toggle,
  44. })}
  45. </Header>
  46. <Content
  47. className="site-layout-background"
  48. style={{
  49. margin: '24px 16px',
  50. padding: 24,
  51. minHeight: 280,
  52. }}
  53. >
  54. Content
  55. </Content>
  56. </Layout>
  57. </Layout>
  58. );
  59. }
  60. }
  61. ReactDOM.render(<SiderDemo />, mountNode);
  1. #components-layout-demo-custom-trigger .trigger {
  2. font-size: 18px;
  3. line-height: 64px;
  4. padding: 0 24px;
  5. cursor: pointer;
  6. transition: color 0.3s;
  7. }
  8. #components-layout-demo-custom-trigger .trigger:hover {
  9. color: #1890ff;
  10. }
  11. #components-layout-demo-custom-trigger .logo {
  12. height: 32px;
  13. background: rgba(255, 255, 255, 0.2);
  14. margin: 16px;
  15. }
  16. .site-layout .site-layout-background {
  17. background: #fff;
  18. }

Layout布局 - 图7

响应式布局

Layout.Sider 支持响应式布局。

说明:配置 breakpoint 属性即生效,视窗宽度小于 breakpoint 时 Sider 缩小为 collapsedWidth 宽度,若将 collapsedWidth 设置为零,会出现特殊 trigger。

  1. import { Layout, Menu } from 'antd';
  2. import { UploadOutlined, UserOutlined, VideoCameraOutlined } from '@ant-design/icons';
  3. const { Header, Content, Footer, Sider } = Layout;
  4. ReactDOM.render(
  5. <Layout>
  6. <Sider
  7. breakpoint="lg"
  8. collapsedWidth="0"
  9. onBreakpoint={broken => {
  10. console.log(broken);
  11. }}
  12. onCollapse={(collapsed, type) => {
  13. console.log(collapsed, type);
  14. }}
  15. >
  16. <div className="logo" />
  17. <Menu theme="dark" mode="inline" defaultSelectedKeys={['4']}>
  18. <Menu.Item key="1">
  19. <UserOutlined />
  20. <span className="nav-text">nav 1</span>
  21. </Menu.Item>
  22. <Menu.Item key="2">
  23. <VideoCameraOutlined />
  24. <span className="nav-text">nav 2</span>
  25. </Menu.Item>
  26. <Menu.Item key="3">
  27. <UploadOutlined />
  28. <span className="nav-text">nav 3</span>
  29. </Menu.Item>
  30. <Menu.Item key="4">
  31. <UserOutlined />
  32. <span className="nav-text">nav 4</span>
  33. </Menu.Item>
  34. </Menu>
  35. </Sider>
  36. <Layout>
  37. <Header className="site-layout-sub-header-background" style={{ padding: 0 }} />
  38. <Content style={{ margin: '24px 16px 0' }}>
  39. <div className="site-layout-background" style={{ padding: 24, minHeight: 360 }}>
  40. content
  41. </div>
  42. </Content>
  43. <Footer style={{ textAlign: 'center' }}>Ant Design ©2018 Created by Ant UED</Footer>
  44. </Layout>
  45. </Layout>,
  46. mountNode,
  47. );
  1. #components-layout-demo-responsive .logo {
  2. height: 32px;
  3. background: rgba(255, 255, 255, 0.2);
  4. margin: 16px;
  5. }
  6. .site-layout-sub-header-background {
  7. background: #fff;
  8. }
  9. .site-layout-background {
  10. background: #fff;
  11. }

Layout布局 - 图8

固定头部

一般用于固定顶部导航,方便页面切换。

  1. import { Layout, Menu, Breadcrumb } from 'antd';
  2. const { Header, Content, Footer } = Layout;
  3. ReactDOM.render(
  4. <Layout>
  5. <Header style={{ position: 'fixed', zIndex: 1, width: '100%' }}>
  6. <div className="logo" />
  7. <Menu theme="dark" mode="horizontal" defaultSelectedKeys={['2']}>
  8. <Menu.Item key="1">nav 1</Menu.Item>
  9. <Menu.Item key="2">nav 2</Menu.Item>
  10. <Menu.Item key="3">nav 3</Menu.Item>
  11. </Menu>
  12. </Header>
  13. <Content className="site-layout" style={{ padding: '0 50px', marginTop: 64 }}>
  14. <Breadcrumb style={{ margin: '16px 0' }}>
  15. <Breadcrumb.Item>Home</Breadcrumb.Item>
  16. <Breadcrumb.Item>List</Breadcrumb.Item>
  17. <Breadcrumb.Item>App</Breadcrumb.Item>
  18. </Breadcrumb>
  19. <div className="site-layout-background" style={{ padding: 24, minHeight: 380 }}>
  20. Content
  21. </div>
  22. </Content>
  23. <Footer style={{ textAlign: 'center' }}>Ant Design ©2018 Created by Ant UED</Footer>
  24. </Layout>,
  25. mountNode,
  26. );
  1. #components-layout-demo-fixed .logo {
  2. width: 120px;
  3. height: 31px;
  4. background: rgba(255, 255, 255, 0.2);
  5. margin: 16px 24px 16px 0;
  6. float: left;
  7. }
  8. .site-layout .site-layout-background {
  9. background: #fff;
  10. }

Layout布局 - 图9

固定侧边栏

当内容较长时,使用固定侧边栏可以提供更好的体验。

  1. import { Layout, Menu } from 'antd';
  2. import {
  3. AppstoreOutlined,
  4. BarChartOutlined,
  5. CloudOutlined,
  6. ShopOutlined,
  7. TeamOutlined,
  8. UserOutlined,
  9. UploadOutlined,
  10. VideoCameraOutlined,
  11. } from '@ant-design/icons';
  12. const { Header, Content, Footer, Sider } = Layout;
  13. ReactDOM.render(
  14. <Layout>
  15. <Sider
  16. style={{
  17. overflow: 'auto',
  18. height: '100vh',
  19. position: 'fixed',
  20. left: 0,
  21. }}
  22. >
  23. <div className="logo" />
  24. <Menu theme="dark" mode="inline" defaultSelectedKeys={['4']}>
  25. <Menu.Item key="1">
  26. <UserOutlined />
  27. <span className="nav-text">nav 1</span>
  28. </Menu.Item>
  29. <Menu.Item key="2">
  30. <VideoCameraOutlined />
  31. <span className="nav-text">nav 2</span>
  32. </Menu.Item>
  33. <Menu.Item key="3">
  34. <UploadOutlined />
  35. <span className="nav-text">nav 3</span>
  36. </Menu.Item>
  37. <Menu.Item key="4">
  38. <BarChartOutlined />
  39. <span className="nav-text">nav 4</span>
  40. </Menu.Item>
  41. <Menu.Item key="5">
  42. <CloudOutlined />
  43. <span className="nav-text">nav 5</span>
  44. </Menu.Item>
  45. <Menu.Item key="6">
  46. <AppstoreOutlined />
  47. <span className="nav-text">nav 6</span>
  48. </Menu.Item>
  49. <Menu.Item key="7">
  50. <TeamOutlined />
  51. <span className="nav-text">nav 7</span>
  52. </Menu.Item>
  53. <Menu.Item key="8">
  54. <ShopOutlined />
  55. <span className="nav-text">nav 8</span>
  56. </Menu.Item>
  57. </Menu>
  58. </Sider>
  59. <Layout className="site-layout" style={{ marginLeft: 200 }}>
  60. <Header className="site-layout-background" style={{ padding: 0 }} />
  61. <Content style={{ margin: '24px 16px 0', overflow: 'initial' }}>
  62. <div className="site-layout-background" style={{ padding: 24, textAlign: 'center' }}>
  63. ...
  64. <br />
  65. Really
  66. <br />
  67. ...
  68. <br />
  69. ...
  70. <br />
  71. ...
  72. <br />
  73. long
  74. <br />
  75. ...
  76. <br />
  77. ...
  78. <br />
  79. ...
  80. <br />
  81. ...
  82. <br />
  83. ...
  84. <br />
  85. ...
  86. <br />
  87. ...
  88. <br />
  89. ...
  90. <br />
  91. ...
  92. <br />
  93. ...
  94. <br />
  95. ...
  96. <br />
  97. ...
  98. <br />
  99. ...
  100. <br />
  101. ...
  102. <br />
  103. ...
  104. <br />
  105. ...
  106. <br />
  107. ...
  108. <br />
  109. ...
  110. <br />
  111. ...
  112. <br />
  113. ...
  114. <br />
  115. ...
  116. <br />
  117. ...
  118. <br />
  119. ...
  120. <br />
  121. ...
  122. <br />
  123. ...
  124. <br />
  125. ...
  126. <br />
  127. ...
  128. <br />
  129. ...
  130. <br />
  131. ...
  132. <br />
  133. ...
  134. <br />
  135. ...
  136. <br />
  137. ...
  138. <br />
  139. ...
  140. <br />
  141. ...
  142. <br />
  143. ...
  144. <br />
  145. ...
  146. <br />
  147. ...
  148. <br />
  149. ...
  150. <br />
  151. ...
  152. <br />
  153. ...
  154. <br />
  155. ...
  156. <br />
  157. content
  158. </div>
  159. </Content>
  160. <Footer style={{ textAlign: 'center' }}>Ant Design ©2018 Created by Ant UED</Footer>
  161. </Layout>
  162. </Layout>,
  163. mountNode,
  164. );
  1. #components-layout-demo-fixed-sider .logo {
  2. height: 32px;
  3. background: rgba(255, 255, 255, 0.2);
  4. margin: 16px;
  5. }
  6. .site-layout .site-layout-background {
  7. background: #fff;
  8. }

API

  1. <Layout>
  2. <Header>header</Header>
  3. <Layout>
  4. <Sider>left sidebar</Sider>
  5. <Content>main content</Content>
  6. <Sider>right sidebar</Sider>
  7. </Layout>
  8. <Footer>footer</Footer>
  9. </Layout>

Layout

布局容器。

参数说明类型默认值
className容器 classNamestring-
hasSider表示子元素里有 Sider,一般不用指定。可用于服务端渲染时避免样式闪动boolean-
style指定样式object-

Layout.Header Layout.Footer Layout.Content API 与 Layout 相同

Layout.Sider

侧边栏。

参数说明类型默认值
breakpoint触发响应式布局的断点xs | sm | md | lg | xl | xxl-
className容器 classNamestring-
collapsed当前收起状态boolean-
collapsedWidth收缩宽度,设置为 0 会出现特殊 triggernumber80
collapsible是否可收起booleanfalse
defaultCollapsed是否默认收起booleanfalse
reverseArrow翻转折叠提示箭头的方向,当 Sider 在右边时可以使用booleanfalse
style指定样式object-
theme主题颜色light | darkdark
trigger自定义 trigger,设置为 null 时隐藏 triggerstring|ReactNode-
width宽度number|string200
onCollapse展开-收起时的回调函数,有点击 trigger 以及响应式反馈两种方式可以触发(collapsed, type) => {}-
onBreakpoint触发响应式布局断点时的回调(broken) => {}-
zeroWidthTriggerStyle指定当 collapsedWidth 为 0 时出现的特殊 trigger 的样式object-

breakpoint width

{
  xs: '480px',
  sm: '576px',
  md: '768px',
  lg: '992px',
  xl: '1200px',
  xxl: '1600px',
}