0

i have problem with align divs inside main centered div.

Here is my code

<style>
body {
  max-width: 1150px;
  min-width: 900px;
  margin:0 auto; }

.container {
  text-align:center;
  background-color:#e1e1e1; }

.box {
  width: 250px; }

.inline-block {
  color: #eee;
  margin: 10px 0px 0px 10px;
  text-align: center;
  display:inline-block; }

.one {
  height: 22px;
  background: #744; }

</style>

<div class="container">
    <div class="inline-block"><div class="one box">1</div>
    </div>
    <div class="inline-block"><div class="one box">2</div>
    </div>
    <div class="inline-block"><div class="one box">3</div>
    </div>
    <div class="inline-block"><div class="one box">4</div>
    </div>
    <div class="inline-block"><div class="one box">5</div>
    </div>
    <div class="inline-block"><div class="one box">6</div>
    </div>
    <div class="inline-block"><div class="one box">7</div>
    </div>
    <div class="inline-block"><div class="one box">8</div>
    </div>
</div>

Result when i resize window

What i need

P.S. Sorry for my English, i hope you understand this.

Mohsen Safari
  • 6,669
  • 5
  • 42
  • 58
  • Here are two simple methods to center divs within divs, vertically, horizontally or both (pure CSS): http://stackoverflow.com/a/31977476/3597276 – Michael Benjamin Aug 20 '15 at 15:13

2 Answers2

0

Here is the DEMO

Just it's simple add Float:left to it

coder
  • 13,002
  • 31
  • 112
  • 214
0

I think .container { text-align:left;} will do the trick for you, of course then you'll need .container > div { text-align:center;}. And I would also suggest to add classes to those divs so you don't have to use the immediate child selector.

xpy
  • 5,481
  • 3
  • 29
  • 48