代码之家  ›  专栏  ›  技术社区  ›  Duncan Jones

如何在物料界面网格项中水平居中?

  •  0
  • Duncan Jones  · 技术社区  · 7 年前

    如何在材质UI网格项中居中放置元素?以下是我的React应用程序的一个片段:

    <Grid container>
      <Grid item xs={4}>
        // Unrelated stuff here
      </Grid>
      <Grid item xs={4}>
        // How do I centre these items?
        <IconButton className={classes.menuButton} color="inherit">
          <EditIcon/>
        </IconButton>
        <IconButton className={classes.menuButton} color="inherit">
          <CheckBoxIcon/>
        </IconButton>
      </Grid>
      <Grid item xs={4}>
        // Unrelated stuff here
      </Grid>
    </Grid>
    

    alignContent , justify , alignItems (致家长) <Grid item>

    我认为这将是相当简单的,但我没有找到任何关于居中网格项目内的项目的信息。

    1 回复  |  直到 7 年前
        1
  •  19
  •   Duncan Jones    7 年前

    <Grid item xs={4} style={{textAlign: "center"}}>
    </Grid>
    

    如果有其他更“正确”的方法,请随时发布另一个答案。

        2
  •  19
  •   Bhary    6 年前
     <Grid container  className = {classes.root} align = "center" justify = "center" alignItems = "center"  >
                <CssBaseline/>
                <Grid item xs = {false} sm = {4} md = {6}>
    
                </Grid>
                <Grid item xs = {12} sm = {4} md = {6}>
    
                </Grid>
            </Grid>`enter code here`
    
        3
  •  14
  •   Juan David Arce    6 年前

    这是正确的方法:

    <Grid container item xs={4} justify="center">
    

    如果container属性设置为true,那么组件将具有flex 容器行为。

    Grid API