Flexbox makes this pretty easy with a justify-content
value of space-between
:
.flexrow {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
This makes sure that the items will stick to the outer edge of the container when the dimensions are correct.
The gutter is created by setting the width of the flex items to less than 100% of the total width. Here we want 2 columns so you can set the width of the items to 50% minus enough to make up the gutter width:
.flexcol {
width: calc(50% - 5px); // 50% minus 5px for each column, with 2 columns that's a 10px gutter space between the two columns.
margin-bottom: 10px; //space between the rows, remove if you dont want that.
}
Now to set the first and third rows, just change the width accordingly:
.col-1,
.col-6 {
width: calc(40% - 5px); // here's the 40% ones
}
.col-2,
.col-5 {
width: calc(60% - 5px); // and the 60% ones
}
For the 100% change at 992px, just add a media query and update the necessary values:
@media (max-width: 992px) {
.flexcol {
width: 100%; // 100% width, no margin or anything to deal with because of the space-between layout approach
}
.col-5 {
margin-bottom: 10px; // add this so the 5th and 6th items have space between them when 100% wide
}
}
.flexrow {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
background: #efefef;
}
.flexcol {
width: calc(50% - 5px);
margin-bottom: 10px;
/* just for visibility */
border: 1px solid red;
padding: 20px;
background: #fff;
box-sizing: border-box;
}
.col-1,
.col-6 {
width: calc(40% - 5px);
}
.col-2,
.col-5 {
width: calc(60% - 5px);
}
.col-5,
.col-6 {
margin-bottom: 0;
}
@media (max-width: 992px) {
.flexcol {
width: 100%;
}
.col-5 {
margin-bottom: 10px;
}
}
<div class="flexrow">
<div class="flexcol col-1">THING 1</div>
<div class="flexcol col-2">THING 2</div>
<div class="flexcol col-3">THING 3</div>
<div class="flexcol col-4">THING 4</div>
<div class="flexcol col-5">THING 5</div>
<div class="flexcol col-6">THING 6</div>
</div>