I have a red triangle inside a black square, like the code below. How can I modify this code so that the background of this triangle becomes transparent?
I mean, how can I create a responsive shape of this black square minus the triangle?
here is an online demo: https://jsfiddle.net/wf42gpnu/1/
.bg-danger {
background: transparent;
padding: 20px;
}
.square {
width: 100vw;
height: 32px;
background: black;
}
.triangle {
width: 0;
height: 0;
border-left: 50vw solid transparent;
border-right: 50vw solid transparent;
border-bottom: 32px solid red;
border-radius: 0;
}
<div class="square">
<div class="triangle"></div>
</div>
3
Answers
You can use
clip-path
instead of a triangle child element:Just apply the styles you used for the triangle to the square, but swap the border colors. No need for the triangle: