Expanding upon the @G-Cyrillus response, which is the approved solution.
To ensure a better user experience on certain screen sizes by making your columns full width, insert this code snippet at the end of your CSS file:
/* Full Width below 768 pixels */
@media only screen and (max-width: 768px) {
.col-1, .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-10, .col-11, .col-12{
grid-column: auto/span 12;
}
}
Here is how your complete code should appear:
.grid {
margin: 1em;
border: solid lightgray;
background: lightgray;
display: grid;
grid-template-columns: repeat(12, 1fr);
grid-gap: 2px;
counter-reset: div;
}
.grid div {
border: solid;
text-align: center;
}
.grid div:before {
counter-increment: div;
content: 'N°' counter(div);
}
.grid div[class]:after {
display: block;
text-align: center;
background: lightblue;
content: "Class applied : "attr(class);
color: crimson;
}
/* spanning cols, complete values missing */
.col-2 {
grid-column: auto/span 2;
}
.col-3 {
grid-column: auto/span 3;
}
.col-6 {
grid-column: auto/span 6;
}
.col-8 {
grid-column: auto/span 8;
}
/* spanning rows , complete values missing*/
.row-2 {
grid-row: auto/span 2;
}
/* Full Width below 768 pixels */
@media only screen and (max-width: 768px) {
.col-1, .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-10, .col-11, .col-12{
grid-column: auto/span 12;
}
}
<div class="grid">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div class="grid">
<div class="col-3"></div>
<div class="col-3"></div>
<div class="col-3"></div>
<div class="col-3"></div>
<div class="col-6"></div>
<div class="col-6"></div>
<div class="col-2 row-2"></div>
<div class="col-8"></div>
<div class="col-2 row-2"></div>
<div class="col-3"></div>
<div class="col-2"></div>
<div class="col-3"></div>
</div>