【问题标题】:Is creating Equilateral responsinve triangle with background image in css even possible?在css中创建带有背景图像的等边响应三角形甚至可能吗?
【发布时间】:2016-10-16 21:03:50
【问题描述】:

它也应该在 IE11 中工作。 我试过了:

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

  • 剪辑路径 - 失败不支持 IE

  • 具有倾斜和变换的三角形必须与适当的基于百分比的长度进行斗争。经过大约 3 小时的尝试后 - 失败

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

【问题讨论】:

  • 提问时请不要骂人
  • 只要图像是 SVG 图像(而不是 HTML 图像),最后的努力应该可以工作。然后,您可以使用 SVG 文件(连同图像和蒙版)作为背景图像。
  • 使用具有透明度的 .png 图像,并通过要在其中显示它的 div 的 css 将其设置为背景。

标签: html css svg


【解决方案1】:

获得它的一种可能性:

.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%);
}
<div class="base">
  <div class="test"></div>
  </div>

【讨论】:

    猜你喜欢
    • 2016-03-04
    • 2015-05-14
    • 2013-07-16
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    • 2023-04-08
    • 2013-03-04
    相关资源
    最近更新 更多