【问题标题】:How to add a border ("triangled") that allows see image background?如何添加允许查看图像背景的边框(“三角形”)?
【发布时间】:2018-05-17 18:39:03
【问题描述】:

由于很难解释,我将向您展示我假装的图像。

问题不在于“三角形”,而在于三角形生成的“空间”中要显示的图像背景。

【问题讨论】:

    标签: image css background-image


    【解决方案1】:

    这是我的方法,如何处理这个任务。我使用带有transform: skewX(deg)border-left 属性的伪元素:before:after。 这是代码sn-p:

    .bg-arrow {
    display: flex;
      justify-content: flex-end;
      background:url('http://wallpaperlepi.com/wp-content/uploads/2014/10/Stone-And-Star-Wallpaper.jpg') #ddd center center no-repeat;
      background-size: cover;
    }
    
    .arrow-shape{
      position: relative;
      display: flex;
      align-items: center;
      justify-content: space-around;
      width: 200px; 
      height: 100px;
      background-color: #fff;
    }
    
    .arrow-shape:before,
    .arrow-shape:after{
      content: '';
      position: absolute;
      left: 0;
      height: 50%;
      width: 100%;
      background-color: #fff;
      border-left: 4px solid #000;
      z-index: 1;
    }
    
    .arrow-shape:before {
      top: 0;
        transform: skewX(15deg) translateX(-30px);
    }
    
    .arrow-shape:after {
        transform: skewX(-15deg) translateX(-30px);
      bottom: 0;
    }
    
    .arrow-shape .text {
      position: relative;
      text-align: center;
      z-index: 2;
    }
    <div class="bg-arrow">
      <div class="arrow-shape">
        <div class="text">
          Lorem ipsum dolor sit amet consectetur.
        </div>
      </div>
    </div>

    【讨论】:

      【解决方案2】:

      这是另一个带有 一个 元素、多个背景和更少代码的想法:

      .box {
        padding: 50px 30px;
        text-align: right;
        background-image:
          linear-gradient(60deg,transparent 70%,#000 70%,#000 71%,#fff 71%),
          linear-gradient(120deg,transparent 70%,#000 70%,#000 71%,#fff 71%),
          url(https://picsum.photos/2000/1000?image=1069);
        background-position:top right,bottom right,center;
        background-size:600px 50%,600px 50%,cover;
        background-repeat:no-repeat;
      }
      <div class="box">
        some text here<br> more text
      </div>

      【讨论】:

      • 你会如何用你的方法用曲线来做呢?不是“三角形”,而是曲线
      • @FlamingMoe 我会考虑这样的径向渐变:jsfiddle.net/f81hsvza ;)
      • 太棒了!你是最棒的!
      • 对不起,我正在尝试垂直做同样的事情,但我找不到路:-P
      • @FlamingMoe 是的,我知道这很棘手 :) 您可以考虑通过显示您是如何尝试调整它以及您失败的地方来添加另一个问题;)您可能会得到很多答案 [可能包括我的一个]
      猜你喜欢
      • 1970-01-01
      • 2012-06-13
      • 2014-04-09
      • 2016-03-04
      • 2015-02-07
      • 2022-08-03
      • 2017-11-18
      • 1970-01-01
      相关资源
      最近更新 更多