Movatterモバイル変換


[0]ホーム

URL:


  1. 面向开发者的 Web 技术
  2. CSS:层叠样式表
  3. CSS 参考
  4. 属性
  5. margin-inline

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in EnglishAlways switch to English

margin-inline

Baseline Widely available *

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

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

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

尝试一下

margin-inline: 5% 10%;writing-mode: horizontal-tb;
margin-inline: 10px 40px;writing-mode: vertical-rl;
margin-inline: 5% 10%;writing-mode: horizontal-tb;direction: rtl;
<section>  <div>    <div>One</div>    <div>Two</div>    <div>Three</div>  </div></section>
#container {  width: 300px;  height: 200px;  display: flex;  align-content: flex-start;  justify-content: flex-start;}.col {  width: 33.33%;  border: solid #ce7777 10px;  background-color: #2b3a55;  color: white;  flex-shrink: 0;}#example-element {  border: solid 10px #ffbf00;  background-color: #2b3a55;  unicode-bidi: bidi-override;}

属性构成

此属性为下列 CSS 属性的简写属性:

语法

css
/* <length> 值 */margin-inline: 10px 20px; /* 绝对长度 */margin-inline: 1em 2em; /* 相对于文本尺寸 */margin-inline: 5% 2%; /* 相对于最近区块容器的宽度 */margin-inline: 10px; /* 同时设置行首和行末值 *//* 关键词值 */margin-inline: auto;/* 全局值 */margin-inline: inherit;margin-inline: initial;margin-inline: revert;margin-inline: revert-layer;margin-inline: unset;

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

margin-inline 属性可用一个或两个值指定。

  • 一个值指定时,行首和行末应用同样的外边距。
  • 两个值指定时,第一个外边距应用于行首,第二个应用于行末

取值

margin-inline 属性的取值与margin 属性相同。

形式定义

初始值该简写所对应的每个属性:
适用元素same asmargin
是否是继承属性
Percentagesdepends on layout model
计算值该简写所对应的每个属性:
  • margin-inline-start: if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise,auto
  • margin-inline-end: if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise,auto
动画类型alength

形式语法

margin-inline =
<'margin-top'>{1,2}

<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

示例

设置行首和行末外边距

CSS

css
div {  background-color: yellow;  width: 120px;  height: auto;  border: 1px solid green;}p {  margin: 0;  margin-inline: 20px 40px;  background-color: tan;}.verticalExample {  writing-mode: vertical-rl;}

HTML

html
<div>  <p>示例文本</p></div><div>  <p>示例文本</p></div>

结果

规范

Specification
CSS Logical Properties and Values Module Level 1
# propdef-margin-inline

浏览器规范性

参见

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp