如何将Clip-Path用于倾斜边缘?

问题描述 投票:2回答:1

目前使用此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%  );

谢谢!

html css clip-path
1个回答
1
投票

你可以调整如下。你让第二点从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>
© www.soinside.com 2019 - 2024. All rights reserved.