ant-design/components/layout/demo/top-side.md

95 lines
2.4 KiB
Markdown
Raw Normal View History

---
order: 2
title:
zh-CN: 顶部-侧边布局
en-US: Header-Sider
---
## zh-CN
2017-02-27 23:39:16 +08:00
拥有顶部导航及侧边栏的页面,多用于展示类网站。
## en-US
2017-02-27 23:39:16 +08:00
Both the top navigation and the sidebar, commonly used in documentation site.
```tsx
import { Layout, Menu, Breadcrumb, MenuProps } from 'antd';
import { UserOutlined, LaptopOutlined, NotificationOutlined } from '@ant-design/icons';
2018-06-27 15:55:04 +08:00
2019-05-07 14:57:32 +08:00
const { Header, Content, Footer, Sider } = Layout;
const items1: MenuProps['items'] = ['1', '2', '3'].map(key => ({
key,
label: `nav ${key}`,
}));
const items2: MenuProps['items'] = [UserOutlined, LaptopOutlined, NotificationOutlined].map(
(icon, index) => {
const key = String(index + 1);
return {
key: `sub${key}`,
icon: React.createElement(icon),
label: `subnav ${key}`,
children: new Array(4).fill(null).map((_, j) => {
const subKey = index * 4 + j + 1;
return {
key: subKey,
label: `option${subKey}`,
};
}),
};
},
);
export default () => (
<Layout>
<Header className="header">
<div className="logo" />
<Menu theme="dark" mode="horizontal" defaultSelectedKeys={['2']} items={items1} />
</Header>
<Content style={{ padding: '0 50px' }}>
2017-10-16 20:39:53 +08:00
<Breadcrumb style={{ margin: '16px 0' }}>
<Breadcrumb.Item>Home</Breadcrumb.Item>
<Breadcrumb.Item>List</Breadcrumb.Item>
<Breadcrumb.Item>App</Breadcrumb.Item>
</Breadcrumb>
2019-12-26 12:21:08 +08:00
<Layout className="site-layout-background" style={{ padding: '24px 0' }}>
<Sider className="site-layout-background" width={200}>
<Menu
mode="inline"
defaultSelectedKeys={['1']}
defaultOpenKeys={['sub1']}
style={{ height: '100%' }}
items={items2}
/>
</Sider>
2019-05-07 14:57:32 +08:00
<Content style={{ padding: '0 24px', minHeight: 280 }}>Content</Content>
</Layout>
</Content>
2019-05-07 14:57:32 +08:00
<Footer style={{ textAlign: 'center' }}>Ant Design ©2018 Created by Ant UED</Footer>
</Layout>
2018-11-28 15:00:03 +08:00
);
2019-05-07 14:57:32 +08:00
```
2019-05-07 14:57:32 +08:00
```css
#components-layout-demo-top-side .logo {
float: left;
width: 120px;
height: 31px;
margin: 16px 24px 16px 0;
background: rgba(255, 255, 255, 0.3);
}
.ant-row-rtl #components-layout-demo-top-side .logo {
float: right;
margin: 16px 0 16px 24px;
}
2019-12-26 12:21:08 +08:00
#components-layout-demo-top-side .site-layout-background {
2019-12-26 12:21:08 +08:00
background: #fff;
}
2019-05-07 14:57:32 +08:00
```