tags:

views:

26

answers:

3

if the block is text,that will be easy.but the block is image en……

A: 

Specify height equals to line-height for the container and vertical-align:middle on the image.

.container {
   height:5em;
   line-height:5em;
   text-align:center;
}
.container img {
   vertical-align:middle;
}

<div class="container">
   <img src="exemple.jpg" alt="exemple" />
</div>

Tableless and cross-browser !

MatTheCat
I am afraid this method it is only for text blocks
nancyping
I'm using it and it works perfectly, what's the problem ?
MatTheCat
Thanks all the same
nancyping
A: 

There's not a perfect way to do this without using tables, since the vertical-align CSS property unfortunately does different thing with inline elements and table elements (see http://phrogz.net/css/vertical-align/index.html).

Several solutions, with specific pro's and con's discussed, can be found here: http://blog.themeforest.net/tutorials/vertical-centering-with-css/

Of them, one of the better solutions is the third method presented:

insert a div above the content element. This will be set to height:50%; and margin-bottom:-contentheight;. The content will then clear the float and end up in the middle.

<div id="floater">
<div id="content">
    <img src="my-image.png"/>
</div>
</div>

#floater    {float:left; height:50%; margin-bottom:-120px;}
#content    {clear:both; height:240px; position:relative;}
Noah Callaway
I think it is a way.thanks!
nancyping
A: 

html code:

<div class="zxx_align_box_5 fix"> <a href="#"> <img src="http://image.zhangxinxu.com/image/study/s/s128/mm1.jpg" /></a><a href="#"><img src="http://image.zhangxinxu.com/image/study/s/s128/mm2.jpg" /></a></div>

the css:

.zxx_align_box_5 a{display:inline-block; width:1.2em; font-size:128px; text-align:center; vertical-align:middle;} .zxx_align_box_5 a img{vertical-align:middle; padding:2px; border:1px solid #beceeb;}

nancyping