aspect-ratio - CSS: Cascading Style Sheets 编辑

The aspect-ratio  CSS property sets a preferred aspect ratio for the box, which will be used in the calculation of auto sizes and some other layout functions.

aspect-ratio: 1 / 1;

/* Global values */
aspect-ratio: inherit;
aspect-ratio: initial;
aspect-ratio: unset;

Values

<auto>
Replaced elements with an intrinsic aspect ratio use that aspect ratio, otherwise the box has no preferred aspect ratio. Size calculations involving intrinsic aspect ratio always work with the content box dimensions.
<ratio>
The box’s preferred aspect ratio is the specified ratio of width / height. Size calculations involving preferred aspect ratio work with the dimensions of the box specified by box-sizing.

Formal definition

Initial valueauto
Applies toall elements except inline boxes and internal ruby or table boxes
Inheritedno
Computed valueas specified
Animation typediscrete

Formal syntax

auto | <ratio>

Examples

Examples of values for aspect-ratio

aspect-ratio: 1 / 1;
aspect-ratio: 16 / 9;

Mapping width and height to aspect-ratio

Browsers have added an internal aspect-ratio property that applies to replaced elements and other related elements that accept width and height attributes. This appears in the browser's internal UA stylesheet. 

In Firefox, the internal stylesheet rule looks like this:

img, input[type="image"], video, embed, iframe, marquee, object, table {
  aspect-ratio: attr(width) / attr(height);
}

You can read more about this feature in Setting Height And Width On Images Is Important Again.

Specifications

SpecificationStatusComment
CSS Box Sizing Module Level 4
The definition of 'aspect-ratio' in that specification.
Editor's DraftInitial definition

Browser compatibility

BCD tables only load in the browser

See also

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

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

发布评论

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

词条统计

浏览:60 次

字数:4694

最后编辑:7 年前

编辑次数:0 次

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