width

介绍

指定了一个元素的宽度。
默认情况下,这个属性决定的是边框区域(border-box)的宽度,但是如果将box-sizing设置为content-box, 这个属性决定的将是内容区域(content area)的高度。

取值

  • auto 默认值

  • max-content 将宽度定义为内容最大宽度。

  • <length> 将宽度定义为一个绝对值。

  • <percentage> 将宽度定义为相对包含块宽度的百分比。

  • <fit-content> 在内容最大宽度及 fit-content 定义值中取最小值。

样例:

/* <length> values */
width: 300px;
width: 25em;

/* <percentage> value */
width: 75%;

/* Keyword values */
width: max-content;
width: fit-content(20em);
width: auto;
1
2
3
4
5
6
7
8
9
10
11

标准化语法

auto | <length> | <percentage> | max-content | fit-content
1

与 Web 的区别

暂时不支持 inherit、initial、revert、unset、max-content 等取值。 默认内容区域与 web 不一致,为box-sizing:border-box;

Last Updated: 2022/7/15 下午7:22:06