是否可以在css中创建具有背景图像的等边责任三角形?

时间:2016-06-15 16:13:36

标签: html css html5 css3 svg

它也应该在IE11中运行。 我试过了:

  • 使用边框的常用三角形装箱技术 - 失败,无背景图片。

  • 剪辑路径 - 失败没有IE支持

  • 具有倾斜和变形的三角形必须具有适当的基于百分比的长度的战争。在尝试解决约3个小时后 - 失败

我最后的绝望努力可能是创建一个SVG蒙版,其中切入三角形并将其放置在<div>的顶部,并带有所需的图像。但它感觉很糟糕。

1 个答案:

答案 0 :(得分:1)

获得它的一个可能性:

&#13;
&#13;
.base {
  width: 70%;;
  height: 200px;
  margin: 10px;
}

.test {
  background-image: url(http://lorempixel.com/600/600);
  width: 100%;
  height: 0px;
  padding-top: 86.6%;
  position: relative;
}

.test:before {
  content: "";
  position: absolute;
  height: 100%;
  width: 50%;
  bottom: 0px;
  background-image: linear-gradient(-60deg, transparent 50%, white 50%);
}

.test:after {
  content: "";
  position: absolute;
  height: 100%;
  width: 50%;
  bottom: 0px;
  right: 0px;
  background-image: linear-gradient(60deg, transparent 50%, white 50%);
}
&#13;
<div class="base">
  <div class="test"></div>
  </div>
&#13;
&#13;
&#13;