块级大小
**block-size
** CSS 属性定义元素块的水平或垂直大小,具体取决于其书写模式。它对应于 width
或 height
属性,具体取决于 writing-mode
的值。
如果书写模式是垂直方向,则 block-size
的值与元素的宽度有关;否则,它与元素的高度有关。相关属性是 inline-size
,它定义元素的另一个维度。
试一试
语法
css
/* <length> values */
block-size: 300px;
block-size: 25em;
block-size: anchor-size(height);
block-size: calc(anchor-size(--myAnchor block) * 0.75);
/* <percentage> values */
block-size: 75%;
/* Keyword values */
block-size: max-content;
block-size: min-content;
block-size: fit-content;
block-size: fit-content(20em);
block-size: auto;
/* Global values */
block-size: inherit;
block-size: initial;
block-size: revert;
block-size: revert-layer;
block-size: unset;
值
正式定义
正式语法
block-size =
<'width'>
<width> =
auto |
<length-percentage [0,∞]> |
min-content |
max-content |
fit-content( <length-percentage [0,∞]> ) |
<calc-size()>
<length-percentage> =
<length> |
<percentage>
<calc-size()> =
calc-size( <calc-size-basis> , <calc-sum> )
<calc-size-basis> =
<intrinsic-size-keyword> |
<calc-size()> |
any |
<calc-sum>
<calc-sum> =
<calc-product> [ [ '+' | '-' ] <calc-product> ]*
<calc-product> =
<calc-value> [ [ '*' | '/' ] <calc-value> ]*
<calc-value> =
<number> |
<dimension> |
<percentage> |
<calc-keyword> |
( <calc-sum> )
<calc-keyword> =
e |
pi |
infinity |
-infinity |
NaN
示例
带垂直文本的块大小
HTML
html
<p class="exampleText">Example text</p>
CSS
css
.exampleText {
writing-mode: vertical-rl;
background-color: yellow;
block-size: 200px;
}
结果
规范
规范 |
---|
CSS 逻辑属性和值级别 1 # dimension-properties |
CSS 盒子大小模块级别 4 # sizing-values |
浏览器兼容性
BCD 表格仅在启用 JavaScript 的浏览器中加载。
另请参阅
- 映射的物理属性:
width
和height
writing-mode