在线文档教程
CSS

形状外部 | shape-outside

shape-outside

这是一个实验技术

在使用此产品之前,请仔细检查浏览器兼容性表。

shape-outside CSS属性使用形状值来定义浮动区域的浮动,这将使得内联内容会环绕着形状,而不是产生浮动的边框。

/* Keyword values */ shape-outside: none; shape-outside: margin-box; shape-outside: content-box; shape-outside: border-box; shape-outside: padding-box; /* Function values */ shape-outside: circle( shape-outside: ellipse( shape-outside: inset(10px 10px 10px 10px shape-outside: polygon(10px 10px, 20px 20px, 30px 30px /* <url> value */ shape-outside: url(image.png /* Gradient value */ shape-outside: linear-gradient(45deg, rgba(255, 255, 255, 0) 150px, red 150px /* Global values */ shape-outside: initial; shape-outside: inherit; shape-outside: unset;

Initial valuenone
Applies tofloats
Inheritedno
Mediavisual
Computed valueas defined for <basic-shape> (with <shape-box> following, if supplied), the <image> with its URI made absolute, otherwise as specified.
Animation typeyes, as specified for <basic-shape>, otherwise no
Canonical orderthe unique non-ambiguous order defined by the formal grammar

语法

可用值

none——浮动区域不受影响。

插值

为了在两个基本形状之间进行插值(interpolating),应用下面的规则。形状函数中的值在插入时看做一个简单列表。列表值可能作为长度、百分比或者是计算值进行插入。如果列表值不属于上述类型中的任何一个,但是是相同的(例如nonzero在两个列表中找到相同的列表位置),则这些值也会进行内插。

  • 这两个形状必须使用相同的reference box。

  • 如果两个形状都是ellipse()circle()类型,且它们的半径都未使用closest-side或最远端的关键字,则在形状函数中的每个值之间进行插值。

  • 如果两种形状都是inset()类型,则在形状函数中的每个值之间进行插值。

  • 如果两种形状都是polygon()类型,且两个多边形都具有相同的顶点数,并使用相同<fill-rule>,那么在形状函数中的每个值之间插值。

  • 在所有其他情况下,不指定插值。

形式语法

none | <shape-box> || <basic-shape> | <image>where <shape-box> = <box> | margin-box <basic-shape> = <inset()> | <circle()> | <ellipse()> | <polygon()> <image> = <url> | <image()> | <image-set()> | <element()> | <cross-fade()> | <gradient> where <box> = border-box | padding-box | content-box <inset()> = inset( <length-percentage>{1,4} [ round <border-radius> ]? ) <circle()> = circle( [ <shape-radius> ]? [ at <position> ]? ) <ellipse()> = ellipse( [ <shape-radius>{2} ]? [ at <position> ]? ) <polygon()> = polygon( <fill-rule>? , [ <length-percentage> <length-percentage> ]# ) <image()> = image( [ [ <image> | <string> ]? , <color>? ]! ) <image-set()> = image-set( <image-set-option># ) <element()> = element( <id-selector> ) <cross-fade()> = cross-fade( <cf-mixing-image> , <cf-final-image>? ) <gradient> = <linear-gradient()> | <repeating-linear-gradient()> | <radial-gradient()> | <repeating-radial-gradient()> where <length-percentage> = <length> | <percentage> <shape-radius> = <length-percentage> | closest-side | farthest-side <position> = [[ left | center | right | top | bottom | <length-percentage> ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ] | [ center | [ left | right ] <length-percentage>? ] && [ center | [ top | bottom ] <length-percentage>? ]] <fill-rule> = nonzero | evenodd <color> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hex-color> | <named-color> | currentcolor | <deprecated-system-color> <image-set-option> = [ <image> | <string> ] <resolution> <cf-mixing-image> = <percentage>? && <image> <cf-final-image> = <image> | <color> <linear-gradient()> = linear-gradient( [ <angle> | to <side-or-corner> ]? , <color-stop-list> ) <repeating-linear-gradient()> = repeating-linear-gradient( [ <angle> | to <side-or-corner> ]? , <color-stop-list> ) <radial-gradient()> = radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> ) <repeating-radial-gradient()> = repeating-radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> ) where <rgb()> = rgb( [ [ <percentage>{3} | <number>{3} ] [ / <alpha-value> ]? ] | [ [ <percentage>#{3} | <number>#{3} ] , <alpha-value>? ] ) <rgba()> = rgba( [ [ <percentage>{3} | <number>{3} ] [ / <alpha-value> ]? ] | [ [ <percentage>#{3} | <number>#{3} ] , <alpha-value>? ] ) <hsl()> = hsl( [ <hue> <percentage> <percentage> [ / <alpha-value> ]? ] | [ <hue>, <percentage>, <percentage>, <alpha-value>? ] ) <hsla()> = hsla( [ <hue> <percentage> <percentage> [ / <alpha-value> ]? ] | [ <hue>, <percentage>, <percentage>, <alpha-value>? ] ) <side-or-corner> = [ left | right ] || [ top | bottom ] <color-stop-list> = <color-stop>#{2,} <ending-shape> = circle | ellipse <size> = closest-side | farthest-side | closest-corner | farthest-corner | <length> | <length-percentage>{2} where <alpha-value> = <number> | <percentage> <hue> = <number> | <angle> <color-stop> = <color> <length-percentage>?

实例

CSS内容

.main { width: 500px; } .left, .right { width: 40%; height: 12ex; background-color: lightgray; } .left { -webkit-shape-outside: polygon(0 0, 100% 100%, 0 100% shape-outside: polygon(0 0, 100% 100%, 0 100% float: left; -webkit-clip-path: polygon(0 0, 100% 100%, 0 100% clip-path: polygon(0 0, 100% 100%, 0 100% } .right { -webkit-shape-outside: polygon(100% 0, 100% 100%, 0 100% shape-outside: polygon(100% 0, 100% 100%, 0 100% float: right; -webkit-clip-path: polygon(100% 0, 100% 100%, 0 100% clip-path: polygon(100% 0, 100% 100%, 0 100% } p { text-align: center; }

HTML内容

<div class="main">   <div class="left"></div>   <div class="right"></div>   <p>     Sometimes a web page's text content appears to be     funneling your attention towards a spot on the page     to drive you to follow a particular link.  Sometimes     you don't notice.   </p> </div>

输出

规范

SpecificationStatusComment
CSS Shapes Module Level 1The definition of 'shape-outside' in that specification.Candidate RecommendationInitial definition

浏览器兼容性

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support37No support1No support248.0 -webkit
<gradient>?No supportNo support??
inset()?No support2No support??
polygon()?No support3No support??

FeatureAndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic supportNo supportNo support1No supportNo support8.0 -webkit
<gradient>No supportNo supportNo supportNo support?
inset()No supportNo support2No supportNo support?
polygon()No supportNo support3No support??