如何添加允许查看图像背景的边框(“三角”)?

时间:2018-05-17 07:01:16

标签: image css3 background-image

由于很难解释,我会告诉你一个我假装的图像。

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

enter image description here

2 个答案:

答案 0 :(得分:2)

这是我的方法,如何处理这项任务。我使用伪元素:之前:之后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>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

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

&#13;
&#13;
.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;
}
&#13;
<div class="box">
  some text here<br> more text
</div>
&#13;
&#13;
&#13;