block-size

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

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

尝试一下

语法

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

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

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

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

取值

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

形式定义

初始值auto
适用元素same as width and height
是否是继承属性
Percentagesblock-size of containing block
计算值same as width and height
Animation typea length, percentage or calc();

形式语法

block-size = 
<'width'>

示例

竖排文本的块向尺寸

HTML

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

CSS

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

结果

规范

Specification
CSS Logical Properties and Values Level 1
# dimension-properties
CSS Box Sizing Module Level 4
# sizing-values

浏览器兼容性

BCD tables only load in the browser

参见