Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

reactjs - Does Material UI Grid Item require defined breakpoints on positional properties ? (textAlign / text-align in my case)

extension to this question: How to horizontally center an item in Material UI grid item?

I've noticed this behavior but I was unable to find corresponding explanation in my look into the Grid documentation for material UI

in essence, I have a button within a grid item that is in a grid container that I am trying to center. It looks like this

      <Grid container>
    <Grid item xs={9}>
    </Grid>
    <Grid item xs={3}>
          <Grid item xs={12} style={{textAlign: "center"}}>
            <Button>Create a Post</Button>
          </Grid>
    </Grid>
  </Grid>

The code above only runs because I provided the breakpoint of xs={12}, without which it would refuse to center the element.

My question being, is this a requirement that I provide a breakpoint when I attempt to center elements?

question from:https://stackoverflow.com/questions/65869121/does-material-ui-grid-item-require-defined-breakpoints-on-positional-properties

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First of all, give your Element inside a grid a fullWidth property, otherwise it is not going to display as you wish.
By default your element is not centered inside of grid, so yes, you need to provide some styles. No need to make a grid inside of another grid. If you fork your code in sandbox, I can help more.

<Grid item xs={3}  style={{//center here, using flexbox or something else}}>          
   <Button fullWidth>Create a Post</Button>          
</Grid>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...