Как добавить рамку («треугольник»), которая позволяет видеть фоновое изображение? - PullRequest
0 голосов
/ 17 мая 2018

Поскольку это довольно сложно объяснить, я покажу вам изображение того, что я притворяюсь.

Проблема не в "треугольнике", а в том, что фон изображения должен быть показан в этом "пространстве", котороегенерирует треугольник.

enter image description here

Ответы [ 2 ]

0 голосов
/ 17 мая 2018

Вот еще одна идея с одним элементом, несколькими фонами и меньшим количеством кода:

.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>
0 голосов
/ 17 мая 2018

Вот мой подход, как справиться с этой задачей.Я использую псевдоэлементы : до и : после со свойствами transform: skewX(deg) и border-left.Вот фрагмент кода:

.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>
...