Margin is generally more desirable than padding imo. Component/element knows the content it contains and uses margins to require a minimum amount of spacing. It avoids the need to make decisions on the spacing between every combination of components. Padding only works if you know everywhere your component might be used or don't mind remaking spacing decisions every time you use it. In my experience minimizing code n…
Use spacer components instead of CSS margins (2020)
41–50 of 230 posts
Re: Use spacer components instead of CSS margins (2020)
#42Earlier quoted context omitted.
Then the title of the article is misleading and should be changed to avoid confusion
or you could maybe read the article before looking at its source code for a gotcha?
Re: Use spacer components instead of CSS margins (2020)
#43Edit: The amount of oscillation this comment has had (between -1 and +1) is amazing, I wish I could see total number of up and downvotes..
Re: Use spacer components instead of CSS margins (2020)
#44Quoted post unavailable.
We may, as engineers, use tools that internally implement software patterns that we have an academic disagreement with. And that doesn't make us any less dignified in our beliefs.
Re: Use spacer components instead of CSS margins (2020)
#45Re: Use spacer components instead of CSS margins (2020)
#46A more accurate title for this blog post would be “Ban Outer CSS Margins from Components”.
Re: Use spacer components instead of CSS margins (2020)
#47Re: Use spacer components instead of CSS margins (2020)
#48Margin is generally more desirable than padding imo. Component/element knows the content it contains and uses margins to require a minimum amount of spacing. It avoids the need to make decisions on the spacing between every combination of components. Padding only works if you know everywhere your component might be used or don't mind remaking spacing decisions every time you use it. In my experience minimizing code n…
The author is arguing exactly that: remake spacing decisions every time you use a component, because that’s what many designers (most?) do. This is also true in my experience.
Moreover,
> Margin breaks component encapsulation. A well-built component should not affect anything outside itself.
Definitely not, margins are an essential part of a component, like a garden around a house, and they make components "usable in any context or layout" (unless the context or layout is stupidly overcomplicated).
Re: Use spacer components instead of CSS margins (2020)
#49I think the main bugbear of margins that the article doesn't mention is margin collapse: I personally don't find the rules super intuitive and I would rather just be explicit with spacing than have the browser collapse things together!
Re: Use spacer components instead of CSS margins (2020)
#50Flutter does this, and its layout model is quite well thought.