This content originally appeared on Web development blog - Manuel Matuzović and was authored by Manuel Matuzović
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.
Logical properties are a new way of working with directions and dimensions, one that allows you to control layout through logical, rather than physical mappings. This is especially useful, if you’re dealing with websites that are presented in different languages and writing modes, like right-to-left.
Physical properties
We're used to working with physical properties like margin-right
, top
, or border-left
.
ul {
display: flex;
list-style: none;
padding: 0.5rem 0;
}
li {
background-color: #6befef;
margin-right: 2rem;
}
<h3>left to right</h3>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
<h3>right to left</h3>
<ul dir="rtl">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
In right-to-left languages “One” should be positioned at the very right, but it's not because with physical properties every list item has its margin always on the right, no matter the reading direction.
- One
- Two
- Three
- One
- Two
- Three
Logical properties
Using logical properties, “One” is at the very right in right-to-left languages because logical properties don't work with the concept of top and bottom or left and right, but start and end, which may switch depending on the writing mode.
- One
- Two
- Three
- One
- Two
- Three
li {
margin-inline-end: 2rem;
}
<h3>left to right</h3>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
<h3>right to left</h3>
<ul dir="rtl">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
This content originally appeared on Web development blog - Manuel Matuzović and was authored by Manuel Matuzović
Manuel Matuzović | Sciencx (2022-09-27T09:38:54+00:00) Day 2: logical properties. Retrieved from https://www.scien.cx/2022/09/27/day-2-logical-properties/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.