4 ms·
CSS adds vertical centering in 2024
- superkuh 2y agoIt's kind of funny seeing center-aligned "align-content just works!" aligned-left within the div in Firefox ESR. This is definitely a bleeding edge feature but a welcome one. It'll be some years before I chose to use it. edit: It's in the top left, not centered horizontally or vertically.
- atoav 2y agoYou do realize this is about vertical alignment, right?
- pinkmuffinere 2y agoPer the article, _align_ is for vertical distribution, and _justify_ is for horizontal. The example is actually behaving correctly. The naming is confusing though, imo
- red_trumpet 2y agoWell, to center the text in flow layout, you would use text-align:center;
- superkuh 2y agoAh! Thanks for the correction. Unfortunately it's not centered vertically either. It's in the top left.
- pinkmuffinere 2y agoOh lol that’s not great
- cabbageicefruit 2y agoFirefox has supported this since 125. So if you are on ESR 128 it should work fine https://caniuse.com/mdn-css_properties_align-content_block_context https://caniuse.com/mdn-css_properties_align-content_block_c...
- deleted 2y ago[deleted]
- telios 2y agoThat is what the article claims, but... I see it as left-aligned. Firefox 129.0.1 on MacOS.
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]
- chimert 2y agoThis was already a feature for flex box and grid. They’re just adding this to flow layout. Still a welcome addition but consider that all browsers that add support for this will already have support for flex and grid.
- steve_adams_86 2y agoYes, but imagine if you're new to CSS how unintuitive and annoying it is that you need to figure out what display modes mean and how they behave in order for a property like `align-content` to work as expected? That's a weird thing about css in my opinion.
- squidbeak 2y agoBizarre that a statement of fact is being voted down.
- robinson7d 2y agoDidn’t downvote (can’t even downvote, wouldn’t anyway), but if I were to guess it’s that the article talks about it fairly extensively.
- deathanatos 2y agoYeah … but that's also what makes the title clickbait — that the article itself knows that what is written isn't true. "CSS makes vertical centering easier in 2024" or just "CSS makes vertical centering easier" would have been more honest, I think.
- politelemon 2y agoThe article already addresses this. The point is to have the feature exist without having to know about flexbox/grid (or history).
- cloudking 2y agoLearning flex box has great ROI for saving your time and sanity wrangling CSS.
- lelandfe 2y agoWhy don’t top and bottom `auto` margins center things?
- wryoak 2y agoDoesn’t seem like that would play nice with margin collapsing, like what if you had two box elements with that style that would otherwise undergo margin collapsing, how should they render? What’s the baseline margin to combine if they should collapse and what’s the baseline margin to separate them if they shouldn’t?
- 9dev 2y agoJust let me opt out of margin collapsing. That may be helpful if we’re dealing with paragraphs on a long piece of prose, but that’s decidedly not what I’m dealing with 95% of the time. 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.
- wryoak 2y agoYou can use flex or grid to opt out of margin collapsing and get your easy center alignments and justifications. 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.
- ffsm8 2y ago
- phkahler 2y agoIt seems odd that "style sheets" turned into layout language. ;-)
- benatkin 2y agoAlways has been. 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. https://www.w3.org/TR/WD-html40-970708/intro/sgmltut.html https://www.w3.org/TR/WD-html40-970708/intro/sgmltut.html
- thiht 2y agoThat’s the whole point yeah
- lofaszvanitt 2y agoCSS has finally arrived. Only took 20 years. Now remove the syntax bloat with something like: made-by-humans: enabled
- CM30 2y agoStill surprised it took so long. Feels like the folks working on CSS have some really weird prioritites when it comes to deciding what to work on and what to add.
- eyelidlessness 2y agoVertical centering has been trivial in numerous ways for many years. At least since flexbox. This is mostly a convenience to achieve what flexbox already did, with a simpler (albeit more error prone) imposition on document structure. With that in mind, which “really weird priorities” would you have deprioritized relative to this convenience?
- The_Colonel 2y agoIndeed, since at least 1997, when HTML 3.2 standardized tables.
- Levitz 2y agoI don't think it's fair to dismiss something as "convenience". Convenience is very important in development, convenience is the reason we use CSS to begin with. 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.
- eyelidlessness 2y agoAll of what you say is reasonable, as written. But I also don’t think it’s fair to characterize my comment as dismissing convenience. I think “really weird priorities” is a strong claim, and I think it deserves perspective and warrants questioning.
- 2y ago
- DonHopkins 2y agoBut what about all the Vertical Centering as a Service providers that is going to put out of business??!
- dylan604 2y agoThey can pry my flex box from my cold dead fingers
- nsonha 2y ago> It’s amazing that CSS finally has a single property to control vertical align It's amazing that this happens in 2024, CSS, you have one job!
- deleted 2y ago[deleted]