shape-margin CSS property sets a margin for a CSS shape created using shape-outside .

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

The margin lets you adjust the distance between the edges of the shape (the float element ) and the surrounding content.

句法

/* <length> values */
shape-margin: 10px;
shape-margin: 20mm;
/* <percentage> value */
shape-margin: 60%;
/* Global values */
shape-margin: inherit;
shape-margin: initial;
shape-margin: unset;
					

<length-percentage>
Sets the margin of the shape to a <length> value or to a <percentage> of the width of the element's containing block.

形式定义

初始值 0
适用于 floats
继承 no
百分比 refer to the width of the containing block
计算值 as specified, but with relative lengths converted into absolute lengths
动画类型 a length , percentage or calc();

形式句法

<length-percentage>

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

范例

Adding a margin to a polygon

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 he exists, probably knows its truth as we know it.</section>
					

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;
}
					

结果

规范

规范 状态 注释
CSS Shapes Module Level 1
The definition of 'shape-margin' in that specification.
候选推荐 初始定义

浏览器兼容性

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 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
shape-margin Chrome 完整支持 37 Edge 完整支持 79 Firefox 完整支持 62
完整支持 62
不支持 61 — 62 Disabled
Disabled ). To change preferences in Firefox, visit
IE 不支持 No Opera 完整支持 24 Safari 完整支持 10.1 WebView Android 完整支持 37 Chrome Android 完整支持 37 Firefox Android 完整支持 62
完整支持 62
不支持 61 — 62 Disabled
Disabled ). To change preferences in Firefox, visit
Opera Android 完整支持 24 Safari iOS 完整支持 10.3 Samsung Internet Android 完整支持 3.0

图例

完整支持

完整支持

不支持

不支持

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

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

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改: