A popular method for achieving this is by placing your AppBar in a sticky
position next to an element that houses the main section of your app.
Here is a typical approach (using Grid
as you are working with material-ui
):
<Grid id="whole-app" style={{ position: "relative", height: "90vh" }}>
<Grid
id="appbar"
style={{ position: "sticky", top: 0, left: 0, right: 0 }}
>
Some AppBar content
</Grid>
<Grid
id="main"
container
justify="center"
alignItems="center"
style={{ height: "inherit" }}
>
<div>Main section</div>
</Grid>
</Grid>
You can view the live example here.
The concept here is simple: we have a parent container (#whole-app
) with a specified height and positioning, with two child elements - the sticky AppBar
and the main content area. The main section container uses display: flex
(via the container
prop), has a height for vertical alignment, and utilizes props for centering its children.
In your code sandbox, there were issues because align
is not a valid Grid
prop and the spacing
prop was unnecessary.
On another note, I recommend exploring tailwindcss, which may be more beginner-friendly.