此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

inline-size

基线
广泛可用
*

自 2020年1月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

* 此特性的某些部分的支持程度可能有所不同。

CSS 属性 inline-size 根据元素的书写模式定义了元素区块的横向或纵向尺寸。根据 writing-mode 的值,此属性对应于 widthheight 属性。

若为纵向书写模式,则 inline-size 的值对应于元素的高度;否则对应于元素的宽度。与此相关的属性为 block-size,此属性定义了元素另一方向的尺度。

尝试一下

inline-size: 150px;
writing-mode: horizontal-tb;
inline-size: 150px;
writing-mode: vertical-rl;
inline-size: auto;
writing-mode: horizontal-tb;
inline-size: auto;
writing-mode: vertical-lr;
<section class="default-example" id="default-example">
  <div class="transition-all" id="example-element">
    This is a box where you can change the inline-size.
  </div>
</section>
#example-element {
  display: flex;
  flex-direction: column;
  background-color: #5b6dcd;
  height: 80%;
  justify-content: center;
  color: #ffffff;
}

语法

css
/* <length> 值 */
inline-size: 300px;
inline-size: 25em;

/* <percentage> 值 */
inline-size: 75%;

/* 关键词值 */
inline-size: max-content;
inline-size: min-content;
inline-size: fit-content(20em);
inline-size: auto;

/* 全局值 */
inline-size: inherit;
inline-size: initial;
inline-size: revert;
inline-size: revert-layer;
inline-size: unset;

取值

inline-size 属性的取值与 widthheight 属性相同。

形式定义

初始值auto
适用元素same as width and height
是否是继承属性
Percentagesinline-size of containing block
计算值same as width and height
动画类型a length, percentage or calc();

形式语法

inline-size = 
auto |
<box-size>

<box-size> =
<length-percentage> |
stretch |
contain |
min-content |
max-content |
fit-content |
fit-content( ) |
calc-size( )

<length-percentage> =
<length> |
<percentage>

示例

以像素为单位设置行向尺寸

HTML

html
<p class="exampleText">示例文本</p>

CSS

css
.exampleText {
  writing-mode: vertical-rl;
  background-color: yellow;
  inline-size: 110px;
}

结果

规范

规范
CSS Logical Properties and Values Module Level 1
# dimension-properties
CSS Box Sizing Module Level 3
# sizing-values

浏览器兼容性

参见