Margins not working due to *:not(style)~*:not(style)
See original GitHub issueAn 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>
Issue Analytics
- State:
- Created 3 years ago
- Reactions:14
- Comments:27 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
andpadding
. 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.
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:
From a usage standpoint, we don’t recommend adding custom margins to the children of
HStack
,VStack
orStack
.If you ever need to, then maybe you don’t need to use them and reach for
Flex
or use theshouldWrapChildren
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.