Day 2: logical properties

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. In the following example, list items are positioned horizontally, and each item has a right margin.

HTML:

<ul>
  <li>One</li>
  <li>Two</li>
  <li>Three</li>
</ul>

CSS:

li {
  background-color: #6befef;
  margin-right: 2rem;
}
  • One
  • Two
  • Three

The first item “One” is at the left edge of its parent element.

When you change the reading direction from right to left, you’d expect the first item to be positioned at the right edge of its parent, but it’s not because physical properties don’t change with the reading direction.

HTML:

<ul dir="rtl">
  <li>One</li>
  <li>Two</li>
  <li>Three</li>
</ul>
  • 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 switches depending on the writing mode.

HTML:

li {
  margin-inline-end: 2rem;
}
  • One
  • Two
  • Three

My blog doesn’t support comments yet, but you can reply via blog@matuzo.at.


This content originally appeared on Manuel Matuzović - Blog and was authored by Manuel Matuzović

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. In the following example, list items are positioned horizontally, and each item has a right margin.

HTML:

<ul>
  <li>One</li>
  <li>Two</li>
  <li>Three</li>
</ul>

CSS:

li {
  background-color: #6befef;
  margin-right: 2rem;
}
  • One
  • Two
  • Three
The first item “One” is at the left edge of its parent element.

When you change the reading direction from right to left, you'd expect the first item to be positioned at the right edge of its parent, but it's not because physical properties don't change with the reading direction.

HTML:

<ul dir="rtl">
  <li>One</li>
  <li>Two</li>
  <li>Three</li>
</ul>
  • 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 switches depending on the writing mode.

HTML:

li {
  margin-inline-end: 2rem;
}
  • One
  • Two
  • Three

My blog doesn't support comments yet, but you can reply via blog@matuzo.at.


This content originally appeared on Manuel Matuzović - Blog and was authored by Manuel Matuzović


Print Share Comment Cite Upload Translate Updates
APA

Manuel Matuzović | Sciencx (2022-09-27T00:00:00+00:00) Day 2: logical properties. Retrieved from https://www.scien.cx/2022/09/27/day-2-logical-properties-2/

MLA
" » Day 2: logical properties." Manuel Matuzović | Sciencx - Tuesday September 27, 2022, https://www.scien.cx/2022/09/27/day-2-logical-properties-2/
HARVARD
Manuel Matuzović | Sciencx Tuesday September 27, 2022 » Day 2: logical properties., viewed ,<https://www.scien.cx/2022/09/27/day-2-logical-properties-2/>
VANCOUVER
Manuel Matuzović | Sciencx - » Day 2: logical properties. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/09/27/day-2-logical-properties-2/
CHICAGO
" » Day 2: logical properties." Manuel Matuzović | Sciencx - Accessed . https://www.scien.cx/2022/09/27/day-2-logical-properties-2/
IEEE
" » Day 2: logical properties." Manuel Matuzović | Sciencx [Online]. Available: https://www.scien.cx/2022/09/27/day-2-logical-properties-2/. [Accessed: ]
rf:citation
» Day 2: logical properties | Manuel Matuzović | Sciencx | https://www.scien.cx/2022/09/27/day-2-logical-properties-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.