I'm trying to create a HTML design with objects which contain angled sides.
What I'm currently using is a background: linear-gradient()
but the edges are not sharp and get pixelated. The reason I used this is because it is in % which makes it easier for responsiveness.
Code:
#container {
position: absolute;
width: 100%;
height: 100%;
display: block;
}
#shape {
position: absolute;
z-index: 6;
background: #42145f;
width: 45%;
height: 60%;
left: 0px;
top: 0px;
background: linear-gradient(to right bottom, #42145f 50%, transparent 50%)
}
#shape2 {
position: absolute;
z-index: 5;
background: #c50084;
width: 100%;
height: 35%;
left: 0px;
top: 0px;
background: linear-gradient(to right bottom, #c50084 50%, transparent 50%)
}
#shape3 {
position: absolute;
z-index: 4;
background: #6e2c6b;
width: 37%;
height: 73%;
left: 0px;
top: 27%;
background: linear-gradient(to right top, #6e2c6b 50%, transparent 50%)
}
#shape4 {
position: absolute;
z-index: 3;
background: #b71234;
width: 100%;
height: 14%;
left: 0;
top: 86%;
background: linear-gradient(to left top, #b71234 50%, transparent 50%)
}
#shape5 {
position: absolute;
z-index: 0;
background: #8d1b3d;
width: 20%;
height: 78%;
left: 80%;
top: 22%;
background: linear-gradient(to left top, #8d1b3d 50%, transparent 50%)
}
#shape6 {
position: absolute;
z-index: 2;
background: #ff5800;
width: 22%;
height: 59%;
left: 78%;
top: 0;
background: linear-gradient(to left bottom, #ff5800 50%, transparent 50%)
}
#shape7 {
position: absolute;
z-index: 1;
background: #fadc41;
width: 30%;
height: 54%;
left: 70%;
top: 0;
background: linear-gradient(to left bottom, #fadc41 50%, transparent 50%)
}
<div id="container">
<div id="shape"></div>
<div id="shape2"></div>
<div id="shape3"></div>
<div id="shape4"></div>
<div id="shape5"></div>
<div id="shape6"></div>
<div id="shape7"></div>
</div>
What I previously used was a div
with border
which has a smooth and sharp edge but border
doest not support % so in that case I thought it wouldn't be possible in this solution for responsiveness:
#container {
position: absolute;
width: 100%;
height: 100%;
display: block;
}
#shape {
position: absolute;
height: 0;
width: 0px;
border-top: 600px solid #42145f;
border-right: 700px solid transparent;
z-index: 6;
}
#shape2 {
position: absolute;
height: 0;
width: 0px;
border-top: 375px solid #c50084;
border-right: 1600px solid transparent;
z-index: 5;
}
#shape3 {
position: absolute;
height: 0;
width: 0px;
top: 200px;
border-bottom: 780px solid #6e2c6b;
border-right: 600px solid transparent;
z-index: 4;
}
#shape4 {
position: absolute;
height: 0;
width: 0px;
top: 840px;
left: 0px;
border-bottom: 140px solid #b71234;
border-left: 1600px solid transparent;
z-index: 3;
}
#shape5 {
position: absolute;
height: 0;
width: 0px;
top: 250px;
left: 1300px;
border-bottom: 700px solid #8d1b3d;
border-left: 300px solid transparent;
z-index: 0;
}
#shape6 {
position: absolute;
height: 0;
width: 0px;
left: 1250px;
border-top: 600px solid #ff5800;
border-left: 350px solid transparent;
z-index: 2;
}
#shape7 {
position: absolute;
height: 0;
width: 0px;
left: 1130px;
border-top: 554px solid #fadc41;
border-left: 470px solid transparent;
z-index: 1;
}
<div id="container">
<div id="shape"></div>
<div id="shape2"></div>
<div id="shape3"></div>
<div id="shape4"></div>
<div id="shape5"></div>
<div id="shape6"></div>
<div id="shape7"></div>
</div>
I'm aware of the :before
and :after
options but I'm not sure if it will create the sharp edges for angled <div>
's and how this could be done. Any help?
It should look like this: