margin-inline-end

Baseline 廣泛可用 *

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2020 年 1 月⁩ 起,所有主流瀏覽器均已支援。

* 此特性的某些部分可能存在不同級別的支援。

margin-inline-end CSS 屬性定義了元素的邏輯行內結束外邊距,它根據元素的書寫模式、方向性和文字方向對映到一個物理外邊距。換句話說,它對應於 margin-topmargin-rightmargin-bottommargin-left 屬性,具體取決於為 writing-modedirectiontext-orientation 定義的值。

試一試

margin-inline-end: 20px;
writing-mode: horizontal-tb;
margin-inline-end: 20px;
writing-mode: vertical-rl;
margin-inline-end: 20%;
writing-mode: horizontal-tb;
direction: rtl;
<section id="default-example">
  <div id="container">
    <div class="col">One</div>
    <div class="col transition-all" id="example-element">Two</div>
    <div class="col">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
/* <length> values */
margin-inline-end: 10px; /* An absolute length */
margin-inline-end: 1em; /* relative to the text size */
margin-inline-end: 5%; /* relative to the nearest block container's width */
margin-inline-end: anchor-size(height);
margin-inline-end: calc(anchor-size(--my-anchor self-inline, 25px) / 5);

/* Keyword values */
margin-inline-end: auto;

/* Global values */
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
應用於margin 相同
繼承性
百分比取決於佈局模型
計算值如果指定為長度,則為相應的絕對長度;如果指定為百分比,則為指定值;否則為 auto
動畫型別一個長度

正式語法

margin-inline-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">Example text</p>
</div>

CSS

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

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

結果

規範

規範
CSS 邏輯屬性和值第 1 級
# margin-properties

瀏覽器相容性

另見