136 points · by thunderbong · 2y ago · 44 comments
With that in mind, which “really weird priorities” would you have deprioritized relative to this convenience?
The idea of centering an element within another is extremely basic. Something someone might want to do literally within the first 30 minutes of touching CSS for the first time and historically that person, who probably expected some evident answer instead found a 5000 vote post in stackoverflow with information on flexbox, margin auto, text align and half a dozen hacks for different situations.
Like I can do a js implementation of array.has() in a couple of minutes. I would still be shocked if it was never implemented by default and it got implemented now.
[1] https://caniuse.com/css-has
`:has()` is very clever, powerful, and has been desired for a long time. However, even if someone figured out how to implement it twenty years ago, it probably still couldn't have been used for performance reasons.
CSS nesting may have also been infeasible for performance reasons.
If your styles are defined within external stylesheets, then having to extract them from their respective stylesheets and place them directly in a noscript DOM node is not very ergonomic (and it will also affect your ability to cache those styles, since they're now a part of your potentially dynamically generated HTML rather than a static stylesheet).
> use JavaScript itself to add or remove a class that is used within the relevant selectors.
Well yeah, If you're ok with adding JS then most native CSS features can be polyfilled. This is a very imperative solution to a problem that the scripting media query handles declaratively. I would much rather have my styles dictated by my stylesheets, and reserve my JS for adding interactivity.
> However, even if someone figured out how to implement it twenty years ago, it probably still couldn't have been used for performance reasons.
Yeah the has selector is similar to a lookahead assertion in a regular expression, and CSS nesting is similar to a lookbehind (both of which can be computationally expensive). I'm not sure browsers needed to wait until the 2020s to deliver these features though. I would have loved to ditch SASS and SCSS years ago.
edit: It's in the top left, not centered horizontally or vertically.
https://caniuse.com/mdn-css_properties_align-content_block_c...
Even with all the cool layout props we have today, it’s way too complicated to say „make this thing fill the whole screen minus the navbar at the top, make it scrollable if the content overflows and Center it vertically otherwise“. Add a grid or sticky elements or z index modifications to the mix, and the quirks get loud fast.
You’re right that it’s super hard to accomplish that but you have to remember it’s also hard to accomplish that in real life if you’re mathing it out. It’s easy to look at something and put something in its center (probably not accurately but convincingly enough) but to automate it is a different case, especially when the DSL for doing so 1) must handle so many other structuring features, as you noted, 2) was originally designed for structuring text documents rather than applications, as you noted, and 3) must maintain backwards compatibility so as not to break the internet.
It’s frustrating, it is. I’m not trying to say “margin collapsing takes precedence over your minute concerns!” I’m just suggesting one reason (of perhaps many reasons) why margin: auto isn’t an effective approach.
It's amazing that this happens in 2024, CSS, you have one job!
From SGML, precursor to HTML:
> Style sheets provide the means to specify the rendering of arbitrary elements, including whether an element is rendered as block or inline.
made-by-humans: enabled