Dock App Bar to top of window in react material ui

做~自己de王妃 提交于 2019-12-22 09:28:56

问题


In React material ui, how do you make app bar fixed so that it stays fixed while the rest of the page scrolls?


回答1:


Just add a position: fixed !important; css (inline or with external css) to your AppBar component. The !important is needed if you use external css to force overriding the style defined in material-ui. Don't forget to set margin-top to your content because it will get pushed to the top.




回答2:


Don't know if this feature is just new but you don't need the code above. Just add a position="fixed" attribute to your <AppBar />

return (
  <div className={classes.root}>
    <AppBar position="fixed">
      <Toolbar>
        <IconButton className={classes.menuButton} color="inherit" aria-label="Menu">
          <MenuIcon />
        </IconButton>
        <Typography variant="title" color="inherit" className={classes.flex}>
          Title
        </Typography>
        <Button color="inherit">Login</Button>
      </Toolbar>
    </AppBar>
  </div>
);

Adjusted example from: https://codesandbox.io/s/yw67vxwo69 (demo.js)



来源:https://stackoverflow.com/questions/43647661/dock-app-bar-to-top-of-window-in-react-material-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!