仅倾斜div的一个角

时间:2019-05-06 22:16:04

标签: css skew

我只需要下拉英雄div的右下角。我尝试了所有歪斜和旋转配置。 enter image description here

https://codepen.io/alecfried/full/pmvLMw

<div class="position-relative" style="min-height: 400px; background: purple; width: 100%;transform-origin: bottom; transform: skewX(-17deg); overflow: hidden;"> </div>

2 个答案:

答案 0 :(得分:1)

这是另一种解决方案(在您发表评论后)。尽管我尚未删除,但此<div class=" wrapper ">在这里没有职责。

.wrapper {
  width: 100%;
  /* may remove width:100%, as div is always 100% */
  margin: 0 auto;
  overflow: hidden;
}

.position-relative {
  min-height: 400px;
  background: purple;
  width: 100%;
  /* may remove width:100%, as div is always 100% */
  /* transform-origin: bottom; */
  /* transform: skewX(-17deg); */
  -webkit-clip-path: polygon(0 0, 100% 0%, 100% 100%, 0 80%);
  clip-path: polygon(0 0, 100% 0%, 100% 100%, 0 80%);
}
<div class="wrapper">
  <div class="position-relative"> </div>
</div>

关于剪辑路径,您可以在clippy上找到一些直观示例

答案 1 :(得分:0)

是的!这是可以实现的,但您可能需要应用这种技巧! :)

.wraper {
        width: 100%; /* may remove width:100%, as div is always 100% */
        margin: 0 auto;
        overflow: hidden;
    }
    
    .position-relative {
        min-height: 400px;
        background: purple;
        width: 100%; /* may remove width:100%, as div is always 100% */
        transform-origin: bottom;
        transform: skewX(-17deg);
    }
    <div class="wraper">
        <div class="position-relative"> </div>
    </div>