【发布时间】:2021-04-30 08:59:56
【问题描述】:
我目前正在构建布局组件(导航栏、页脚和内容),它看起来像这样:
// containers/Layout/index.jsx
export default function Layout({ children }) {
const classes = useStyles();
return (
<>
<Navbar />
<main className={classes.root}>{children}</main>
<Footer />
</>
);
}
这些是样式:
// containers/Layout/styles.js
export default makeStyles((theme) => ({
root: {
minHeight: `calc(100vh - 64px - ${theme.mixins.toolbar.minHeight}px)`,
},
}));
现在我遇到了一个问题,Material-UI Toolbar 是响应式的。我的页脚是64px 高,但我的应用栏当然是动态的。
// component/Appbar/index.jsx
export default function Navbar() {
return (
<AppBar position="static">
<Toolbar />
</AppBar>
);
}
作为参考,这是 mixin 的样子:
我正在尝试获取AppBar 的当前高度,以便我可以使我的calc 函数响应。我试过使用 mixin,但它只返回正常的最小高度。另一种选择是使用媒体查询,但我不想这样做,因为媒体查询已经存在于工具栏混合中。
如何获得这个最小高度以正确适应屏幕尺寸?我的目标是始终用底部的页脚填充 100% 的屏幕,并用内容填充剩余空间。
【问题讨论】:
标签: reactjs material-ui