FlamingMoe
FlamingMoe

Reputation: 2994

How to add a triangled border (vertically) respecting the background image of one side?

I have a vertical banner made in CSS and I'd like to create two zones.

The separation should be in triangle shape. One side has a background and the "triangle shape" should keep that background.

Better explained in a image ;-)

enter image description here

I'm about to do it, but a shape continues up to the end ... and I'm getting stuck.

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

Upvotes: 4

Views: 63

Answers (1)

Temani Afif
Temani Afif

Reputation: 272734

You may adjust the code like this:

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

Upvotes: 1

Related Questions