如何将 Clip-Path 用于倾斜的边缘?
How can I Use Clip-Path for slanted edges?
目前正在使用这个 CSS 从左到右的底部倾斜:
clip-path: polygon( 0 0, 100% 0, 100% calc(100% - 3vw), 0 100% );
它对于响应式解决方案非常有效,但很难弄清楚如何针对 div 顶部从左到右向下倾斜的响应式解决方案执行此操作。
我试过这个:
clip-path: polygon( 0 0, 100% calc(100% - 29vw), 100% 100%, 0 100% );
谢谢!
您可以像下面这样调整。您将第二个点从 3vw
开始降低,然后将另一个点放回 100%
.box {
height: 100px;
background: red;
clip-path: polygon( 0 0, 100% 3vw, 100% 100%, 0 100%);
/* (0,0) ----------------- (100%,0)
| |<---------(100%,3vw)
| |
| |
| |
(0,100%) ----------------- (100%,100%)
}
<div class="box">
</div>
如果你想从右到左,像这样:
.box {
height: 100px;
background: red;
clip-path: polygon( 0 3vw, 100% 0, 100% 100%, 0 100%);
}
<div class="box">
</div>
侧面:
.box {
height: 100px;
background: red;
clip-path: polygon( 0 0, calc(100% - 3vw) 0, 100% 100%, 0 100%);
}
<div class="box">
</div>
如果你想要更支持的方式,可以考虑像下面这样的多背景:
.box {
height: 100px;
margin:5px;
padding-top:3vw;
background:
/*a triangle shape on the padding-top area*/
linear-gradient(to bottom var(--d,left),transparent 48%,red 50%) top/100% 3.1vw no-repeat,
/*color the content and not the padding-top*/
linear-gradient(red,red) content-box;
}
<div class="box">
</div>
<div class="box" style="--d:right">
</div>
目前正在使用这个 CSS 从左到右的底部倾斜:
clip-path: polygon( 0 0, 100% 0, 100% calc(100% - 3vw), 0 100% );
它对于响应式解决方案非常有效,但很难弄清楚如何针对 div 顶部从左到右向下倾斜的响应式解决方案执行此操作。
我试过这个:
clip-path: polygon( 0 0, 100% calc(100% - 29vw), 100% 100%, 0 100% );
谢谢!
您可以像下面这样调整。您将第二个点从 3vw
开始降低,然后将另一个点放回 100%
.box {
height: 100px;
background: red;
clip-path: polygon( 0 0, 100% 3vw, 100% 100%, 0 100%);
/* (0,0) ----------------- (100%,0)
| |<---------(100%,3vw)
| |
| |
| |
(0,100%) ----------------- (100%,100%)
}
<div class="box">
</div>
如果你想从右到左,像这样:
.box {
height: 100px;
background: red;
clip-path: polygon( 0 3vw, 100% 0, 100% 100%, 0 100%);
}
<div class="box">
</div>
侧面:
.box {
height: 100px;
background: red;
clip-path: polygon( 0 0, calc(100% - 3vw) 0, 100% 100%, 0 100%);
}
<div class="box">
</div>
如果你想要更支持的方式,可以考虑像下面这样的多背景:
.box {
height: 100px;
margin:5px;
padding-top:3vw;
background:
/*a triangle shape on the padding-top area*/
linear-gradient(to bottom var(--d,left),transparent 48%,red 50%) top/100% 3.1vw no-repeat,
/*color the content and not the padding-top*/
linear-gradient(red,red) content-box;
}
<div class="box">
</div>
<div class="box" style="--d:right">
</div>