Sub topic 2
inline-size and block-size
Assume you know the CSS box model, basic HTML, writing-mode, dir, and physical properties such as width, margin-left, and top. Logical properties describe layout relative to the text flow, so the same CSS can work in English, Arabic, and vertical writing.
inline-size and block-size
The inline axis follows the line of text. The block axis moves to the next line. In normal English text, inline is horizontal and block is vertical. In vertical-rl, inline is vertical and block is horizontal.
Use inline-size where you would normally use width, and block-size where you would normally use height.
.card {
inline-size: min(100%, 40ch);
block-size: auto;
margin-inline: auto;
}The value 40ch limits the card to about 40 characters of inline content. Its physical width or height depends on the writing mode.
Logical margin and padding
Use margin-inline and margin-block for spacing along an axis. The corresponding padding properties are padding-inline and padding-block.
.panel {
margin-block: 1rem 2rem;
padding-inline: 1.5rem;
padding-block: 1rem;
}For individual sides, use names such as margin-inline-start and padding-block-end.
Logical borders
Logical border properties follow the same axes:
.note {
border-inline-start: 4px solid steelblue;
border-block-end: 1px solid #ccc;
}In right-to-left text, border-inline-start appears on the right. In vertical text, it appears on the side that starts the inline flow.
> callout note > Do not assume “start” always means left or that “block-end” always means bottom. Writing mode and direction determine the physical side.
Positioning with inset-inline and inset-block
For positioned elements, replace left, right, top, and bottom with flow-relative inset properties.
.badge {
position: absolute;
inset-block-start: 0;
inset-inline-end: 0;
}This places the badge at the block-start and inline-end corner. In English that is usually the top right. In Arabic it is usually the top left.
Reading the two-value shorthands
Two values follow the axis, not the screen:
margin-inline: 1rem 2remmeans inline-start1rem, inline-end2rem.padding-block: 1rem 2remmeans block-start1rem, block-end2rem.inset-inline: 0 1remmeans inline-start0, inline-end1rem.
Exercise
In writing-mode: vertical-rl, which physical dimension does inline-size control?
Show answer
It controls the element's height because the inline axis runs vertically.