Technology News

Logical Properties for Useful Shorthands

Michelle Barker with my favorite sorta blog post: short, practical, and leaves you with a valuable nugget for your time. Here, she gets into logical property shorthands in CSS, particularly those that set lengths just on a single axis, say only the block (vertical) axis or just the inline (horizontal) axis.

I say “block” and ”inline” because, as far as logical properties are concerned, the x-axis could just as well behave like a vertical axis depending on the current writing-mode.

So, where we’ve always had padding, margin, and border shorthands that can support a multi-value syntax, none of them allow us to declare lengths on a specific axis without also setting a length on the other axis.

For example:

/* This gives us margin on the inline axis */
margin: 0 3rem;

…but we had to set the other axis in order to get there. With logical properties, however, we have additional shorthands for each axis meaning we can cue up the margin-inline shorthand to work specifically on the inline axis:

margin-inline: 3rem;

Michelle mentions my favorite logical property shorthand in passing. How many times do you position something to this sort of tune:

.position-me { position: absolute; top: 0; right: 0; bottom: 0; left: 0;
}

We can get those four lines into in with inset: 0. Or we could target the block and inline axis directly with inset-block and inset-inline, respectively.

While we’re talking shorthands, I always like to put a word of caution about ”accidental” CSS resets. Just one of the common CSS mistakes I make.

Direct Link →

4 Proven Ways to Get Approved for an SME Loan Quickly
How the “Move Fast” era of Facebook led to one of its biggest scandals

Related Articles

Scaling Up The Outreach Through Amazon

scaling-up-the-outreach-through-amazon
Scaling Up The Outreach Through Amazon Scaling up a business outreach is not difficult when you are offering an amazing service or product with a strong foundation. Amazon enables you…

Biden’s offshore wind plan is also a jobs plan

bidens-offshore-wind-plan-is-also-a-jobs-plan
The United States’ struggling power grid is finally getting some major upgrades. Last week, the Biden administration announced a plan that, among other efforts, will aim to bring more sources…

Zero-Width Space

zero-width-space
The name zero-width space is antithetical, but it’s not without uses. In text, maybe you’d use it around slashes because you want to be sure the words are treated individually…