简体   繁体   English

如何在CSS3中实现梯形?

[英]How to achieve a trapezoid in CSS3?

I'm trying to achieve the following container in CSS3. 我正在尝试在CSS3中实现以下容器。 I tried with transform: skewY but i don't have the desired result. 我尝试了transform: skewY但是我没有想要的结果。 I know that I can achieve it with 3d Transforms, but I have in mind our lovely Internet Explorer. 我知道我可以使用3d变换来实现它,但是我要记住我们可爱的Internet Explorer。 Also I tried to play with pseudo elements but I lost it. 我也尝试玩伪元素,但我输了。 Is there any css rule that I can, lets say, increase the height of the top and bottom right corners? 我可以说有任何CSS规则可以增加右上角和右下角的高度吗?

JSFiddle JSFiddle

Thank you 谢谢

梯形

You could use skewed pseudo elements for this (ensuring the skews are on the pseudos, and not the element itself): 您可以为此使用偏斜的伪元素(确保偏斜在伪元素上,而不是元素本身):

 div { position: relative; height: 200px; width: 80vw; margin: 10vw; } div:after { content: ""; position: absolute; top: 0; left: 0; height: 90%; width: 100%; -webkit-transform: skewY(5deg); -ms-transform: skewY(5deg); transform: skewY(5deg); background: gray; z-index: -1; } div:before { content: ""; position: absolute; height: 90%; width: 100%; left: 0; bottom: -20%; background: gray; -webkit-transform: skewY(-5deg); -ms-transform: skewY(-5deg); transform: skewY(-5deg); z-index: -1; } html { background: url(http://placekitten.com/g/300/300); } 
 <div>Content!!</div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM