形状外部 | 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 value | none |
---|---|
Applies to | floats |
Inherited | no |
Media | visual |
Computed value | as defined for <basic-shape> (with <shape-box> following, if supplied), the <image> with its URI made absolute, otherwise as specified. |
Animation type | yes, as specified for <basic-shape>, otherwise no |
Canonical order | the 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>
输出
规范
Specification | Status | Comment |
---|---|---|
CSS Shapes Module Level 1The definition of 'shape-outside' in that specification. | Candidate Recommendation | Initial definition |
浏览器兼容性
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 37 | No support1 | No support | 24 | 8.0 -webkit |
<gradient> | ? | No support | No support | ? | ? |
inset() | ? | No support2 | No support | ? | ? |
polygon() | ? | No support3 | No support | ? | ? |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | No support | No support1 | No support | No support | 8.0 -webkit |
<gradient> | No support | No support | No support | No support | ? |
inset() | No support | No support2 | No support | No support | ? |
polygon() | No support | No support3 | No support | ? | ? |