1

Logical Properties for Useful Shorthands | CSS-Tricks - CSS-Tricks

 1 year ago
source link: https://css-tricks.com/logical-properties-for-useful-shorthands/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Logical Properties for Useful Shorthands

Geoff Graham on Jul 20, 2022

DigitalOcean joining forces with CSS-Tricks! Special welcome offer: get $100 of free credit.

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 →

DigitalOcean joining forces with CSS-Tricks! Special welcome offer: get $100 of free credit.

Leave a Reply Cancel reply

Comment

Name

Email

Website

Save my name, email, and website in this browser for the next time I comment.

Get the CSS-Tricks newsletter

s_23DCC53F37C675A56273FC1D596017BBDCB5DB765FF03E9E64CEC128CB81E439_1624787344817_blockandinline.png?fit=1200%2C454&ssl=1&resize=350%2C200

CSS Logical Properties and Values

Now that cross-browser support is at a tipping point, it's a good time to take a look at logical properties and values. If you're creating a website in multiple languages, logical properties and values are incredibly useful. Even if you're not, there are still some convenient new shorthands it's worth…

July 27, 2021

Creating a 3D Cube Image Gallery

The following is a guest post by Kushagra Gour (@chinchang457). Kushagra wrote to me to show me a fun interactive demo he made. It touches on many of the concepts of 3D transforms in CSS, a topic we haven't covered a ton here. So here's Kushagra taking the reins to…

August 6, 2013
rtl-ltr.png?fit=1200%2C600&ssl=1&resize=350%2C200

Building Multi-Directional Layouts

There are some new features in CSS that can assist us with building layouts for different directions and languages with ease. This article is about CSS logical properties and values (e.g. margin-inline-start).  These are a W3C working draft that still going under heavy editing, but have shipped in many browsers.…

January 23, 2020

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK