css - Material ui 将元素置于移动设备、台式机、平板电脑的底部响应式
问题描述
我是布局设计的初学者,并且正在使用React
和Material UI
. 我需要将应用导航放在底部。问题是应用程序导航位于不同的位置,具体取决于移动屏幕分辨率。(iPhone X 和 iPhone 7)。如何放置它以使其在多个移动设备上以及可能在平板电脑和台式机上响应?
const useStyles = makeStyles({
divContainer: {
display: 'flex',
alignItems: 'flex-end',
height: '99vh',
},
root: {},
});
export default function SimpleBottomNavigation() {
const classes = useStyles();
const [value, setValue] = React.useState(0);
return (
<Container className={classes.divContainer}>
<BottomNavigation
value={value}
onChange={(event, newValue) => {
setValue(newValue);
}}
showLabels
className={classes.root}
>
<BottomNavigationAction label="Home" icon={<HomeRoundedIcon />} />
<BottomNavigationAction label="Wishlist" icon={<FavoriteIcon />} />
<BottomNavigationAction
label="Add"
icon={<AddCircleOutlineRoundedIcon />}
/>
<BottomNavigationAction
label="Notifications"
icon={<NotificationsIcon />}
/>
<BottomNavigationAction
label="Profile"
icon={<AccountCircleRoundedIcon />}
/>
</BottomNavigation>
</Container>
);
}
解决方案
在中创建root
如下useStyle
:
const useStyles = makeStyles({
root: {
position: "fixed",
bottom: "0px",
left: "0px",
right: "0px",
marginBottom: "0px",
width: "100vw",
backgroundColor: "red",
}
});
然后将其作为BottomNavigation
组件的类名:
<BottomNavigation
value={value}
onChange={(event, newValue) => {
setValue(newValue);
}}
showLabels
className={classes.root}
>
然后,它将被放置在不同设备上的页面底部。
推荐阅读
- ajax - Django:在 AJAX 上将列表传递给模板的正确方法完成
- python - 根据使用 Pandas 保留其他列值的列对 DataFrame 中的日期进行排序
- mysql - 如何减小 PostgreSQL 数据库大小?
- javascript - date-fns 在 safari 上返回无效日期
- ios - iOS如何将视图添加到键盘
- javascript - 如何通过 TypeScript 或 JavaScript 映射 JSON 结构以重新格式化和删除一些不需要的元素?
- laravel - Eloquent create 说 movie_id 不存在,即使它确实存在
- carousel - 环聊聊天中的水平轮播
- google-apps-script - 如何将信息从一张纸复制到另一张纸?
- reactjs - Create carousel cards as in fb messenger in react js