I'm getting crazy with a grid. For my website I have a modular grid with a fixed size, 3 x 2. In this grid I can distribute, without space and with a 1 px margin between every element, some blocks.
I can have 5 types of block:
- huge, a 3 x 2 block
- big-square, a 2 x 2 block
- horizontal, a 2 x 1 block
- vertical, a 1 x 2 block
- square, 1 x 1 block.
In this image I show some variants, and un the right the "tablet" version. 
I have to generate the grid using code so I don't want to create X fixed templates to fill, I want a single template that adapt itself. Now I'm using float and some class for every variant.
For Example for first cover variant
<section class="cover variant-1">
<div class="cover-block horizontal" id="block-1">
<img alt="image" src="https://via.placeholder.com/900x350" />
</div>
<div class="cover-block small" id="block-2">
<img alt="image" src="https://via.placeholder.com/450x350" />
</div>
<div class="cover-block square" id="block-3">
<img alt="image" src="https://via.placeholder.com/450x350" />
</div>
<div class="cover-block horizontal" id="block-4">
<img alt="image" src="https://via.placeholder.com/900x350" />
</div>
</section>
And for the second cover variant
<section class="cover variant-2">
<div class="cover-block big-square" id="block-1">
<img alt="image" src="https://via.placeholder.com/900x700" />
</div>
<div class="cover-block vertical" id="block-2">
<img alt="image" src="https://via.placeholder.com/450x700" />
</div>
</section>
The CSS is
.cover {
float: none;
max-width: 1350px;
max-height: 700px;
margin: 0;
}
.cover .cover-block {
float: left;
position: relative;
border: 0px solid #fff;
}
.cover .cover-block img {
width: 100%;
height: 100%;
}
.cover .cover-block.huge {
width: 1350px;
height: 700px;
}
.cover .cover-block.vertical {
width: 450px;
height: 700px;
}
.cover .cover-block.horizontal {
width: 900px;
height: 350px;
}
.cover .cover-block.big-square {
width: 900px;
height: 700px;
}
.cover .cover-block.square {
width: 450px;
height: 350px;
}
.cover .variant-1 #block-1 {
border-width: 0 1px 0 0;
}
.cover .variant-1 #block-2 {
border-width: 0 1px 0 0;
}
.cover .variant-1 #block-4 {
border-width: 1px 1px 0 0;
}
.cover .variant-1 #block-5 {
border-width: 1px 0 0 0;
}
.cover .variant-2 #block-1 {
border-width: 0 1px 0 0;
}
.cover .variant-2 #block-3 {
border-width: 1px 1px 0 0;
}
.cover .variant-2 #block-4 {
border-width: 1px 0 0 0;
}
.cover .variant-2 #block-5 {
display: none;
}
Whit the floats I have to define an ID for every block to handle the 1 pixel space just in one direction, and I have also a lot of media queries to have this grid responsive.
Is there a smarter way to design my grid, maybe using flexbox?
Here is the Codepen