Hacker News new | ask | show | jobs
by shadowgovt 857 days ago
Having to use flexbox already feels like we're shooting a fly with an elephant gun, is the thing.

Everyone expects it to be as simple as <div centered> and everyone is surprised it isn't. That's a pretty universal experience in web development.

2 comments

`<div centered>` is the same thing as `<div read-my-mind>` since there are so many variations of what you might want. And once you generalize the solution around those variations, you have something like flexbox.

For example, what does `<div centered>` do when there are two children? And what do you do when you want the opposite behavior?

> For example, what does `<div centered>` do when there are two children?

Force me to use the advanced option or to wrap the two children in a centered container? I am certain this wouldn't cover many, many edge cases, but they are called edge cases for a reason.

Edit: People can complain about tables etc being the wrong approach all they like, in the end those examples are only proof that the proper way could be at least as simple for the average case.

It takes the sum of two children’s intrinsic sizes with a margin between them and centers the bounding rectangle as if it was a single object. Flexbox does the same, and I didn’t even think of it while writing the previous sentence. But somehow you didn’t have the same read-my-mind complaint about flexbox.
Because flexbox picks a default when you give it no configuration but it lets you configure it, so it doesn't need to read my mind and it can be wrong every time.

Now show me how you change spacing/centering behavior with the proposed <div centered> and you'll finish out the point of my previous comment.

Contrast the need to use flexbox with the ability to just specify bold or italic style, or for that matter use <b> or <i> tags. You basically get what you want every time. Nobody has to argue about whether the italicization is the right slope, and while you can select a particular font weight if you want to, bold is bold and is fine for basically everybody.

Hell, I would argue that centered table contents gave people what they wanted most of the time, and if it didn't you could fix it by adding more tables. Tables composed quite nicely and gave you something if you just laid down a table and some TDs.

Flexbox doesn't scale down the way tables do. I have to have both the container and elements inside that container and think about the ramifications of all of that. It's minimum level of complexity is a higher floor than most of the HTML specification.

That's not to say it's the wrong solution for the problem; I think a case can be made that the problem itself is irreducibly complicated. But that's why I say it feels like using an elephant gun relative to much of the rest of the spec; I have a "read my mind" option for bold and italic.

Do you want your div centered vertically? horizontally? both? Relative to what? the window? the container? These are just some of the common questions that are asked every time you need to centre something. A simple attribute cannot work.
> Relative to what? the window? the container?

I don't think I ever wanted things centered relative to anything other than the direct parent, no matter what that is. I am sure some cases need it differently, but I don't see why those should prevent intuitive defaults.

> A simple attribute cannot work

Can it not work at all or just if one insists on covering 100% of cases on the internet with a single comprehensive option? I'm not an expert in this so I'm not sure, but I've seen a lot of software center items automatically and it worked quite well because they didn't assume by default that I might push the boundaries of design to new heights at any moment.

It worked exactly that way with tables, attributes align and valign:

https://www.geeksforgeeks.org/html-td-tag/

Tables only ever "worked" when compared to the poor implementation and browser support of the alternatives of its time.

In today's web landscape using tables to center categorically fails to work in many scenarios that will work with flexbox.

They worked great and still do for the vast majority of use cases.

The fact it took over two decades to surpass is not a compliment at all. Considering "internet time" (first identified in the 90s), it's a disgrace.