There are logical properties for width and height values.
width and height
The logical alternative for width is inline-size and the alternative for height is block-size. Here’s an example of how using inline-size over width makes a difference.
If you use width, the property sets the physical width, regardless of the writing mode.
h1 {
border: 1rem solid;
padding: 1rem;
width: 16rem;
}
.vertical {
writing-mode: vertical-rl;
}
<h1>width horizontal</h1>
<h1 class="vertical">width vertical</h1>
width horizontal
width vertical
If you use inline-size, the property sets the logical width with respect to the writing mode.
h1 {
border: 1rem solid;
padding: 1rem;
inline-size: 16rem;
}
.vertical {
writing-mode: vertical-rl;
}
inline-size horizontal
inline-size vertical
vi and vb
There are also logical unit alternatives for vw and vh.
The width and height of the <div> is always the width and height of the viewport, regardless of the writing mode.
div {
border: 1rem solid;
width: 20vw;
height: 40vh;
}
.vertical {
writing-mode: vertical-rl;
}
vw + vh
vw + vh
The width and height of the <div> matches either the vertical or horizontal dimensions of the viewport, depending on the writing mode.
div {
border: 1rem solid;
width: 20vi;
height: 40vb;
}
vi + vb
vi + vb
50vwalternative:50vi50vhalternative:50vb50dvhalternative:50dvb50svhalternative:50svb50lvhalternative:50lvb
My blog doesn't support comments yet, but you can reply via blog@matuzo.at.
