发布时间:2025-12-10 22:46:35 浏览次数:1
一、css什么是clip属性?
clip属性剪裁绝对定位元素。clip属性允许定义一个元素的可见尺寸,当一幅图像的尺寸大于包含此元素时,此图像就会被修剪并显示为这个元素定义的形状。
1.语法
img{
position:absolute;
clip:rect(0px,60px,200px,0px);
}
代码示例:
<!DOCTYPEhtml>
<html>
<head>
<metacharset="UTF-8">
<title></title>
<style>
.demo{
width:200px;
height:500px;
margin:50pxauto;
}
img{
border:1pxsolid#000;
}
.img{
position:absolute;
clip:rect(0px,165px,200px,34px);
}
</style>
</head>
<body>
<pclass="demo">
<h5>原图:</h5>
<imgsrc="css.jpg"width="200"height="131"/>
<h5>裁剪后</h5>
<imgclass="img"src="css.jpg"width="200"height="131"/>
</p>
</body>
</html>