首页 > 解决方案 > 如何使用css变换构建45度倒梯形?

问题描述

如何用css搭建一个45度倒梯形?

.inverted-trapezoid {
    position: relative;
    display: flex;
    flex-direction: row;
    justify-content: center;
    padding: 1.5em 0em 1.5em 0em;
    color: white;
    height: 1em;
    z-index: 0;
    // margin: 3em;
}
.inverted-trapezoid::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: -1;
    background: red;
    border-bottom: none;
    transform: perspective(9.5em) rotateX(-45deg);
    transform-origin: bottom;
}

我们可以使用变换来制作倒梯形,但我们如何才能精确地制作 45 度呢?

标签: css

解决方案


use clip-path: polygon(0% 0%, 100% 0%, 75% 100%, 25% 100%); for inverted trapezoid

<div class="Inverted-trapezoid"></div>

.Inverted-trapezoid{width:200px; height:200px;background:#000;margin-bottom:50px; margin-right:20px; clip-path: polygon(0% 0%, 100% 0%, 75% 100%, 25% 100%);}

推荐阅读