I have two columns of blocks, and I need to do space between all of them the same.
Please help
Here a code:
<div class="row">
<div class="col-md-6">
<img src="./img/02.jpg" class="img-fluid" alt="Image">
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-6">
<div class="square-container bg-primary"></div>
</div>
<div class="col-md-6">
<div class="square-container bg-secondary"></div>
</div>
<div class="col-md-6">
<div class="square-container bg-success"></div>
</div>
<div class="col-md-6">
<div class="square-container bg-danger"></div>
</div>
</div>
</div>
</div>
There is Css that I also have:
body {
font-family: 'Exo 2', sans-serif;
width: 100%;
height: 100%;
background-size: cover;
}
p {
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.square-container {
width: 220px;
height: 235px;
}
.grid-gap {
display: grid;
grid-gap: 1em;
}
I tried to do it with grid. But with grid all squares goes down in one column
3
Answers
You can use css
display: grid
and define the columns and thegap
property.As you are using boostrap row class, so just use g class for gap. And it will work. Here is a sample code:
I used gx for horizontal spacing and gy for vertical spacing. You can use simple g for both horizontal and vertical spacing.
In bootstrap
col-md-6
class has50%
width and paddling left and right of15px
To remove extra space between the columns, first make
.square-container
‘s width to100%
so there won’t be extra space inside column.If you need more or less space than default
15px
, then you can manually override this or you can use gutter for spacing between columns.bootstrap gutters docs
jsfiddle