0

I have a div with 3 images :

.main_block {
  width: 800px;
}

.main_block: before, .main_block: after {
  overflow: hidden;
  content: "";
  display: table;
}

.main_block: after {
  clear: both;
}

.inner_block {
  display: inline-block;
  float: left;
  padding-left: 20px
}

.inner_block img {
  height: auto;
  vertical-align: middle;
}
<div class="main_block">
  <div class="inner_block">
    <img src="img/features/1.png"/>
  </div>

  <div class="inner_block">
    <img src="img/features/2.png"/>
  </div>  
  <div class="inner_block">
    <img src="img/features/3.png"/>
  </div>   
</div>

And it allways align to the left of the page, i tried to add position relative to the main div but it's still align to the left

Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49
YosiFZ
  • 7,792
  • 21
  • 114
  • 221

4 Answers4

2

I use flexbox for this:

display:flex is the key

here is the code

.main_block {
    width: 100%;
    display:flex;
    justify-content:space-between;
}

.inner_block {
    display: inline-block;    
    margin: 0 auto;
}
<div class="main_block">
        <div class="inner_block">
                <img src="http://html5doctor.com/wp-content/themes/html5doctor2/images/HTML5_Badge_64.png"/>
            </div>

            <div class="inner_block">
                <img src="http://html5doctor.com/wp-content/themes/html5doctor2/images/HTML5_Badge_64.png"/>
            </div>  
        <div class="inner_block">
                <img src="http://html5doctor.com/wp-content/themes/html5doctor2/images/HTML5_Badge_64.png"/>
            </div>   
    </div>
Maciej Wojcik
  • 2,115
  • 2
  • 28
  • 47
0

I just add a text-align:center; to the main div, and remove float: left; on the inner divs.

.main_block {
  width: 800px;
  text-align:center;
}

.main_block: before, .main_block: after {
  overflow: hidden;
  content: "";
  display: table;
}

.main_block: after {
  clear: both;
}

.inner_block {
  display: inline-block;
  padding-left: 20px
}

.inner_block img {
  height: auto;
  vertical-align: middle;
}
<div class="main_block">
  <div class="inner_block">
    <img src="img/features/1.png"/>
  </div>

  <div class="inner_block">
    <img src="img/features/2.png"/>
  </div>  
  <div class="inner_block">
    <img src="img/features/3.png"/>
  </div>   
</div>

Is it what you want ?

Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49
-1

It is because of the float property in the .inner-block class. You can remove it and add <center></center> selector in the html file. Code snippet below:

.main_block {
    width: 800px;
}

.main_block: before, .main_block: after {
    overflow: hidden;
    content: "";
    display: table;
}

.main_block: after {
    clear: both;
}

.inner_block {
    display: inline-block;
    padding-left: 20px
}

.inner_block img {
    height: auto;
    vertical-align: middle;
}
<div class="main_block">
      <center>
        <div class="inner_block">
                <img src="http://blinklist.com/files/logos/lastpass-logo.gif"/>
            </div>

            <div class="inner_block">
                <img src="http://blinklist.com/files/logos/lastpass-logo.gif"/>
            </div>  
        <div class="inner_block">
                <img src="http://blinklist.com/files/logos/lastpass-logo.gif"/>
            </div>   
            </center>
    </div>
dwrdlnz
  • 134
  • 5
-1

I think it works

.main_block { width: 800px; margin: 0 auto }