CSS Transform to skew the shape to a trapezium

巧了我就是萌 提交于 2019-12-18 13:01:22

问题


I want to be able to skew an element in the way the image displays below.

I have been playing around with it, but dont seem to be able to get close to replicating that shape.

My css code is

transform:skew(30deg,30deg);

Is transform even the right way to do this? Please let me know the best, most browser compatible, solution.


回答1:


You can apply some rotate transform around the X axis and apply an appropriate pespective before:

div {    
  width:300px;
  height:200px;
  background:url(http://placekitten.com/300/200);
  border:2px solid red;    
  border-top-width:4px;
  border-bottom-width:1px;
  -webkit-transform: perspective(200px) rotateX(40deg);    
  margin:100px;
}

Demo




回答2:


Try this:

Html

<div class="trapezium"></div>

StyleSheet

.trapezium {
    border-bottom: 80px solid #fff;
    border-left: 45px solid transparent;
    border-right: 45px solid transparent;
    padding: 0 8px 0 0;
    height: 0;
    width: 120px;
    position: relative;
    margin: 2em auto;
}

.trapezium:before {
    border-bottom: 90px solid #000;
    border-left: 50px solid transparent;
    border-right: 50px solid transparent;
    padding: 0 8px 0 0;
    height: 0;
    width: 130px;
    position: absolute;
    bottom: -85px;
    left: -55px;
    content: "";
    z-index: -1;
}

Here is the Demo



来源:https://stackoverflow.com/questions/23177903/css-transform-to-skew-the-shape-to-a-trapezium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!