lig*_*ght 5 javascript reactjs react-router
我试图按照本指南(https://github.com/negomi/react-burger-menu)来实现react-burger-menu与react-router
我遇到的问题是菜单按钮似乎位于菜单的左侧,并且菜单似乎没有隐藏。这是它的外观的屏幕截图。
我的代码如下所示:
应用程序.js
// This component handles the App template used on every page.
import React, {PropTypes} from 'react';
import SideBar from './common/Header';
class App extends React.Component {
render() {
return (
<div className="container-fluid">
<SideBar />
{this.props.children}
</div>
);
}
}
App.propTypes = {
children: PropTypes.object.isRequired
};
export default App;
Run Code Online (Sandbox Code Playgroud)
头文件.js
import React, {PropTypes} from 'react';
import { Link, IndexLink } from 'react-router';
import {slide as Menu} from 'react-burger-menu';
import Radium from 'radium';
let RadiumLink = Radium(Link);
let RadiumIndexLink = Radium(IndexLink);
const SideBar = () => {
return (
<Menu className="bm-menu">
<RadiumIndexLink className="bm-item-list" to="/" activeClassName="active">Home</RadiumIndexLink>
<RadiumLink className="bm-item-list" to="/courses" activeClassName="active">Courses</RadiumLink>
<RadiumLink className="bm-item-list" to="/about" activeClassName="active">About</RadiumLink>
</Menu>
);
};
export default SideBar;
Run Code Online (Sandbox Code Playgroud)
样式文件
#app {
font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
color: #4d4d4d;
min-width: 550px;
max-width: 850px;
margin: 0 auto;
}
a.active {
color: orange;
}
nav {
padding-top: 20px;
padding-bottom: 20px;
}
/* Position and sizing of burger button */
.bm-burger-button {
position: fixed;
width: 36px;
height: 30px;
left: 36px;
top: 36px;
}
/* Color/shape of burger icon bars */
.bm-burger-bars {
background: #373a47;
}
/* Position and sizing of clickable cross button */
.bm-cross-button {
height: 24px;
width: 24px;
}
/* Color/shape of close button cross */
.bm-cross {
background: #bdc3c7;
}
/* General sidebar styles */
.bm-menu {
background: #373a47;
padding: 2.5em 1.5em 0;
font-size: 1.15em;
}
/* Morph shape necessary with bubble or elastic */
.bm-morph-shape {
fill: #373a47;
}
/* Wrapper for item list */
.bm-item-list {
color: #b8b7ad;
padding: 0.8em;
}
/* Styling of overlay */
.bm-overlay {
background: rgba(0, 0, 0, 0.3);
}
Run Code Online (Sandbox Code Playgroud)
为什么切换按钮出现在实际菜单的左侧,为什么实际菜单没有隐藏?如果我单击切换按钮,菜单只会向右移动更多......
将其添加到您的 CSS 中:
.bm-menu-wrap {
bottom: 0;
left: 0;
}
Run Code Online (Sandbox Code Playgroud)
这会将菜单放置在屏幕左侧。
出现在屏幕左侧的按钮是故意的,如果您希望它粘在页面上而不是在您滚动时跟随您,请更改
.bm-burger-button {
position:fixed;
}
Run Code Online (Sandbox Code Playgroud)
到
.bm-burger-button {
position:absolute;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7167 次 |
| 最近记录: |