Logical properties for sizing - CSS: Cascading Style Sheets 编辑

In this guide we will explain the flow-relative mappings between physical dimension properties and logical properties used for sizing elements on our pages.

When specifying the size of an item, the Logical Properties and Values specification gives you the ability to indicate sizing as it relates to the flow of text (inline and block) rather than physical sizing which relates to the physical dimensions of horizontal and vertical (e.g. left and right). While these flow relative mappings may well become the default for many of us, in a design you may well use both physical and logical sizing. You might want some features to always relate to the physical dimensions whatever the writing mode.

Mappings for dimensions

The table below provides mappings between logical and physical properties. These mappings assume that you are in a horizontal-tb writing mode, such as English or Arabic, in which case width would be mapped to inline-size.

If you were in a vertical writing mode then inline-size would be mapped to height.

Logical PropertyPhysical Property
inline-sizewidth
block-sizeheight
min-inline-sizemin-width
min-block-sizemin-height
max-inline-sizemax-width
max-block-sizemax-height

Width and height example

The logical mappings for width and height are inline-size, which sets the length in the inline dimension and block-size, which sets the length in the block dimension. When working in English, replacing width with inline-size and height with block-size will give the same layout.

In the live example below I have set the Writing Mode to horizontal-tb. Change it to vertical-rl and you will see that the first example — which uses width and height — remains the same size in each dimension, despite the text becoming vertical. The second example — which uses inline-size and block-size — will follow the text direction as if the entire block has rotated.

Min-width and min-height example

There are also mappings for min-width and min-height — these are min-inline-size and min-block-size. These work in the same way as the inline-size and block-size properties, but setting a minimum rather than a fixed size.

Try changing the example below to vertical-rl, as with the first example, to see the effect it has. I am using min-height in the first example and min-block-size in the second.

Max-width and max-height example

Finally you can use max-inline-size and max-block-size as logical replacements for max-width and max-height. Try playing with the below example in the same way as before.

Logical keywords for resize

The resize property sets whether or not an item can be resized and has physical values of horizontal and vertical. The resize property also has logical keyword values. Using resize: inline allows resizing in the inline dimension and resize: block allow resizing in the block dimension.

The keyword value of both for the resize property works whether you are thinking physically or logically. It sets both dimensions at once. Try playing with the below example.

Note that currently the logical values for resize are only supported by Firefox.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:94 次

字数:7122

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文