Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 411
hotcakedev Avatar asked Aug 07 '20 04:08

hotcakedev


People also ask

What are material UI grids and how do they work?

By default, Material UI Grids will try to space your items perfectly evenly, so if you have something simple, like 4 grids items, each item will take up 25% of the window. But, Material UI Grids work on a 12 column grid-layout, and each grid width is a certain percentage of that.

How do I create a grid item8?

Make "item8" start on row-line 1 and column-line 2, and end on row-line 5 and column line 6: Make "item8" start on row-line 2 and column-line 1, and span 2 rows and 3 columns: The grid-area property can also be used to assign names to grid items. Named grid items can be referred to by the grid-template-areas property of the grid container.

Can you add grids to react material UI?

Material UI — Grids. We can add grids with images and text. | by John Au-Yeung | codeburst Material UI is a Material Design library made for React. It’s a set of React components that have Material Design styles. In this article, we’ll look at how to create layouts Material Design.

How do I place an item on a grid row?

To place an item, you can refer to line numbers, or use the keyword "span" to define how many columns the item will span. The grid-row property defines on which row to place an item. You define where the item will start, and where the item will end.


2 Answers

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>
like image 138
Dmytro Pastukh Avatar answered Sep 30 '22 10:09

Dmytro Pastukh


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>
like image 22
cryss Avatar answered Sep 30 '22 09:09

cryss