CSS中clip-path属性

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;
兼容性
chromeFirefoxoperaSafariIEAndroidios
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%);
}

这里写图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值