Readit News logoReadit News
perilunar · 5 years ago
Let's not.

This is a huge amount of unnecessary code just to add some whitespace.

Instead you could just directly add a whitespace character between the icon and the text, e.g. a non-breaking space ( ), and en-space ( ), or an em-space ( ). Or just add a right margin to the icon — there's no need for an extra wrapper element.

cookiengineer · 5 years ago
Let's not use space characters in the markup.

Instead, use "white-space: nowrap" [1] in CSS.

Well, or just read up on the display box model in the first place.

[1] https://developer.mozilla.org/en-US/docs/Web/CSS/white-space

perilunar · 5 years ago
"white-space: nowrap" just stops line wrapping — it won't add a space that doesn't already exist in the source code.

The cleanest way to add whitespace in this situation is to add a right margin to the icon. The quickest way is to add an HTML character entity. The lightest way is to add a single unicode space character before the text.

1_player · 5 years ago
> Let's not use space characters in the markup.

Why not?

rado · 5 years ago
Yes, my first thought was  
FriedrichN · 5 years ago
> This is a huge amount of unnecessary code just to add some whitespace.

Only if you use the whole React nonsense. You could just make a CSS class and use that on <span> elements to use as spacer elements. That's hardly 'a huge amount' of code.

iamleppert · 5 years ago
This is everything on how the modern web is a complete disaster. We need react and a 30+ line “component” to represent what used to be a single html tag.

Please wake me when this nonsense is over.

Griffinsauce · 5 years ago
The article doesn't make any argument that you need react. It just happens to be what the author uses. (yes he assumes that you do as well but come on, you can translate it to whatever you're doing)

Also, the flexibility described will not fit in a single tag - what tag exactly did you mean?

I personally prefer gap-style solutions like a Stack component or something like Tailwind's `space` classes (both using an owl-selector to set margins on children).

Either way, margin is tricky in a components-based world because it often breaks the encapsulation. I see this as just an exploration of an option to solve that, do we really need to be this dismissive of exploration?

oatmealsnap · 5 years ago
I thought this was a parody post.
tlrobinson · 5 years ago
And yet somehow developers are more productive and build better web apps than ever.

“Modern web app development sucks” is a really tired trope.

martin_a · 5 years ago
> build better web apps than ever

Is this really true? Most apps and websites are broken in one way or another, terribly slow on older devices or connections and sometimes break for unknown reasons.

They look better, yes, but are they really that much better in a complexity to function ratio?

TeMPOraL · 5 years ago
> And yet somehow developers are more productive and build better web apps than ever.

Only if you ask the developers themselves. They sure feel that way. Ask their bosses, or hell, ask users what they feel about the modern web, and the answer may start to differ.

type0 · 5 years ago
Mobile first web development leaves many sites unusable on the desktop, this includes banking sites where you can't see the whole row of numbers when entering accounts, how is that not broken. Clueless developers using myriads of JS frameworks doesn't make "better web apps than ever" ever.

Deleted Comment

tlrobinson · 5 years ago
Spacer components are great.

They’re very obvious when reading code why they’re there. You don’t have to think about whether margin or padding makes more sense, and which element it should belong on. No one is reading your perfectly crafted semantic HTML anyway. Screen readers don’t care about an empty span.

And apparently they really bother the “get off my lawn” types on Hacker News.

My preferred API is allowing one of 3 props: “size”, “width”, or “height” (because including both “size” and “axis” is pretty verbose)

8lall0 · 5 years ago
I care because it's cognitive overhead, i MUST know what the "spacer" does and how it does, instead of having a simple margin or padding which works so well when you set box-sizing: border-box.
memco · 5 years ago
If the semantics of margin really are a problem as the article suggests why not use a css grid with a gap? Surely creating a JS component just to add a small gap is a more egregious semantic violation? I would argue that the icon is a visual only element and so the element should render correctly with no icon and the icon should add the necessary space to separate itself from the text.
vages · 5 years ago
He commented on this in the "What about `gap`?" info box.

I want to add that gap does not work well when you want different gaps between different items; then you have to whip out margins again.

krsdcbl · 5 years ago
... or pass a class to the component variant and set an according gap?

Adding a dedicated node with it's own properties to adjust width of whitespace is nowhere a better solution than just adding a css class

dharmab · 5 years ago
Fun fact: HN uses spacer gifs to indent comment replies.
jonah-archive · 5 years ago
I recommend that everyone go check out Sian Bahram’s 2016 talk on computing while blind. At around 6:30 he specifically addresses how inaccessible HN is to a visually impaired user: https://www.youtube.com/watch?v=G1r55efei5c
pixelbath · 5 years ago
I find it interesting that not a single problem mentioned in the talk has been addressed on the site in the intervening 5 years.
edflsafoiewq · 5 years ago
Yup, you can spot them easily if you select a bunch of text.
shadowofneptune · 5 years ago
And Paul Graham's page uses them extensively. Only places on the modern web where I see them used.
jedberg · 5 years ago
I wouldn't call PGs page an example of the modern web. And I doubt he would either. :)

Deleted Comment

nxpnsv · 5 years ago
Proper developers indent their code with gifs rather than tabs or spaces.
onion2k · 5 years ago
It feels like the author has read a lot of very sound arguments against using margins in component systems (they leak, they collapse, etc) and has taken those arguments to mean "never use margins". I don't see a good reason to avoid margins in the specific "icon and label" example.
Griffinsauce · 5 years ago
It's a bit contrived but say both the icon and the text element are components. Now you need to find a solution.

I like to let the parent layout its children in a situation like that but that's also not without its issues.

onion2k · 5 years ago
It's a bit contrived but say both the icon and the text element are components. Now you need to find a solution.

There are solid arguments not to use margins with components, but that's not what the article is about. In the example in the article using margin is fine.

krsdcbl · 5 years ago
Specially as margin collapse is a thing that only affects vertical margins on blocks. The "icon has margin right if something comes after it" is perfectly solveable with even CSS 2.1
Xevi · 5 years ago
The title is clickbait, since the article is actually NOT about bringing back spacer GIFs.

It's just about creating a spacer component, which loads of component frameworks already have.

krsdcbl · 5 years ago
which essentially is just the same, spacer gifs aren't inherently bad because they're a gif, but because they're an empty DOM node used to handle presentational attributes
Xevi · 5 years ago
I was just pointing out that the article wasn't about bringing back gif spacers. It's actually about using normal css spacers, which is pretty much the standard nowadays across a lot of component libraries. This makes the article a lot less interesting.