2016-05-16 10:58:34 +08:00
---
order: 4
2017-01-23 11:08:46 +08:00
title:
zh-CN: 可收起展开的侧边导航
en-US: Collapsed aside
2016-05-16 10:58:34 +08:00
---
2017-01-23 11:08:46 +08:00
## zh-CN
2016-05-16 10:58:34 +08:00
页面横向空间有限时使用。侧边导航默认收起,点击底部按钮时展开。
2017-01-23 11:08:46 +08:00
## en-US
2017-01-25 11:12:04 +08:00
This pattern is used when the horizontal space is limited. By default, Aside navigation is collapsed. You can click the button at the bottom to expand it.
2017-01-23 11:08:46 +08:00
2017-02-13 10:55:53 +08:00
````jsx
2016-05-16 10:58:34 +08:00
import { Menu, Breadcrumb, Icon } from 'antd';
2016-05-27 11:48:08 +08:00
import BrowserDemo from 'site/theme/template/BrowserDemo';
2016-05-16 10:58:34 +08:00
const SubMenu = Menu.SubMenu;
const AsideCollapse = React.createClass({
getInitialState() {
return {
collapse: true,
};
},
onCollapseChange() {
this.setState({
collapse: !this.state.collapse,
})
},
render() {
const collapse = this.state.collapse;
return (
2016-12-23 17:58:37 +08:00
< div className = {collapse ? " layout-aside layout-aside-collapse " : " layout-aside " } >
< aside className = "layout-sider" >
< div className = "layout-logo" > < / div >
2016-05-16 10:58:34 +08:00
< Menu mode = "inline" theme = "dark" defaultSelectedKeys = {['user']} >
< Menu.Item key = "user" >
2016-11-30 10:54:42 +08:00
< Icon type = "user" / >
2017-01-23 11:08:46 +08:00
{!collapse & & < span className = "nav-text" > Navigation 1< / span > }
2016-05-16 10:58:34 +08:00
< / Menu.Item >
< Menu.Item key = "setting" >
2016-11-30 10:54:42 +08:00
< Icon type = "setting" / >
2017-01-23 11:08:46 +08:00
{!collapse & & < span className = "nav-text" > Navigation 2< / span > }
2016-05-16 10:58:34 +08:00
< / Menu.Item >
< Menu.Item key = "laptop" >
2016-11-30 10:54:42 +08:00
< Icon type = "laptop" / >
2017-01-23 11:08:46 +08:00
{!collapse & & < span className = "nav-text" > Navigation 3< / span > }
2016-05-16 10:58:34 +08:00
< / Menu.Item >
< Menu.Item key = "notification" >
2016-11-30 10:54:42 +08:00
< Icon type = "notification" / >
2017-01-23 11:08:46 +08:00
{!collapse & & < span className = "nav-text" > Navigation 4< / span > }
2016-05-16 10:58:34 +08:00
< / Menu.Item >
< Menu.Item key = "folder" >
2016-11-30 10:54:42 +08:00
< Icon type = "folder" / >
2017-01-23 11:08:46 +08:00
{!collapse & & < span className = "nav-text" > Navigation 5< / span > }
2016-05-16 10:58:34 +08:00
< / Menu.Item >
< / Menu >
2016-12-23 17:58:37 +08:00
< div className = "aside-action" onClick = {this.onCollapseChange} >
2016-05-16 10:58:34 +08:00
{collapse ? < Icon type = "right" / > : < Icon type = "left" / > }
< / div >
< / aside >
2016-12-23 17:58:37 +08:00
< div className = "layout-main" >
< div className = "layout-header" > < / div >
< div className = "layout-container" >
2016-05-16 10:58:34 +08:00
< Breadcrumb >
2017-01-23 11:08:46 +08:00
< Breadcrumb.Item > Home< / Breadcrumb.Item >
< Breadcrumb.Item > App list< / Breadcrumb.Item >
< Breadcrumb.Item > Any app< / Breadcrumb.Item >
2016-05-16 10:58:34 +08:00
< / Breadcrumb >
2016-12-23 17:58:37 +08:00
< div className = "layout-content" >
2016-05-16 10:58:34 +08:00
< div style = {{ height: 220 } } >
2017-01-23 11:08:46 +08:00
Contents
2016-05-16 10:58:34 +08:00
< / div >
< / div >
< / div >
2016-12-23 17:58:37 +08:00
< div className = "layout-footer" >
2017-01-23 11:08:46 +08:00
Ant Design all rights reserved © 2015 Created by Ant UED
2016-05-16 10:58:34 +08:00
< / div >
< / div >
< / div >
);
},
});
2016-05-16 14:35:24 +08:00
2016-05-16 10:58:34 +08:00
ReactDOM.render(< BrowserDemo > < AsideCollapse / > < / BrowserDemo > , mountNode);
````
````css
2016-12-23 17:58:37 +08:00
.layout-aside {
2016-05-16 10:58:34 +08:00
position: relative;
min-height: 100%;
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-logo {
2016-05-16 10:58:34 +08:00
height: 32px;
background: #333 ;
2016-12-23 17:58:37 +08:00
border-radius: 4px;
margin: 16px 24px;
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-logo {
2016-05-16 10:58:34 +08:00
width: 32px;
margin: 16px;
2016-12-23 17:58:37 +08:00
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-sider {
2016-05-16 10:58:34 +08:00
width: 224px;
background: #404040 ;
position: absolute;
overflow: visible;
padding-bottom: 24px;
height: 100%;
2016-12-23 17:58:37 +08:00
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-sider {
2016-05-16 10:58:34 +08:00
width: 64px;
2016-12-23 17:58:37 +08:00
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-sider > .menu {
2016-05-16 10:58:34 +08:00
margin-bottom: 20px;
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-sider > .menu > .menu-item {
2016-05-16 10:58:34 +08:00
margin: 16px 0;
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-sider > .menu > .menu-item .nav-text {
2016-05-20 14:19:09 +08:00
vertical-align: baseline;
2016-05-18 11:43:40 +08:00
display: inline-block;
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-sider > .menu > .menu-item > .anticon {
2016-05-18 11:43:40 +08:00
transition: font-size .3s;
2016-05-16 14:35:24 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-sider > .menu > .menu-item {
2016-05-16 10:58:34 +08:00
transition: all 0s ease;
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-sider > .menu > .menu-item > .anticon {
2016-05-16 14:35:24 +08:00
font-size: 16px;
display: inline-block;
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-sider > .menu > .menu-item .nav-text {
2016-05-16 10:58:34 +08:00
display: none;
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-sider > .menu > .menu-item:hover {
2016-05-16 10:58:34 +08:00
background: #2db7f5 ;
color: #fff ;
transition: all 0s ease;
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-sider > .menu > .menu-item:hover .nav-text {
2016-05-16 10:58:34 +08:00
display: inline-block;
2016-05-16 14:35:24 +08:00
vertical-align: top;
2016-05-16 10:58:34 +08:00
background: #2db7f5 ;
color: #fff ;
padding-right: 16px;
border-radius: 0 5px 5px 0;
}
2016-05-16 14:35:24 +08:00
/* 实际使用中需要改成 position: fixed */
2016-12-23 17:58:37 +08:00
.layout-aside .aside-action {
2016-05-16 10:58:34 +08:00
height: 42px;
width: 224px;
position: absolute;
bottom: 0;
background: #656565 ;
color: #fff ;
text-align: center;
line-height: 42px;
cursor: pointer;
2016-12-23 17:58:37 +08:00
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .aside-action {
2016-05-16 10:58:34 +08:00
width: 64px;
2016-12-23 17:58:37 +08:00
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-header {
2016-05-16 10:58:34 +08:00
background: #fff ;
height: 64px;
border-bottom: 1px solid #e9e9e9 ;
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-main {
2016-05-16 10:58:34 +08:00
margin-left: 224px;
2016-12-23 17:58:37 +08:00
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-main {
2016-05-16 10:58:34 +08:00
margin-left: 64px;
2016-12-23 17:58:37 +08:00
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-container {
margin: 12px 16px 24px;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-content {
2016-05-16 10:58:34 +08:00
background: #fff ;
padding: 24px;
2016-12-23 17:58:37 +08:00
margin-top: 12px;
border-radius: 4px;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-footer {
2016-05-16 10:58:34 +08:00
height: 64px;
line-height: 64px;
text-align: center;
font-size: 12px;
color: #999 ;
background: #fff ;
border-top: 1px solid #e9e9e9 ;
width: 100%;
}
````