0

I am experimenting with the grid system (no bootstrap) and I am having an issue. My 4 divs (containing placeholders) who should all take 25% are not aligned in a row, only 3 of them. but 4x 25% = 100% . When I put 20% it fits but why? When I remove the 10% container margin it is the same situation.

What is the problem? Thanks in advance!

have a look here in the dev tools screenshot

My code is:

/* Book page */

#book-container {
  margin: 10%;
}

.h-header {
  background-color: #5f1c36;
  height: 150px;
}

.book-divs {
  display: inline-block;
}


/* Simple Responsive Framework. */

.row {
  width: 100%;
}


/********** Large devices only **********/

@media (min-width: 1025px) {
  .col-lg-1 {
    width: 8.33%;
  }
  .col-lg-2 {
    width: 16.66%;
  }
  .col-lg-3 {
    width: 25%;
  }
  .col-lg-4 {
    width: 33.33%;
  }
  .col-lg-5 {
    width: 41.66%;
  }
  .col-lg-6 {
    width: 50%;
  }
  .col-lg-7 {
    width: 58.33%;
  }
  .col-lg-8 {
    width: 66.66%;
  }
  .col-lg-9 {
    width: 74.99%;
  }
  .col-lg-10 {
    width: 83.33%;
  }
  .col-lg-11 {
    width: 91.66%;
  }
  .col-lg-12 {
    width: 100%;
  }
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/tiny-slider/2.9.4/min/tiny-slider.js"></script>
  <script src="https://kit.fontawesome.com/99f2f640c0.js" crossorigin="anonymous"></script>
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/tiny-slider/2.9.4/tiny-slider.css">
  <link rel="stylesheet" href="/css/style.css">
  <title> CG </title>
</head>

<body>

  <div class="row">
    <div class="h-header"></div>
  </div>

  <div id="book-container">
    <div class="row">
      <div>
        <div class="col-lg-3 col-md-3 col-sm-6 book-divs ">
          <img src="https://via.placeholder.com/200x300">
        </div>
        <div class="col-lg-3 col-md-3 col-sm-6 book-divs ">
          <img src="https://via.placeholder.com/200x300">
        </div>
        <div class="col-lg-3 col-md-3 col-sm-6 book-divs ">
          <img src="https://via.placeholder.com/200x300">
        </div>
        <div class="col-lg-3 col-md-3 col-sm-6 book-divs ">
          <img src="https://via.placeholder.com/200x300">
        </div>
      </div>
    </div>

</body>

</html>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161

1 Answers1

-1

-- You can use "cal()" when you want adjust div width.
https://developer.mozilla.org/en-US/docs/Web/CSS/calc()

-- display inline block contain some default space in HTML.

-- in your code i add some 15px space in "book-divs" & in "col-md-3" i use cal() function for maintain space like this width: calc(25% - 33px).

-- using width:100% i fi

 /* Book page */
body{
  margin: 0;
}

#book-container {
  margin: 10%;
}

.h-header {
  background-color: #5f1c36;
  height: 150px;
}

.book-divs {
  padding: 15px;
  display: inline-block;
}


/* Simple Responsive Framework. */

.row {
  width: 100%;
}
.book-wrapper .book-divs img {
    width: 100%;
}



/********** Large devices only **********/

@media (min-width: 1025px) {
  .col-lg-1 {
    width: 8.33%;
  }
  .col-lg-2 {
    width: 16.66%;
  }
  .col-lg-3 {
    width: calc(25% - 33px);
  }
  .col-lg-4 {
    width: 33.33%;
  }
  .col-lg-5 {
    width: 41.66%;
  }
  .col-lg-6 {
    width: 50%;
  }
  .col-lg-7 {
    width: 58.33%;
  }
  .col-lg-8 {
    width: 66.66%;
  }
  .col-lg-9 {
    width: 74.99%;
  }
  .col-lg-10 {
    width: 83.33%;
  }
  .col-lg-11 {
    width: 91.66%;
  }
  .col-lg-12 {
    width: 100%;
  }
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/tiny-slider/2.9.4/min/tiny-slider.js"></script>
  <script src="https://kit.fontawesome.com/99f2f640c0.js" crossorigin="anonymous"></script>
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/tiny-slider/2.9.4/tiny-slider.css">
  <link rel="stylesheet" href="/css/style.css">
  <title> CG </title>
</head>

<body>

  <div class="row">
    <div class="h-header"></div>
  </div>

  <div id="book-container">
    <div class="row">
      <div class="book-wrapper">
        <div class="col-lg-3 col-md-3 col-sm-6 book-divs ">
          <img src="https://via.placeholder.com/200x300">
        </div>
        <div class="col-lg-3 col-md-3 col-sm-6 book-divs ">
          <img src="https://via.placeholder.com/200x300">
        </div>
        <div class="col-lg-3 col-md-3 col-sm-6 book-divs ">
          <img src="https://via.placeholder.com/200x300">
        </div>
        <div class="col-lg-3 col-md-3 col-sm-6 book-divs ">
          <img src="https://via.placeholder.com/200x300">
        </div>
      </div>
    </div>

</body>
<style type="text/css">
 
</style>
</html>
Satish Modha
  • 759
  • 1
  • 4
  • 8