question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Grid] Unexpected spacing behavior

See original GitHub issue
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

In the Material UI documentation on the Grid component examples, it works fine inside the main container when using spacing

Expected Behavior 🤔

What is expected is that if I copy and paste the same example code to be able to test it will behave in the same way, but this does not work Link to codesandbox

It ends up generating a horizontal scroll.

Some solutions are given, but I don’t see these being used in the example.

  • We are using a Container component as parent

Steps to Reproduce 🕹

Steps:

  1. Copy NestedGrid code example
  2. Paste to codesandbox
  3. Run app

Context 🔦

We were building a Layout for a page and we were in doubt regarding the spacing of the Grid component since we began to have several problems with horizontal scrolling.

Our implementation is

container: {
  paddingTop: 8,
  paddingBottom: 8,
}

<Container className={classes.container}>
  <Grid container spacing={2}>
    <Grid item xs>
      ...
    </Grid>
  </Grid>
</Container>

Your Environment 🌎

Material UI v4.11.2 React v17.0.1

`npx @material-ui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @material-ui/envinfo` goes here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:37 (37 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Jan 6, 2021

But I wonder if item should only have left and top padding instead of having them on its 4 axes.

I don’t think that it matter

1reaction
povilasscommented, Jan 5, 2021

Ok example showed problem bus still you need applied half spacing size to parent https://codesandbox.io/s/new-cache-lrynu like the documentation says.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Grid] Unexpected spacing behavior #24272 - mui/material-ui
We were building a Layout for a page and we were in doubt regarding the spacing of the Grid component since we began...
Read more >
MUI - V5 Grid System spacing not producing gutters between ...
The behavior of the MUI grid spacing is a bit unexpected since it moves the grid items to the bottom right. To keep...
Read more >
Can't adjust repeat grid spacing - Adobe Support Community
The repeat grid must be selected to adjust the spacing. If it's not selected you won't be able to alter the spacing.
Read more >
MUI Grid Spacing, Padding, and Margin: A Styling Guide
The spacing prop must be applied on Grids with nested child Grid items (and it only affects the child elements); The spacing prop...
Read more >
Two flexbox & grid behaviors most people don't know about
When we use flex and grid, there are a lot of things that we know are going to happen, like getting columns and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found