I've been attempting to arrange multiple CSS shapes to hug each other, but I'm facing some difficulties. After researching online, the only solution I came across was using inline-block. However, I'm struggling to achieve the desired outcome. While it works for aligning shapes next to each other, it doesn't work for shapes above and below each other.
For example, if I want to create a diamond shape using triangles:
.r_tleft {
width: 0;
height: 0;
border-style: solid;
border-width: 0 0 25px 25px;
border-color: transparent transparent #007bff transparent;
display: inline-block;
}
.r_tright {
width: 0;
height: 0;
border-style: solid;
border-width: 25px 0 0 25px;
border-color: transparent transparent transparent #64C7CC;
display: inline-block;
}
.r_bleft {
width: 0;
height: 0;
border-style: solid;
border-width: 0 25px 25px 0;
border-color: transparent #64C7CC transparent transparent;
display: inline-block;
}
.r_bright {
width: 0;
height: 0;
border-style: solid;
border-width: 25px 25px 0 0;
border-color: #007bff transparent transparent transparent;
display: inline-block;
}
<div class="r_tleft"></div>
<div class="r_tright"></div>
<div class="r_bleft"></div>
<div class="r_bright"></div>
The result appears like this:
◢◣◥◤
If I add a break tag, it changes the layout:
<div class="r_tleft"></div><div class="r_tright"></div>
<br>
<div class="r_bleft"></div><div class="r_bright"></div>
.r_tleft {
width: 0;
height: 0;
border-style: solid;
border-width: 0 0 25px 25px;
border-color: transparent transparent #007bff transparent;
display: inline-block;
}
.r_tright {
width: 0;
height: 0;
border-style: solid;
border-width: 25px 0 0 25px;
border-color: transparent transparent transparent #64C7CC;
display: inline-block;
}
.r_bleft {
width: 0;
height: 0;
border-style: solid;
border-width: 0 25px 25px 0;
border-color: transparent #64C7CC transparent transparent;
display: inline-block;
}
.r_bright {
width: 0;
height: 0;
border-style: solid;
border-width: 25px 25px 0 0;
border-color: #007bff transparent transparent transparent;
display: inline-block;
}
<div class="r_tleft"></div>
<div class="r_tright"></div>
<br>
<div class="r_bleft"></div>
<div class="r_bright"></div>
This output appears as:
◢◣
◥◤
As evident, neither of these layouts achieve the desired result.