Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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",)

It seems they removed iconElementRight= from the api. Do we have to use the <Grid> now in the appbar? It feels kinds of cludgy. What's the right way to float buttons (e.g. login) in the appbar?

<AppBar position="static">       <Toolbar>         <Grid container spacing={24}>           <Grid item xs={11}>             <Typography type="title" color="inherit">               Title             </Typography>           </Grid>            <Grid item xs={1}>             <div>               <HeartIcon />               <Button raised color="accent">                 Login               </Button>             </div>           </Grid>         </Grid>       </Toolbar>     </AppBar> 

enter image description here

like image 649
Kyle Pennell Avatar asked Dec 07 '17 02:12

Kyle Pennell


People also ask

How do you float right in MUI?

Float Right or Left in MUI with Justify Content With display=”flex” applied to the MUI Box component, we can use justifyContent=”space-between” to move a Button to the far left and to the far right. Recall the screenshot in the intro that showed an example of this.

How do I fix my AppBar?

Just use position="sticky" instead of position="fixed" for your AppBar. Thanks! Works perfectly.

How do you put a button in the right side in material UI?

To align a component to the center or right with React Material UI, we can add a flex container with the Grid component. We add the Grid component and add the container prop to make it a flexbox container. Then we set the justify prop to flex-end to align the child components on the right side.

How do you align items in material UI?

Material-UI Grid Align Right If you need to horizontally align using only CSS, remember that justify-content horizontally aligns using the following values: flex-start: horizontally aligns left. center: horizontally aligns center. flex-end: horizontally aligns right.


1 Answers

@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> 
like image 184
Idan Dagan Avatar answered Oct 20 '22 00:10

Idan Dagan