margin-inline-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.

margin-inline-end CSS 属性定义元素的逻辑行末外边距,根据元素的书写模式、行内方向和文本朝向映射为实体外边距。换句话说,它根据 writing-modedirectiontext-orientation 属性的值对应于 margin-topmargin-rightmargin-bottommargin-left 属性。

尝试一下

语法

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

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

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

这个属性与 margin-block-startmargin-block-endmargin-inline-start 属性相关,它们均定义元素的其他边距。

margin-inline-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-inline-end = 
<'margin-top'>

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

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

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

<anchor-element> =
<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-lr;
  margin-inline-end: 20px;
  background-color: #c8c800;
}

结果

规范

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

浏览器兼容性

BCD tables only load in the browser

参见