

Day 3: logical property shorthands
source link: https://www.matuzo.at/blog/2022/100daysof-day3/
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.

Day 3: logical property shorthands
posted on September 28., 2022
It’s time to get me up on speed with modern CSS. There’s so much new in CSS that I know too little about. To change that I’ve started #100DaysOfMoreOrLessModernCSS. Why more or less modern CSS? Because some topics will be about cutting-edge features, while other stuff has been around for quite a while already, but I just have little to no experience with it.
If you use a shorthand property like margin
with all 4 values, the properties will always be applied in the direction top - right - bottom - left, no matter the reading direction.
<button>Physical margin</button>
<button dir="rtl">Physical margin rtl</button>
button {
margin: 20px 40px 10px 100px;
}
/*
LTR: 20px 40px 10px 100px
RTL: 20px 40px 10px 100px
*/
This might be desired, but it could also happen that you want margin
to respect the reading direction. Logical Properties introduce 2 new shorthand properties, margin-inline
and margin-block
. These properties take 1 or 2 values.
.logical {
margin-inline: 5rem; /* start and end value (= left and right) */
margin-block: 5rem; /* start and end value (= top and bottom) */
margin-inline: 1rem 2rem; /* start / end value (= left / right in ltr) */
margin-block: 3rem 4rem; /* start / end value (= top / bottom in ltr) */
}
Unlike margin
, margin-inline
and margin-block
respect the reading direction.
<button>Logical margin</button>
<button dir="rtl">Logical margin rtl</button>
button {
margin-inline: 100px 40px; /* 100px = start/left, 40px = end/right */
margin-block: 20px 10px; /* 20px = start/top, 10px = end/bottom */
}
/*
LTR: 20px 40px 10px 100px
RTL: 20px 100px 10px 40px
*/
Further reading
Recommend
-
8
For some of the statistics we are going to study for this year’s Web Almanac we may end up needing a list of CSS shorthands and their longhands. Now this is...
-
6
-
12
Convert a given Binary tree to a tree that holds Logical AND propertySkip to content
-
6
Logical Properties for Useful Shorthands Tue Jul 19 2022 Something I like about logical properties is the...
-
4
Logical Properties for Useful Shorthands
-
4
Day 2: logical properties posted on September 27., 2022 It’s time to get me up on speed with modern CSS. There’s so much new in CSS that I know too little about. To change that I’ve...
-
9
Day 9: the inset shorthand property posted on October 6., 2022 It’s time to get me up on speed with modern CSS. There’s so much new in CSS that I know too little about. To change th...
-
4
Day 31: logical border properties posted on November 7., 2022 It’s time to get me up to speed with modern CSS. There’s so much new in CSS that I know too little about....
-
5
Day 44: logical floating and clearing posted on November 24., 2022 It’s time to get me up to speed with modern CSS. There’s so much new in CSS that I know too little ab...
-
8
List of Useful JavaScript Shorthands
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK