14

Possible Duplicate:
How to make an image center (vertically & horizontally) inside a bigger div

HTML code:

<div class="promo_tumbs col_12">
    <div class="promo_tumb"></div>
    <div class="promo_tumb"></div>
    <div class="promo_tumb"></div>
    <div class="promo_tumb"></div>
    <div class="promo_tumb"></div>
</div>

CSS part:

.promo_tumbs {
    height: 155px;
    background: #058;
}
.promo_tumb {
    height: 75px;
    width: 125px;
    background: #990000;
    float: left;
    margin: 0 10px;
    text-align: center;
}

How can I vertically center .promo_tumb?

Community
  • 1
  • 1
Sasha
  • 8,521
  • 23
  • 91
  • 174

5 Answers5

18

Read this article on vertical centering.

http://www.jakpsatweb.cz/css/css-vertical-center-solution.html

If you dont wanna support IE7 or lesser then you can use vertical-align : middle.

Otherwise:

  1. Set display to table in .promo_tumbs col_12
  2. Set vertical-align to middle & display to table-cell for .promo_tumb

and it should work.

Ashwin Krishnamurthy
  • 3,750
  • 3
  • 27
  • 49
4

Will the heights (155px and 75px respectively) always be fixed? In that case it'd be as simple as changing the .promo_tumb margin:

margin: 40px 10px
David Hedlund
  • 128,221
  • 31
  • 203
  • 222
0

use the vertical-align: middle; in the css/style for promo_thumbs.

Manuel
  • 10,153
  • 5
  • 41
  • 60
0
css part insert in head section..........

   <style type="text/css">
  .promo_tumbs {height: 155px; background: #058; }
  .promo_tumb {height: 75px; width: 125px; background: #990000; float: left; 

   margin: 40px 50px; 

   text-align: center; }
  </style> 

body part coding......

          <div class="promo_tumbs col_12">
                <div class="promo_tumb"></div>
                <div class="promo_tumb"></div>
                <div class="promo_tumb"></div>
                <div class="promo_tumb"></div>
                <div class="promo_tumb"></div>
            </div>
0
.promo_tumbs {height: 155px; background: #058;
    vertical-align: middle;
    display:table-cell;
 }
BLUEPIXY
  • 39,699
  • 7
  • 33
  • 70