margin-inline CSS shorthand property is a shorthand property that defines both the logical inline start and end margins of an element, which maps to physical margins depending on the element's writing mode, directionality, and text orientation.

/* <length> values */
margin-inline: 10px 20px;  /* An absolute length */
margin-inline: 1em 2em;    /* relative to the text size */
margin-inline: 5% 2%;      /* relative to the nearest block container's width */
margin-inline: 10px;       /* sets both start and end values */
/* Keyword values */
margin-inline: auto;
/* Global values */
margin-inline: inherit;
margin-inline: initial;
margin-inline: unset;
					

This property corresponds to the margin-top and margin-bottom ,或 margin-right ,和 margin-left properties, depending on the values defined for writing-mode , direction ,和 text-orientation .

组成特性

此特性是下列 CSS 特性的简写:

句法

margin-inline property takes the same values as the margin-left 特性。

形式定义

初始值 0
适用于 如同 margin
继承 no
百分比 depends on layout model
计算值 if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, auto
动画类型 discrete

形式句法

<'margin-left'>{1,2}
					

范例

Setting inline start and end margins

HTML

<div>
  <p class="exampleText">Example text</p>
</div>
					

CSS

div {
  background-color: yellow;
  width: 120px;
  height: 120px;
}
.exampleText {
  writing-mode: vertical-rl;
  margin-inline: 20px 40px;
  background-color: #c8c800;
}
					

结果

规范

规范 状态 注释
CSS Logical Properties and Values Level 1
The definition of 'margin-inline' in that specification.
编者草案 初始定义。
初始值 0
适用于 如同 margin
继承 no
百分比 depends on layout model
计算值 if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, auto
动画类型 discrete

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
margin-inline Chrome 完整支持 69 Disabled
完整支持 69 Disabled
Disabled ). To change preferences in Chrome, visit
Edge 完整支持 79 Disabled
完整支持 79 Disabled
Disabled From version 79: this feature is behind the Experimental Web Platform features preference (needs to be set to 启用 ).
Firefox 完整支持 66 IE 不支持 No Opera 完整支持 56 Safari 不支持 No WebView Android 完整支持 69 Chrome Android 完整支持 69 Disabled
完整支持 69 Disabled
Disabled ). To change preferences in Chrome, visit
Firefox Android 完整支持 66 Opera Android 完整支持 48 Safari iOS 不支持 No Samsung Internet Android 完整支持 10.0

图例

完整支持

完整支持

不支持

不支持

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改: