css裁剪属性----clip-path
2020-03-21 本文已影响0人
RexingLeung
[TOC]
什么是clip-path
clip-path是一个css3新属性 , 一般用在svg元素上 , 但是也可以作为普通元素裁剪使用
解释 : clip-path 属性可以创建一个只有元素的部分区域可以显示的剪切区域。区域内的部分显示,区域外的隐藏
普通标签上的使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="./assets/demo1.css">
</head>
<body>
<div class="pc">
<img src="./assets/正方形.jpg" alt="" style="width: 100%; height: 100%;">
</div>
<div>
</div>
</body>
</html>
.pc{
margin: 200px;
width: 400px;
height: 400px;
background-color: orange;
background-size: cover;
overflow: hidden;
}
.pc>img{
clip-path: polygon(50% 0,100% 50%,50% 100%,0 50%); /*矩形*/
/* clip-path: circle(40%); 圆形*/
transition: .1s clip-path; /* 裁剪的动画 */
}
.pc > img:hover{
clip-path: polygon(0 0,100% 0%,100% 100%,0 100%);
}
语法
/* Keyword values */clip-path: none;
/* <clip-source> values */
clip-path: url(resources.svg#c1);
/* <geometry-box> values */
clip-path: margin-box;
clip-path: border-box;
clip-path: padding-box;
clip-path: content-box;
clip-path: fill-box;
clip-path: stroke-box;
clip-path: view-box;
/* <basic-shape> values */
clip-path: inset(100px 50px);
clip-path: circle(50px at 0 100px);
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
clip-path: path('M0.5,1 C0.5,1,0,0.7,0,0.3 A0.25,0.25,1,1,1,0.5,0.3 A0.25,0.25,1,1,1,1,0.3 C1,0.7,0.5,1,0.5,1 Z');
/* Box and shape values combined */
clip-path: padding-box circle(50px at 0 100px);
/* Global values */
clip-path: inherit;
clip-path: initial;
clip-path: unset;