2

I want to add spaces between columns without losing the grid system layout , when I add margin to the card the layout become 3 cards not 4

here is the code , the problem is that i can't control the spacing between cards and it should be four cards in every row

 <div class ="container">
  <div class ="row">
    <div class ="d-flex flex-wrap">
        <div class ="card p-0 col-12 col-lg-3">
           <img src = "#">
           [i write the title here]<p> .... </p>
        </div>
         <div class ="card p-0 col-12 col-lg-3">
           <img src = "#">
           <p> .... </p>
        </div>
        <div class ="card p-0 col-12 col-lg-3">
           <img src = "#">
           <p> .... </p>
        </div>
        <div class ="card p-0 col-12 col-lg-3">
           <img src = "#">
           <p> .... </p>
        </div>
    </div>
  </div>
 </div>

<style>
.card img{
width:100%;
}
..card p{
width:100%;
color : green;
font-size :18px;
float:right
}
</style>

2 Answers2

1

Since we can't see all your CSS, I don't know if this is for sure, but try using grid-row-gap and grid-column-gap for the spacing between the rows and the spacing between the columns. You can also use grid-template-columns to specify how many columns you want.

Hope this helps!! Tilier

Tilier
  • 80
  • 7
1

Similar questions have been asked before:

Spacing & sizing columns using Bootstrap 4
Bootstrap: add margin/padding space between columns

Adjust the spacing by adjusting the padding. Also, card should be inside columns and columns are always inside row. For example, here px-4 increases the spacing:

<div class="row">  
    <div class="col-12 col-lg-3">
        <div class="card">
            <img src="#"> [i write the title here]<p> .... </p>
        </div>
    </div>
    <div class="px-4 col-12 col-lg-3">
        <div class="card">
            <img src="#">
            <p> .... </p>
        </div>
    </div>
    <div class="px-4 col-12 col-lg-3">
        <div class="card">
            <img src="#">
            <p> .... </p>
        </div>
    </div>
    <div class="col-12 col-lg-3">
        <div class="card">
            <img src="#">
            <p> .... </p>
        </div>
    </div>
</div>

Demo

YakovL
  • 7,557
  • 12
  • 62
  • 102
Carol Skelly
  • 351,302
  • 90
  • 710
  • 624