Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add offset material-ui Grid

I'm trying to make a small 'Item added' popup dialog on material-ui using it's Grid system. But i can't figure out how to add offset to the Grid. I'm trying to achieve something similar to Bootstrap's col-sm-10 offset-1 using

<Grid container justify='center' alignItems='center' item xs={10}>

But it doesn't work. My solution was to add an empty column before and after my content, like:

<Grid item xs={1}></Grid>
<Grid item xs={10} justify='center' alignItems='center'>Content</Grid>
<Grid item xs={1}></Grid>

Do I have to do it like this? I can't figure out why justify and alignItems are not working. Here is the code on codesandbox: https://codesandbox.io/s/item-added-jx9ri

Thanks for the help!

like image 484
Cayo Eduardo Avatar asked Mar 29 '26 03:03

Cayo Eduardo


1 Answers

the best way I found this solution is as follows.

<Grid container>
    {/* offset grid with column you want to offset */}
    <Grid item lg={6} md={6} sm={6}/>
    {/* main grid column! */}
    <Grid item lg={6} md={6} sm={6}>
        I am offset column!.🔥
    </Grid>
</Grid>
like image 150
shahid jamal Avatar answered Mar 31 '26 06:03

shahid jamal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!