代码之家  ›  专栏  ›  技术社区  ›  MeltingDog

反应:如何让材质UI的网格间距起作用?

  •  0
  • MeltingDog  · 技术社区  · 4 年前

    https://material-ui.com/api/grid )但是,对于我的布局,当列和行工作正常时 spacing

    我已导入网格: import Grid from '@material-ui/core/Grid'

      <Grid container spacing={10}>
        <Grid item xs={12} sm={6}>
          CONTENT
        </Grid>
        <Grid item xs={12} sm={6}>
          CONTENT
        </Grid>
      </Grid>
    

    但没有出现填充。

    有人知道如何在网格中包含间距吗?

    0 回复  |  直到 4 年前
        1
  •  0
  •   Akber Iqbal    4 年前

    只是有内容在里面 <Grid> 不起作用,但如果你把它放在 <div> 或者 <Paper> 你会得到你需要的。。。

    相关的 js公司 :

    const useStyles = makeStyles(theme => ({
      root: {
        flexGrow: 1
      },
      grid: {
        textAlign: "center",
        color: theme.palette.text.secondary
      },
      span: {
        border: "1px solid pink",
        backgroundColor: "lightpink`"
      },
      span2: {
        border: "1px solid green",
        backgroundColor: "lightgreen"
      },
      span3: {
        border: "1px solid blue",
        backgroundColor: "lightblue"
      },
    }));
    
    const App = () => {
      var classes = useStyles();
    
      return (
        <div className={classes.root}>
          <Hello name="React" />
          <p>Start editing to see some magic happen :)</p>
          <br />
          <Grid container spacing={10}>
            <Grid item xs className={classes.grid}>
              <div className={classes.span}>CONTENT</div>
            </Grid>
            <Grid item xs className={classes.grid}>
              <div className={classes.span}>CONTENT</div>
            </Grid>
          </Grid>
          <hr />
          <Grid container spacing={8}>
            <Grid item xs className={classes.grid}>
              <div className={classes.span2}>CONTENT</div>
            </Grid>
            <Grid item xs className={classes.grid}>
              <div className={classes.span2}>CONTENT</div>
            </Grid>
          </Grid>
          <hr />
          <Grid container spacing={6}>
            <Grid item xs className={classes.grid}>
              <div className={classes.span3}>CONTENT</div>
            </Grid>
            <Grid item xs className={classes.grid}>
              <div className={classes.span3}>CONTENT</div>
            </Grid>
          </Grid>
        </div>
      );
    };
    

    stackblitz here

        2
  •  0
  •   Raj Kumar    4 年前

    当您使用 xs or sm ,上面的填充将在上面,所以您将得到上面的底部填充

    Grid Padding