shape-margin

Baseline Widely available

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

shape-marginCSS のプロパティで、shape-outside を使用して作成された CSS シェイプのマージンを設定します。

試してみましょう

マージンで、シェイプ (浮動要素) の縁と周囲のコンテンツとの間隔を調整することができます。

構文

css
/* <length> 値 */
shape-margin: 10px;
shape-margin: 20mm;

/* <percentage> 値 */
shape-margin: 60%;

/* グローバル値 */
shape-margin: inherit;
shape-margin: initial;
shape-margin: revert;
shape-margin: unset;

<length-percentage>

シェイプのマージンを <length> 値または要素の包含ブロックの幅に対する <percentage> で設定します。

公式定義

初期値0
適用対象浮動要素
継承なし
パーセント値包含ブロックの幅に対する相対値
計算値指定通り。ただし相対的な長さはは絶対的な長さに変換される
アニメーションの種類length または パーセント値, calc();

形式文法

shape-margin = 
<length-percentage [0,∞]>

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

多角形にマージンを追加

HTML

html
<section>
  <div class="shape"></div>
  We are not quite sure of any one thing in biology; our knowledge of geology is
  relatively very slight, and the economic laws of society are uncertain to
  every one except some individual who attempts to set them forth; but before
  the world was fashioned the square on the hypotenuse was equal to the sum of
  the squares on the other two sides of a right triangle, and it will be so
  after this world is dead; and the inhabitant of Mars, if one exists, probably
  knows its truth as we know it.
</section>

CSS

css
section {
  max-width: 400px;
}

.shape {
  float: left;
  width: 150px;
  height: 150px;
  background-color: maroon;
  clip-path: polygon(0 0, 150px 150px, 0 150px);
  shape-outside: polygon(0 0, 150px 150px, 0 150px);
  shape-margin: 20px;
}

結果

仕様書

Specification
CSS Shapes Module Level 1
# shape-margin-property

ブラウザーの互換性

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
shape-margin

Legend

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

Full support
Full support
Requires a vendor prefix or different name for use.
Has more compatibility info.

関連情報