Content beneath fixed AppBar(固定AppBar下的内容)
本文介绍了固定AppBar下的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能是一个基本问题,但我在文档中找不到任何示例。使用material-ui-next
Beta.30。我有以下内容:
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import * as mui from 'material-ui';
import 'typeface-roboto';
function App() {
return (
<div>
<mui.Reboot />
<mui.AppBar color="primary" position="fixed">
<mui.Toolbar>
<mui.Typography color="inherit" type="title">
My Title
</mui.Typography>
</mui.Toolbar>
</mui.AppBar>
<mui.Paper>
My Content
</mui.Paper>
</div>
);
}
ReactDOM.render(
<App />,
document.getElementById('container')
);
并且我希望mui.Paper
内容显示在AppBar下面,而不是被它隐藏。是不是我在什么地方遗漏了什么组件?
推荐答案
您的内容在屏幕上,但被AppBar
掩盖。您可以使用theme.mixins.toolbar
加载有关应用程序栏高度的信息,并相应地移动您的内容:
const styles = theme => ({
// Load app bar information from the theme
toolbar: theme.mixins.toolbar,
});
然后在您的内容上方创建div
以相应地移动您的内容:
<Paper>
<div className={classes.toolbar} />
MyContent will be shifted downwards by the div above. If you remove
the div, your content will disappear under the app bar.
</Paper>
这里发生的情况是theme.mixins.toolbar
正在将有关AppBar
维度的信息加载到您的样式中。然后,将该信息应用于div
调整div
的大小,使其正好是将内容向下移动的正确高度。
以下是完整的工作示例:
import React from 'react';
import Paper from 'material-ui/Paper';
import Reboot from 'material-ui/Reboot';
import AppBar from 'material-ui/AppBar';
import Toolbar from 'material-ui/Toolbar';
import Typography from 'material-ui/Typography';
import { withStyles } from 'material-ui/styles';
const styles = (theme) => ({
toolbar: theme.mixins.toolbar,
});
const App = (props) => {
const { classes } = props;
return (
<div>
<Reboot />
<AppBar color="primary" position="fixed">
<Toolbar>
<Typography color="inherit" type="title">
My Title
</Typography>
</Toolbar>
</AppBar>
<Paper>
<div className={classes.toolbar} />
MyContent will be shifted downwards by the div above. If you remove
the div, your content will disappear under the app bar.
</Paper>
</div>
);
}
export default withStyles(styles)(App);
这篇关于固定AppBar下的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:固定AppBar下的内容


猜你喜欢
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01