How to achieve a trapezoid in CSS3?

大憨熊 提交于 2019-11-30 20:19:25

问题


I'm trying to achieve the following container in CSS3. I tried with transform: skewY but i don't have the desired result. I know that I can achieve it with 3d Transforms, but I have in mind our lovely 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?

JSFiddle

Thank you


回答1:


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>


来源:https://stackoverflow.com/questions/28879793/how-to-achieve-a-trapezoid-in-css3

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