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.

Margins not working due to *:not(style)~*:not(style)

See original GitHub issue

An unknown style is being applied to elements, so far I can only narrow this down to when using vStack, but I imagine its there in others too. *:not(style)~*:not(style)

Will not get the margins applied from this

    <VStack>
      <Link href="jamie" m="10rem">
        jamie
      </Link>
      <Text variant="caps3" m="10rem">
        Hello World //no margin left
      </Text>
    </VStack>

https://codesandbox.io/s/no-margin-chakra-b56vs

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:14
  • Comments:27 (8 by maintainers)

github_iconTop GitHub Comments

7reactions
TimKolbergercommented, Jan 2, 2021

Your request is technically valid - the margins are getting overridden. But from a design system perspective the current behaviour is correct. The Stack component is an approach to solve the issue “which component owns the whitespace”. It helps distributing space around nested components.

The space around nested components is not their responsibility - they should not interfere with it. This increases the reusability of the component in different contexts.

We have two tools at hand to apply whitespace: margin and padding. We have to choose wisely when to use which tool. My mindset when deciding to use margin or padding is:

  • margin is applied hierarchically from top to bottom (or outside -> inside)
  • padding is applied hierarchically from bottom to top (or inside -> outside)

E.g. when building a grid, the grid itself distributes space between its nested components with margin. Each nested component can manage its space with padding , but it should never interfere with the spacing from the hierarchy level above.

In your specific use cases, play it through which component owns which space. When the ownership is clear, the Space component will be a blessing to work with and there are no “spacing hickups” in your applications.

IMO the implementation of the Stack component needs no change, because there is no bug if you follow the mentioned design principles to ease your development workflow.

Further references:

6reactions
segunadebayocommented, Dec 11, 2020

From a usage standpoint, we don’t recommend adding custom margins to the children of HStack, VStack or Stack.

If you ever need to, then maybe you don’t need to use them and reach for Flex or use the shouldWrapChildren prop.

@with-heart, setting certain values to 0 is needed to get the responsive spacing to work.

Closing this because it isn’t a bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does this CSS margin-top style not work?
You're actually seeing the top margin of the #inner element collapse into the top edge of the #outer element, leaving only the #outer...
Read more >
margin - CSS: Cascading Style Sheets - MDN Web Docs
This property can be used to set a margin on all four sides of an element. Margins create extra space around an element,...
Read more >
margin-right does not work
In the following code, I want my box have a 10px distance from the right wall of the body (blue dashed line). However,...
Read more >
CSS margin property
The margin property sets the margins for an element, and is a shorthand property for the ... This does not happen on horizontal...
Read more >
8 Box model
The background style of the content, padding, and border areas of a box is ... These properties apply to all elements, but vertical...
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