I am trying to create a square that has three colors similar to Two-tone background split by diagonal line using css but instead of just two colors, three more like this:
Any advice? I tried this:
.diagonal-box {
width: 200px;
height: 200px;
position: relative;
}
.diagonal-box:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 0;
height: 0;
border-style: solid;
border-width: 0 0 200px 200px;
border-color: transparent transparent #FF7F50;
}
.diagonal-box:after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 0;
height: 0;
border-style: solid;
border-width: 0 200px 200px 0;
border-color: transparent #00BFFF transparent;
}
.diagonal-box div {
position: absolute;
top: 0;
left: 0;
width: 0;
height: 0;
border-style: solid;
border-width: 200px 200px 0 0;
border-color: #7CFC00 transparent transparent transparent;
}
<div class="diagonal-box">
<div></div>
</div>
but it does not correctly put the triangles in the way that I want.
2
Answers
Does this solve your problem ?
I’ve used
clip-path
to make those simple triangles rather than using invisible borders. You can tweak the width of the triangles’ short sides by changing the--width
value.There’s a simple solution requiring no extra
div
orbefore
andafter
pseudo-elements: