--- title: shape-margin slug: Web/CSS/shape-margin tags: - CSS - CSS Property - CSS Shapes - Reference - float - margin - shape-margin translation_of: Web/CSS/shape-margin --- <div>{{CSSRef}}</div> <p><span class="seoSummary"><a href="/en-US/docs/Web/CSS">CSS</a> 属性 <strong><code>shape-margin</code></strong> 用于设定由{{cssxref("shape-outside")}}创建的CSS形状的外边距。</span></p> <div>{{EmbedInteractiveExample("pages/css/shape-margin.html")}}</div> <p>这个外边距可以让你调整(浮动元素的)形状边缘与环绕内容之间的距离。</p> <h2 id="语法">语法</h2> <pre class="brush:css no-line-numbers">/* <length> values */ shape-margin: 10px; shape-margin: 20mm; /* <percentage> value */ shape-margin: 60%; /* Global values */ shape-margin: inherit; shape-margin: initial; shape-margin: unset; </pre> <h3 id="值">值</h3> <dl> <dt><code><length-percentage></code></dt> <dd>使用{{cssxref("<length>")}}值,或者相对于元素容纳块的{{cssxref("<percentage>")}}值来设定形状的外边距。</dd> </dl> <h3 id="正式语法">正式语法</h3> {{csssyntax}} <h2 id="范例">范例</h2> <h3 id="Adding_a_margin_to_a_polygon">Adding a margin to a polygon</h3> <h4 id="HTML">HTML</h4> <pre class="brush: 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></pre> <h4 id="CSS">CSS</h4> <pre class="brush: 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; }</pre> <h4 id="Result">Result</h4> <p>{{EmbedLiveSample("Adding_a_margin_to_a_polygon", 500, 250)}}</p> <h2 id="规范">规范</h2> <table class="standard-table"> <thead> <tr> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('CSS Shapes', '#shape-margin-property', 'shape-margin')}}</td> <td>{{Spec2('CSS Shapes')}}</td> <td>Initial definition</td> </tr> </tbody> </table> <p>{{cssinfo}}</p> <h2 id="浏览器兼容性">浏览器兼容性</h2> <p>{{Compat}}</p> <h2 id="参见">参见</h2> <ul> <li><a href="/en-US/docs/Web/CSS/CSS_Shapes">CSS Shapes</a></li> <li><a href="/en-US/docs/Web/CSS/CSS_Shapes/Overview_of_CSS_Shapes">Overview of CSS Shapes</a></li> <li>{{cssxref("shape-outside")}}</li> <li>{{cssxref("shape-image-threshold")}}</li> <li>{{cssxref("<basic-shape>")}}</li> </ul>