Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Amalmax's avatar

how to divide bootstrap card class to same size 3 horizontal boxes and 2 vertical boxes for image gallery

using bootstrap 4 and I have following bootstrap code block here,

<div class="card-body text-success">
   
   </div>
  

using bootstrap 4 and I have following bootstrap code block here,

I need to create image gallery same size 3 horizontal boxes and 2 vertical boxes, without any spaces between images. how could I do this?

0 likes
1 reply
gitwithravish's avatar

Umm... simply use grids?

<div class="row">
    <div class="col-md-4"></div>
    <div class="col-md-4"></div>
    <div class="col-md-4"></div>

    <div class="col-md-6"></div>
    <div class="col-md-6"></div>
</div>

You may run into image height problem. You can resolve it by the followings

  • One option is to have appropriate size of images so that you do not have to manage the image size in HTML and CSS
  • Set height manually through css
  • You can do something like this to have your images more responsive as well.
<div class="row gallery">
    <div class="img col-md-4" style="heigh:300px; background-image: url(...)"></div>
    <div class="img col-md-4" style="heigh:300px; background-image: url(...)"></div>
    <div class="img col-md-4" style="heigh:300px; background-image: url(...)"></div>

    <div class="img col-md-6" style="heigh:600px; background-image: url(...)"></div>
    <div class="img col-md-6" style="heigh:600px; background-image: url(...)"></div>
</div>

.gallery img{
    width: 100%;
    backgrouund-size: cover;
    background-position: center;
}
1 like

Please or to participate in this conversation.