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.

[Stack] Spacing overrides margin values given directly to children

See original GitHub issue

When using a Stack, it sets the mt, mr, mb or ml props of its children to value determined by spacing. Unfortunately, they cannot be overrided manually:

function Component() {
  return (
    <Stack spacing={2}>
      <Box>foo</Box>
      <Box mr={100 /* Gets overrided */}>bar</Box>
      <Box>baz</Box>
    </Stack>
  );
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
jescowuestercommented, Dec 3, 2019

To simplify the stack component we could also use sth like this instead of cloneElement:

.stack > * + * {
  margin-top: 1.5rem;
}

That way it can be easily overwritten and it would make the component more intuitive as well IMO.

Here’s a demonstration

0reactions
segunadebayocommented, Oct 23, 2019

Closing this in favor of the suggested alternative.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Stack] Spacing overrides margin values given directly to ...
We'll have to check if child.props.mr || child.props.marginRight exists and use that instead of spacing value. Alternatives. You can use % ...
Read more >
CSS adding margin to all children - DEV Community ‍ ‍
Hi. I think you should drop !important rule. Like this, it will override any other margins on any child element and that is...
Read more >
Space between Column's children in Flutter - Stack Overflow
I have a Column widget with two TextField widgets as children and I want to have some space ...
Read more >
Spacing in CSS - Ahmad Shadeed
A better solution is to cancel the unneeded spacing by adding a negative margin to the parent element. Here is what happens.
Read more >
Stack class - widgets library - Flutter - Dart API docs
A widget that positions its children relative to the edges of its box. This class is useful if you want to overlap several...
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