margin-block-end

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2021.

* Some parts of this feature may have varying levels of support.

CSS 属性 margin-block-end 定义了元素的逻辑块末外边距,并根据元素的书写模式、行内方向和文本朝向对应至实体外边距。

尝试一下

语法

css
/* <length> 值 */
margin-block-end: 10px; /* 绝对长度 */
margin-block-end: 1em; /* 相对于文本尺寸 */
margin-block-end: 5%; /* 相对于最近区块容器的宽度 */

/* 关键词值 */
margin-block-end: auto;

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

根据 writing-modedirectiontext-orientation 所定义的值,此属性对应于 margin-topmargin-rightmargin-bottommargin-left 属性。

与此属性相关的有 margin-block-startmargin-inline-startmargin-inline-end 等定义元素的其他外边距的属性。

取值

margin-block-end 属性的取值与 margin-left 属性相同。

形式定义

初始值0
适用元素same as margin
是否是继承属性
Percentagesdepends on layout model
计算值if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, auto
动画类型a length

形式语法

margin-block-end = 
<'margin-top'>

<margin-top> =
<length-percentage> |
auto |
<anchor-size()>

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

<anchor-size()> =
anchor-size( [ <anchor-name> || <anchor-size> ]? , <length-percentage>? )

<anchor-name> =
<dashed-ident>

<anchor-size> =
width |
height |
block |
inline |
self-block |
self-inline

示例

设置块末外边距

HTML

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

CSS

css
div {
  background-color: yellow;
  width: 120px;
  height: 120px;
}

.exampleText {
  writing-mode: vertical-rl;
  margin-block-end: 20px;
  background-color: #c8c800;
}

结果

规范

Specification
CSS Logical Properties and Values Level 1
# margin-properties

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
margin-block-end
anchor-size()
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
In development. Supported in a pre-release version.
In development. Supported in a pre-release version.
No support
No support
Experimental. Expect behavior to change in the future.

参见