How to add a new row for grid item in material ui?
Asked Answered
L

3

12

I am going to break a line of grid item like this. enter image description here As you can see the image, rest space of grid should be empty.

<Grid container spacing={3}
  <Grid item xs={12}>
    "Grid Item xs={12}"
  </Grid>
  <Grid item xs={4}>
    "Grid Item xs={4}"
  </Grid>
  // empty space
  <Grid item xs={12}>
    "Grid Item xs={12}"
  </Grid>
</Grid>

Should I use inner grid container? Or should I use display flex?

Longitude answered 7/8, 2020 at 4:4 Comment(0)
T
5

I created new component to solve this problem:

export const GridBreak = styled.div`
  width: 100%
`;

Then your code would look like:

<Grid container spacing={3}>
  <Grid item xs={12}>
    "Grid Item xs={12}"
  </Grid>
  <Grid item xs={4}>
    "Grid Item xs={4}"
  </Grid>
  <GridBreak />
  <Grid item xs={12}>
    "Grid Item xs={12}"
  </Grid>
</Grid>
Telegram answered 25/2, 2021 at 17:11 Comment(1)
I am not sure this is the best way to solve my problem, but it seems a good choice. so check.Longitude
B
15

I would add <Box width="100%"/>:

    <Grid container spacing={3}
      <Grid item xs={12}>
        "Grid Item xs={12}"
      </Grid>
      <Grid item xs={4}>
        "Grid Item xs={4}"
      </Grid>

      <Box width="100%"/> // empty space

      <Grid item xs={12}>
        "Grid Item xs={12}"
      </Grid>
    </Grid>
Barthold answered 24/6, 2021 at 9:52 Comment(0)
T
5

I created new component to solve this problem:

export const GridBreak = styled.div`
  width: 100%
`;

Then your code would look like:

<Grid container spacing={3}>
  <Grid item xs={12}>
    "Grid Item xs={12}"
  </Grid>
  <Grid item xs={4}>
    "Grid Item xs={4}"
  </Grid>
  <GridBreak />
  <Grid item xs={12}>
    "Grid Item xs={12}"
  </Grid>
</Grid>
Telegram answered 25/2, 2021 at 17:11 Comment(1)
I am not sure this is the best way to solve my problem, but it seems a good choice. so check.Longitude
M
3

You can just add the empty grid of xs of 8. like this:

<Grid container spacing={3}
  <Grid item xs={12}>
   "Grid Item xs={12}"
  </Grid>
 <Grid item xs={4}>
  "Grid Item xs={4}"
 </Grid>
 <Grid item xs={8}>
  // empty 
 </Grid>
 <Grid item xs={12}>
  "Grid Item xs={12}"
 </Grid>
Machute answered 7/8, 2020 at 4:8 Comment(1)
Of course, I know it works. What about case of md or another responsive size? Should I use Hidden component as well? Not that!Longitude

© 2022 - 2024 — McMap. All rights reserved.