Live data from Hacker News

Use spacer components instead of CSS margins (2020)

mxstbr.com

91–100 of 230 posts

Re: Use spacer components instead of CSS margins (2020)

#91
post #81

Needs (2020) in the title. Original discussion, 123 comments: https://news.ycombinator.com/item?id=22676442 Anyway, considered harmful articles considered harmful . There is a time and place for margins. Being thoughtful with them is a better approach than "banning margin from all components." Should I really ban the use of `margin-left: auto` when positioning my flexed elements? I don't think this article is actuall…

Out of curiosity, why do you need to use "margin-left: auto" when working with flexbox items? What is it that you're trying to do, which can't be solved with "justify-content" and "align-items"?

Not OP but I had a scenario where I had a row with a variable number of items, left-aligned, and then the final item had to be right-aligned. "margin-left: auto" on the final item achieves that effect.

Re: Use spacer components instead of CSS margins (2020)

#92
Margins are part of the specification of CSS. Banning them would be crazy.

If you don't like thinking about them, sure .. introduce the concept of spacer elements in your framework. But outlawing something because you don't fully understand its purpose isn't the way to go.

Re: Use spacer components instead of CSS margins (2020)

#93

I do agree generally, but it's funny that the suggested solution (spacers) are basically back to the old 1px transparent gif trick from the 90s/early 00s. Nothing wrong with the suggestion, but it's just ironic that we seem to be coming full circle again. Next we'll probably have posts extolling components for layouts ;)

> I do agree generally, but it's funny that the suggested solution (spacers) are basically back to the old 1px transparent gif trick from the 90s/early 00s.

They aren't the same thing. Check the link in the article [1]. It is using regular CSS, and some of those components use more modern things like Grids.

They also aren't applied between components like old element-spacers. Component Spacers have much more in common with regular margin/padding than with 90s spacers.

[1] https://seek-oss.github.io/braid-design-system/components/St...

Re: Use spacer components instead of CSS margins (2020)

#94

I do agree generally, but it's funny that the suggested solution (spacers) are basically back to the old 1px transparent gif trick from the 90s/early 00s. Nothing wrong with the suggestion, but it's just ironic that we seem to be coming full circle again. Next we'll probably have posts extolling components for layouts ;)

No post body was provided.

Re: Use spacer components instead of CSS margins (2020)

#95

Earlier quoted context omitted.

Or people could just read the very short article instead of instantly assume stuff based on the title here.

The article's own title is "Margin considered harmful" and the body finishes with the sentence "Ban margin."

The use of the ‘considered harmful’ trope should tell you al you need to know.

Re: Use spacer components instead of CSS margins (2020)

#97
post #92

Margins are part of the specification of CSS. Banning them would be crazy. If you don't like thinking about them, sure .. introduce the concept of spacer elements in your framework. But outlawing something because you don't fully understand its purpose isn't the way to go.

I would recommend reading the article, or at least the top comments here. This is not what the article is advocating.

Re: Use spacer components instead of CSS margins (2020)

#98
post #92

Margins are part of the specification of CSS. Banning them would be crazy. If you don't like thinking about them, sure .. introduce the concept of spacer elements in your framework. But outlawing something because you don't fully understand its purpose isn't the way to go.

> because you don't fully understand its purpose

How did you arrive at the conclusion that OP doesn't understand margins?

Re: Use spacer components instead of CSS margins (2020)

#99
post #72
post #62

Earlier quoted context omitted.

I did read the article and frankly it’s little better than the HN title. It’s heavily biased, fails to offer a convincing argument to anyone other than those who already believed the title, and even explicitly says margins should be banned. Simply put, it’s not a good article.

> It’s heavily biased What does "heavily biased" mean in this context? It's a straightforward article that puts forward a position, a series of propositions supporting that position, and a potential solution. It's biased in that the author has an opinion he's trying to convince people of by providing arguments in its favour, but that's what writing tends to do (including your comment). The "banning" stuff is obvious…

You’ve admitted yourself that the article is highly opinionated and full of hyperbole so I don’t really see why you’re confused by my statement. But I’ll answer your question nonetheless.

Any article stating something should be “banned” can’t really be described as a balanced discussion about the usage of that thing.

I’m all for discussions on why usage of something is bad but in the case of margins there’s clearly use cases that are suited to it, which other commenters have highlighted but which the article entirely glossed over.

So the article is more than just written as a persuasive piece; it misses any balance or contextual clarity and thus ends up dishing out bad advice as a result. Bad advice that is so strongly emphasised that lesser experienced developers would easily be intimidated by it.

Now if people want to discuss the strengths and weaknesses of margins and put forward alternative solutions in the process, that at least informs lesser experienced developers about ways to solve their real world problems rather than berating them for not following some misguided idealised view of perfection.

(Yes I know there was some details about alternative ways to implement a margin, but they were crap and lacked any detail, since the article was essentially a rant piece rather than technical document)

Re: Use spacer components instead of CSS margins (2020)

#100
post #63
post #59

Earlier quoted context omitted.

My gotcha and the negative reaction to it shows only that the majority of readers are ok w/ using of clickbait titles. That's a pity. Although bringing attention to such things always gets negative reaction in the beginning. Not the reason to stay silent anyway. > If a clickbait title will lead to higher engagement, why would an author not use it? Out of intellectual/professional honesty e.g.?

The negative reactions to your post are due to the laziness of not reading the article and the "gotcha". I think most of us come to Hacker News for interesting discussions, and the torrent of confidently incorrect "this person is wrong" comments is not adding anything to any discussion. The top comment is already clarifying the title, so any other comment should be unnecessary, especially snarky ones. The gotcha is a…

Funny and arrogant attempt to mask the problem with clickbait-ish title by turning into personal accusations in laziness, referring to memes, speaking for the rest of community, etc. The whole bag of tricks. Not gonna work, sorry. The title is wrong. Go blame the author, not the one calling out the bullshit.
Post reply on HN