我有一张带有渐变和使用clip-path
剪切角的卡片图片:
.card {
width: 200px;
height: 200px;
background: linear-gradient(to bottom, blue, green);
clip-path: polygon(20px 0, 100% 0, 100% 100%, 0 100%, 0 20px);
}
<div class="card"></div>
裁剪的角必须具有固定的大小,而不受卡片大小的影响,因此我使用像素来裁剪角。
但是,目前浏览器对于clip-path
的支持并不理想,因此我尝试将这个HTML和CSS转换为SVG。
.container {
width: 200px;
height: 200px;
}
<div class="container">
<svg viewBox="0 0 100 100" clip-path="url(#myClip)">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" style="stop-color:rgb(0,0,255);stop-opacity:1" />
<stop offset="100%" style="stop-color:rgb(0,255,0);stop-opacity:1" />
</linearGradient>
</defs>
<polygon points="20,0 100,0 100,100 0,100 0,20" fill="url(#grad1)" />
</svg>
</div>
但问题在于,我无法使这个剪切的角落具有固定的大小,而不管卡片的尺寸如何。