How to implement a triangle overlay on a banner with background?

I am trying to create a banner with a background image, behind a triangle shaped border:

How to implement a triangle overlay on a banner with background?

I have tried using borders on both the :before and :after pseudo selectors, but I cannot achieve the above, especially when it comes to responsiveness.

<div class="contact-banner banner">
    <img src="background.jpg" />
    <div class="contact-banner-inner bg-light">
        <div class="container">
            <div class="content-inner">
                <!-- Content will go here -->
            </div>
        </div>
    </div>
</div>
    .contact-banner-inner:before {
        content: '';
        position: absolute;
        content: '';
        width: 0;
        height: 0;
        border-style: solid;
        border-width: 0 40vh 40vh 0;
        border-color: transparent #f7f7f7 transparent transparent;
        left: 7%;
        top: 0;
        position: absolute;
        z-index: 3;
    }

    .contact-banner-inner:after {
        content: '';
        width: 0;
        height: 0;
        border-style: solid;
        border-width: 0 40vh 40vh 0;
        border-color: transparent #f7f7f7 transparent transparent;
        left: 7%;
        bottom: 0;
        position: absolute;
        z-index: 3;
        transform: rotate(90deg);
    }

Any help would be greatly appreciated. Thanks

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

As you wrote that any idea and any help is welcome I have an idea for you.
I found a site that can help you: bennettfeely, Here you can create different shapes, so I made an example for you.

body {
  margin: 0;
}
.container {
  background: #3c1919;
}
.background {
  width: 30%;
  height: 500px;
  background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAA1BMVEUAXEdZzPuxAAAASElEQVR4nO3BgQAAAADDoPlTX+AIVQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADwDcaiAAFXD1ujAAAAAElFTkSuQmCC");
  clip-path: polygon(50% 0%, 100% 52%, 48% 100%, 0 100%, 0 0);
}
<div class="container">
  <div class="background"></div>
</div>

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply