What's the right way to float right or left using the material-ui appbar with material-ui-next?

前端 未结 2 2025
无人共我
无人共我 2021-02-01 12:35

I can\'t figure out if I\'m using the right approach to get the login/logout buttons to float right in while using material-ui-next (\"material-ui\": \"^1.0.0-beta.22\",)

<
相关标签:
2条回答
  • 2021-02-01 12:44

    You need to add flex: 1 to your <Typography /> component so it pushes the <div /> to the rightmost part of the AppBar:

    <AppBar position="static">
      <Toolbar>
        <Typography type="title" color="inherit" style={{ flex: 1 }}>
          Title
        </Typography>
        <div>
          <HeartIcon />
          <Button raised color="accent">
            Login
          </Button>
        </div>
      </Toolbar>
    </AppBar>
    
    0 讨论(0)
  • 2021-02-01 12:54

    @Kyle You had it right :)

    just add to the grid container:

    justify="space-between"

    With your example:

    <AppBar position="static">
      <Toolbar>
        <Grid
          justify="space-between" // Add it here :)
          container 
          spacing={24}
        >
          <Grid item>
            <Typography type="title" color="inherit">
              Title
            </Typography>
          </Grid>
    
          <Grid item>
            <div>
              <HeartIcon />
              <Button raised color="accent">
                Login
              </Button>
            </div>
          </Grid>
        </Grid>
      </Toolbar>
    </AppBar>
    
    0 讨论(0)
提交回复
热议问题