CSS参考手册
形状 | Shapes
形状外部 | 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
——浮动区域不受影响。
<shape-box>
——如果指定这些值之一:margin-box
,border-box
,padding-box
或content-box
,该形状则基于这些值进行计算。这个形状根据这些浮动元素的边缘计算出浮动的区域,包括由border-radius
属性制造出来的弧度,类似于background-clip
。
<basic-shape>
——形状是基于inset()
,circle()
,ellipse()
或polygon()
中的一个的值来计算。如果还提供了<shape-box>
,则同时为<basic-shape>
函数定义了参考框。如果<shape-box>
未提供,则参考框默认为margin-box
。
<image>
——提取并且计算指定 <image>
的alpha通道得出浮动区域,与通过shape-image-threshold
来定义一样。必须使用由HTML5规范定义的CORS-enabled fetch方法来处理shape-outside
的值中的所有URL。当捕获的时候,用户代理必须使用“匿名”模式来设置层叠样式表的URL的 referrer source 和设置所在文档的URL的 origin 。如果这导致出现没有有效的备份图像这样的网络错误, 产生的影响就跟指定了值 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 |
? |
? |
形状 | Shapes相关
层叠样式表( Cascading Style Sheets )是一种用来表现 HTML 或 XML 等文件样式的计算机语言。CSS 不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。