clip-path
属性可以创建一个只有元素的部分区域可以显示的剪切区域。区域内的部分显示,区域外的隐藏。剪切区域是被引用内嵌的URL定义的路径或者外部svg的路径,或者作为一个形状。例如:circle()
等。
clip-path
已经代替了现在已经弃用的剪切clip
属性。
初始值:none
使用元素:所有元素,在SVG中,适用于不包括defs元素和所有图形元素的容器元素
继承性:否
语法
<clip-source> | [ <basic-shape> || <geometry-box> ] | none
where
<clip-source> = <url>
<basic-shape> = <inset()> | <circle()> | <ellipse()> | <polygon()>
<geometry-box> = <shape-box> | fill-box | stroke-box | view-box
where
<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> ]# )
<shape-box> = <box> | margin-box
where
<length-percentage> = <length> | <percentage>
<shape-radius> = <length-percentage> | closest-side | farthest-side
<position> = [ [ left | center | right ] || [ top | center | bottom ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ]? | [ [ left | right ] <length-percentage> ] && [ [ top | bottom ] <length-percentage> ] ]
<fill-rule> = nonzero | evenodd
<box> = border-box | padding-box | content-box
注:circle的position默认位置是左上角,(0,0)
/*keyword values*/
clip-path: none;
/*image values*/
clip-path: url(resources.svg#c1);
/*Box values
clip-path:fill-box;
clip-path: stroke-box;
clip-path: view-box;
clip-path: margin-box;
clip-path: border-box;
clip-path: padding-box;
clip-path: content-box
*/
/*Geometry values*/
clip-path: inset(100px 50px);
clip-path: circle(50px at 0 100px);
clip-path: polygon(50% 0%,100% 50%,50% 100%,0% 50%);
/*Box and geometry values combined*/
clip-path: padding-box circle(50px at 0 100px);
/*Global values*/
clip-path: inherit;
clip-path: initial;
clip-path: unset;
兼容性
chrome | Firefox | opera | Safari | IE | Android | ios |
---|---|---|---|---|---|---|
24+-webkit- 前缀,经测试,63.0有无前缀均支持 | 支持 | 支持-webkit- 前缀 | 不支持 | 不支持 | 支持 | 支持-webkit- 前缀 |
注:目前chrome和opera目前并不支持外部的SVG
示例:不规则展示图片
width: 300px;
height: 300px;
clip-path:polygon(0 0,37% 12%,50% 0,62% 0,50% 50%,75% 0,87% 0,50% 50%,100% 0,100% 12%,50% 50%,100% 25%,100% 37%,50% 50%,100% 50%,75% 75%,75% 100%,25% 100%,25% 75%,0 50%,25% 37%);
}