【问题标题】:How to add a triangled border (vertically) respecting the background image of one side?如何添加尊重一侧背景图像的三角形边框(垂直)?
【发布时间】:2018-05-21 05:13:50
【问题描述】:

我有一个用 CSS 制作的垂直横幅,我想创建两个区域。

分隔应该是三角形。一侧有背景,“三角形”应保留该背景。

用图片更好地解释 ;-)

我正要这样做,但一个形状一直持续到最后......我被卡住了。

.box {
  background-image: 
    linear-gradient(195deg, transparent 70%, #000 70%, #000 71%, #fff 71%), 
    linear-gradient(165deg, transparent 70%, #000 70%, #000 71%, #fff 71%), 
    url(https://images.unsplash.com/photo-1526327227970-4bda49fa3489?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=3c4bce33d96df6b18af53fb2dae3363e&auto=format&fit=crop&w=2700&q=80);
  background-position: top, center;
  background-size: 250px 100%, cover;
  background-repeat: no-repeat;
}
<div class="box">
  some text here<br> more text
</div>

【问题讨论】:

    标签: css background background-image linear-gradients


    【解决方案1】:

    您可以像这样调整代码:

    .box {
      padding: 50px 30px;
      height:300px;
      width:100px;
      text-align: right;
      background-image:
        linear-gradient(200deg,transparent 70%,#000 70%,#000 71%,#fff 71%),
        linear-gradient(160deg,transparent 70%,#000 70%,#000 71%,#fff 71%),
        url(https://images.unsplash.com/photo-1526327227970-4bda49fa3489?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=3c4bce33d96df6b18af53fb2dae3363e&auto=format&fit=crop&w=2700&q=80);
      background-position:bottom left,bottom right,center;
      background-size:50% 600px,50% 600px,cover;
      background-repeat:no-repeat;
      
      display:flex;
      align-items:flex-end;
    }
    <div class="box">
      some text here<br> more text
    </div>

    【讨论】:

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