Let's Bring Spacer GIFs Back
joshwcomeau.com
joshwcomeau.com
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.
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
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.
Why not?
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.
Please wake me when this nonsense is over.
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?
“Modern web app development sucks” is a really tired trope.
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?
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.
But this is for us using the net before 2000.
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)
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.
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
def 1: Built using modern styles and with a modern design aesthetic.
def 2: commonly accessed as a useful destination in modern times.
Using definition 2 there are still some blogs out there that are still part of the modern web, although probably not as important as they were in their heyday. I mean definition 2 would apply to HN as well, whereas not sure if definition 1 would (it scales like a modern website should though, so maybe).
I like to let the parent layout its children in a situation like that but that's also not without its issues.
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.
It's just about creating a spacer component, which loads of component frameworks already have.
spacergif.org statistics suggest it’s spending roughly 1.5–3KB of bandwidth on each request (I haven’t bothered to go too precise, and it’d be hard to do so anyway because the traffic includes requests to things other than the GIF also). Remember that a spacer GIF is 43 bytes. (This, incidentally, is a reason to prefer GIF to PNG even now that PNG is widely supported—a spacer PNG is 65 bytes, if I recall correctly.)
Just imagine if, instead of telling you to put this in:
<img src="https://img.spacergif.org/v1/spacer.gif" width="1" height="1">
They told you to put this in: <img src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEAAAEALAAAAAABAAEAAAICTAEAOw==" width="1" height="1">
Lighter, more robust, just as developer-friendly, cheaper for them to operate (but perhaps harder to get donations or other moneys out of), and actually privacy-friendly. On that last point, spacergif.org’s privacy policy is a horror show that says “we’ll take whatever we can get our grubby little hands on, and do absolutely whatever we like with it, except that we’ll pay lip service to the law”. Certainly it’s extremely GDPR-noncompliant. <span style="display:inline-block;width:1px;height:1px"></span>Please just add margin-right to the icon that is already an actual targetable node in your DOM or skip the headache altogether by making your button display:grid & setting appropriate gutter width or something.
But the proposed idea is nothing but a showcase of everything that's wrong with "styled components only" and where it might lead you.
Well done!
Please don't.
That's also a not very great idea though. It's almost like all these ways of doing it have tradeoffs or something.