I am trying to achieve grid through the flexbox system as in the image, and I succeeded:
Can there be a better way to achieve this by staying in the realms of flexbox for now.
CSS β
@import url('https://fonts.googleapis.com/css?family=PT+Sans');
@import url('https://fonts.googleapis.com/css?family=Lato:100,100i,300,300i,400,400i,700,700i,900,900i');
body {
font-family: 'Lato', sans-serif;
font-size: 3rem;
}
h1,h2,h3,h4,h5,h6 {
font-family: 'Lato', sans-serif;
padding: 0;
margin:0;
color: #2D2D2D;
}
p {
margin: 0;
padding: 0;
font-size: 0.8rem;
line-height: 1.675;
}
h1{
font-size: 2.5rem;
}
ul {
list-style-type: none;
}
section {
max-width: 700px;
margin:auto;
padding: 20px;
}
.box {
width: 100%;
margin: 10px;
text-align: center;
color: white;
padding: 10vh 0;
}
.box1 {background-color: #9b59b6;}
.box2 {background-color: #34495e;}
.box3 {background-color: #e67e22;}
.box4 {background-color: #e74c3c;}
.box5 {background-color: #2ecc71;}
.flexgrid {
display: flex;
min-height: 50vh;
}
.left-side,
.right-bottom,
.right-top {
display: flex;
}
.right-side {
display: flex;
flex-wrap: wrap;
}
.left-side,
.right-side {
width: 50%;
}
.right-side > * {
width: 100%;
}
.left-side2, .right-side2 {
width: 25%;
display: flex;
flex-wrap: wrap;
}
.medium {
width: 50%;
display: flex;
}
HTML β
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<section class="flexgrid">
<article class="left-side">
<div class="box box1">1</div>
</article>
<article class="right-side">
<div class="right-top">
<div class="box box2">2</div>
</div>
<div class="right-bottom">
<div class="box box3">3</div>
<div class="box box4">4</div>
</div>
</article>
</section>
<section class="flexgrid">
<article class="left-side">
<div class="box box1">1</div>
</article>
<article class="right-side">
<div class="right-top">
<div class="box box2">2</div>
<div class="box box3">3</div>
</div>
<div class="right-bottom">
<div class="box box4">4</div>
<div class="box box5">5</div>
</div>
</article>
</section>
<section class="flexgrid">
<article class="left-side2">
<div class="box box2">2</div>
<div class="box box3">3</div>
</article>
<article class="medium">
<div class="box box1">1</div>
</article>
<article class="right-side2">
<div class="box box4">4</div>
<div class="box box5">5</div>
</article>
</section>
</body>
</html>