←back to thread

Just use a button

(gomakethings.com)
285 points moebrowne | 5 comments | | HN request time: 0.201s | source
1. stack_framer ◴[] No.45775290[source]
I wonder if the "React Ry–thought-leader-guy" crowd (I love this not-so-subtle reference to Ryan Florence) preferred div over button because of the built-in styles that browsers used to apply to button elements.
replies(2): >>45775663 #>>45775951 #
2. 1-more ◴[] No.45775663[source]
This I've never gotten. It takes very little CSS to unstyle them!!
replies(1): >>45775854 #
3. exogen ◴[] No.45775854[source]
In today's world, yes. But as with a LOT of complaints about "web developers!!!!" the answer is usually "because of the way the web WAS."

Before IE became Edge (and maybe even in the earliest versions of Edge), there were certain styles and descendants that simply did not work on a <button> element, like Flexbox and Grid positioning. So, if your button had content like an icon, and you were trying to align it a certain way with the label, you simply couldn't use some features of CSS like you could with a <div>. It was a pain in the ass.

In the same vein, do you remember the period where some browsers wouldn't allow you to make a button look like a link using CSS, because they thought it might deceive people and thus be a security issue? I do.

And similarly when people complain about the complexities of webpack and bundlers in general, do you remember including the jQuery <script> tag on the page and then almost always needing to call `jQuery.noConflict()`? And how in those days, most people got even THAT wrong, because atomic <script async onload> behavior didn't work correctly in all browsers yet, so other code could actually run in between a <script> and its onload callback, meaning the jQuery.noConflict call was ineffective and something else could steal it? I remember. webpack fixed that by automatically scoping everything.

Nowadays, a lot of those workarounds are unnecessary (depends what browsers you're supporting). But it's not like there was never a reason for them.

replies(1): >>45777028 #
4. cferdinandi ◴[] No.45775951[source]
That was a big part of "thought leader guy"'s argument in favor of divs, but not the only one.
5. 1-more ◴[] No.45777028{3}[source]
A cool thing about a lot of the agency work I did early in my career is our audience was not actually the stated audience, it was the staff at the company that hired us. And one of the companies was on IE7. So yeah, I've nine-sliced a gif or two and done a few clearfixes in my time, haha. Never ran into a lot of these, but these weren't apps so much as brochures that happened to be online. Luckily enough we could control the environment pretty well to avoid actually needing noConflict() on jQuery.

But that was in 2011–'13 and things have gotten a bit easier since then and it's up to us to stay abreast of what's possible on the platform.