-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Grid] Grid system spacing not creating proper gutters in v5 #31244
Comments
I have also posted a detailed question here: https://stackoverflow.com/questions/71294950/mui-v5-grid-system-spacing-not-producing-gutters-between-grid-items |
From looking at the docs, it looks like it is not ideal to apply styles directly to the I do notice though that the padding from the import * as React from "react";
import { Box, Grid, Typography } from "@mui/material";
export default function Demo() {
return (
<Box component="section">
<Typography variant="h5">Testing Spacing</Typography>
<Grid container spacing={5}>
<Grid item>
<Box sx={{ backgroundColor: "primary.dark" }}>Item 1</Box>
</Grid>
<Grid item>
<Box sx={{ backgroundColor: "primary.main" }}>Item 2</Box>
</Grid>
<Grid item>
<Box sx={{ backgroundColor: "primary.light" }}>Item 3</Box>
</Grid>
</Grid>
</Box>
);
} |
@justinrusso. Adding a |
I have tried adding a box, It didn't make a difference, but will check again. Either way, at this point I have two issues with this:
The whole point of using this is to make things easier. I will try putting a Box inside |
using |
Thank you, Yes I guess I could do that, but it just doesn't seem like a clean solution. I have decided I will just use native Grid/Flex and use the gap property. |
The prop |
Another major issue on v5 is nesting of grid rows, due to the padding top. In v4 it was possible to have a grid row nested and vertical aligned to the center, now due to the paddingTop a grid row will never be centered. |
The behavior of the MUI grid spacing is a bit unexpected since it moves the grid items to the bottom right. To keep the grid items centered you'll need to manually add paddings to the right and bottom of the container or items. |
Would you mind sharing a CodeSanbox with me? I am working on the new grid implementation and I want to make sure that it covers your case. |
Sure! So I ended up doing something similar to this: It's basically a simple wrapper that overrides the padding of the children. |
@theMyth721 Hey, we have released Grid v2 in The doc is not live but you can take a look at https://deploy-preview-33554--material-ui.netlify.app/material-ui/react-grid2/. (Here is the PR for the doc) The usage is like this: import Grid from '@mui/material/Unstable_Grid2'; |
Hi, thank you, I will try this out very soon. |
Nice! That works, how risky is to use |
I don't see any risk. I even encourage you to use the |
Please open a new issue with reproduced CodeSandbox. You can tag me and I will look into it right away. |
Duplicates
Latest version
Current behavior 😯
MUI V5 Grid doesn't create gutters. Instead when spacing is applied the entire grid overlaps other elements and the items inside the grid are squashed to the bottom.
This looks terrible. I have the basic code from my app but also have managed to reproduce it on my first code sandbox which I dont know how to use properly.
Here is the basic code:
Here are the screenshots before and after adding spacing:
Before spacing:

After adding a spacing of 5:

I have managed to reproduce this in code sandbox as well
But I am new to this so if I haven't done anything properly please let me know:
https://codesandbox.io/s/quirky-lake-50pqf5?file=/src/Demo.tsx
Expected behavior 🤔
There should be clean clear gutters between the items
Steps to reproduce 🕹
Steps:
Context 🔦
If I must provide a context, I am learning MUI to use for my react projects so Im just testing the basics.
I would expect this to work out of the box but it isn't
Most importantly, If nothing is wrong and I have just made a silly error, please do let me know what it is because I have been banging my head against the wall for hours over this.
Thank you
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: