Entry 02
Logical properties
Use them in place of every left, right, top and bottom, in spacing, borders, offsets and alignment.
Code
.card {
position: relative;
padding-inline: 1.5rem;
margin-block-end: 2rem;
border-inline-start: 4px solid;
text-align: start;
}
.card .close {
position: absolute;
inset-block-start: 1rem;
inset-inline-end: 1rem;
}Why it works, the rules and the credits
Why it works
inlineis the direction text runs andblockthe direction blocks stack. Start and end followdirandwriting-mode, so one set of declarations renders mirrored in a right-to-left page.
Rules
- The four-value
margin,paddingandinsetshorthands stay physical. Use the-inlineand-blockshorthands.
Support
- Chrome
- 87
- Firefox
- 66
- Safari
- 14.1
Credits
Borrowed from: Ahmad Shadeed, Digging Into CSS Logical Properties, 2021-03-10