Support Logical ShorthandsĀ inĀ CSS
New Post has been published on https://thedigitalinsider.com/support-logical-shorthands-in-css/
Support Logical ShorthandsĀ inĀ CSS
Thereās a bit of a blind spot when working with CSS logical properties concerning shorthands. Miriam explains:
Logical properties are a great way to optimize our sites in advance, without any real effort.
But what if we want to set multiple properties at once? This is where shorthands likeĀ marginĀ andĀ paddingĀ become useful. But they are currently limited to setting physical dimension. Logical properties are great, but they still feel like a second-class feature of the language.
There are a few 2-value shorthands that have been implemented, likeĀ margin-blockĀ for setting both theĀ -block-startĀ andĀ -block-endmargins. I find those extremely useful and concise. But the existing 4-value shorthands feel stuck in the past. Itās surprising that aĀ size shorthand canāt set theĀ inline-size, and theĀ insetĀ shorthand doesnāt includeĀ inset-block-start. Is there any way to update those shorthand properties so that they can be used to set logical dimensions?
She ends with the money question, whether we can do anything about it. Weāre currently in a position of having to choose between supporting flow-relative terms like block-start and inline-start with longhand properties and the ergonomic benefits of writing shorthand properties that are evaluated as physical terms like top, bottom, left, and right. Those of us writing CSS for a while likely have the muscle memory to adapt accordingly, but itās otherwise a decision that has real consequences, particularly for multi-lingual sites.
Note that Miriam says this is something the CSS Working Group has been working on since 2017. And thereās a little momentum to pick it up and do something about it. The first thing you can do is support Miriamās work ā everything she does with the CSS Working Group (and itās a lot) is a labor of love and relies on sponsorships, so chipping in is one way to push things forward.
The other thing you can do is chime into Miriamās proposal that she published in 2021. I think itās a solid idea. We canāt simply switch from physical to flow-relative terms in shorthand properties without triggering compatibility issues, so having some sort of higher-level instruction for CSS at the top of the stylesheet, perhaps as an at-rule that specifies which āmodeā weāre in.
<coordinate-mode> = [ logical | physical ] or [ relative | absolute ] or ... @mode <coordinate-mode>; /* must come after @import and before any style rules */ @mode <coordinate-mode> <stylesheet> selector property: value !<coordinate-mode>;
Perhaps naming aside, it seems pretty reasonable, eh?