htmlcssbootstrap-4bootstrap-5bootstrap-grid

how do i create a photo collage with html css and bootstrap


I tried adding images to the div it did't work for me,

<img
                  class="img-fluid"
                  src="https://via.placeholder.com/800x800"
                  style="border-radius: 20px"
                />

Therefore I tried adding background images to divs, and when i add images to the divs the images wont show?can anyone tell me a solution to this and why this is hapenning?

<div class="col-lg-6">
            <!-- ??????? how do i create the grid -->
            <div class="row g-0">
              <div class="col-lg-4">
                <div
                  class="imgcollage"
                  style="background-image: url(../img/img2.jpg)"
                ></div>
              </div>
              <div class="col-lg-8">
                <div
                  class="imgcollage"
                  style="background-image: url(../img/img2.jpg)"
                ></div>
              </div>
            </div>
            <div class="row g-0">
              <div class="col-lg-8">
                <div
                  class="imgcollage"
                  style="background-image: url(../img/img2.jpg)"
                ></div>
              </div>
              <div class="col-lg-4">
                <div
                  class="imgcollage"
                  style="background-image: url(../img/img3.jpg)"
                ></div>
              </div>
            </div>
          </div>

here's the css

.imgcollage {
  height: 100%;
  width: 100%;
  background-position: center;
  background-size: cover;
  border-radius: 20px;
}


Solution

  • sorry i'm posting another answer with working pictures the other pics didn't work because they aren't actually urls

    .imgcollage {
      height: 100%;
      width: 100%;
      background-position: center;
      background-size: cover;
      border-radius: 20px;
    }
    .col-lg-6{
      display:grid;
      /* declares how many columns there will automaticaly be and how big they will be +rows and how big of a gap between them*/
      grid-template-columns: 250px 250px;
      grid-template-rows: 250px 250px;
      grid-gap: 15px;
    <div class="col-lg-6">
                <!-- ??????? how do i create the grid -->
                    <div
                      class="imgcollage"
                      style="background-image: url(https://images.pexels.com/photos/2253275/pexels-photo-2253275.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500)"
                    ></div>
                    <div
                      class="imgcollage"
                      style="background-image: url(https://images.pexels.com/photos/1108099/pexels-photo-1108099.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500)"
                    ></div>
                    <div
                      class="imgcollage"
                      style="background-image: url(https://images.pexels.com/photos/731022/pexels-photo-731022.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500)"
                    ></div>
                    <div
                      class="imgcollage"
                      style="background-image: url(https://images.pexels.com/photos/2623968/pexels-photo-2623968.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500)"
                    ></div>
                  </div>