3

I have the following div before my footer and i want to have evenly distribute some more divs in it. currently i'm using manual margin percentage but I want to know is there a way to let CSS automatically distribute them with even space?

CSS

#books {margin:10px auto;}          
.bookimage {width:7%;
            padding-top:7%;
            display:inline-block;
            margin:2%;
            }

HTML

<div id="books">
     <div class="bookimage">  </div>
     <div class="bookimage"> </div>
     <div class="bookimage"> </div>
     <div class="bookimage"> </div>
     <div class="bookimage"> </div>
     <div class="bookimage"> </div>
     <div class="bookimage"> </div>
     <div class="bookimage"> </div>
</div>
Leo The Four
  • 699
  • 9
  • 14

2 Answers2

5

Use this in your CSS

#books {
    margin:10px auto;
    display:flex;
    justify-content:space-between;
}
Adam Nierzad
  • 942
  • 6
  • 19
3

First of all I would recommend to change your IDs to classes instead. Multiple elements with the same ID is invalid and could cause problems. If you dont need support for IE9 and below you can use flexbox to solve your problem.

HTML

<div class="books">
  <div class="book"></div>
  <div class="book"></div>
  <div class="book"></div>
  <div class="book"></div>
</div>

CSS

.books {
  display: flex;
  flex-flow: row wrap;
  justify-content: space-between;
  margin: 10px auto;
}
Alexander
  • 79
  • 9