Reputation: 497
Hell all: the below is the html code, I want to vertically align every image in li , no idea after googling a lot. I can use jquery to set it margin-top according to images' height, but it's inconvenient solution.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312"/>
<style type="text/css">
.psdthumb2 ul {
list-style: none;
}
li.qq2{
height: 400px;
width: 400px;
background-color: red;
}
</style>
</head>
<body>
<div class="psdthumb2">
<ul>
<li>111111</li>
<li class="qq2">
<img src="http://mat1.qq.com/www/images/allskin/wmlogo.gif">
</li>
</ul>
<ul>
<li>222222</li>
<li class="qq2">
<img src="http://img11.360buyimg.com/n4/3445/522086b7-dc0a-432c-b027-7b2a80c79f29.jpg">
</li>
</ul>
</div>
</body>
</html>
thanks in advance.
Upvotes: 0
Views: 10600
Reputation: 7778
see the demo with your updated code:- http://jsbin.com/ozixop/edit#javascript,html,live
you just update your css and add few properties for vertical middle as mentioned below:-
li.qq2{
background-color: red;
display: table-cell;
height: 400px;
text-align: center;
vertical-align: middle;
width: 400px;
}
Upvotes: 1
Reputation: 5914
Here's a working example:
CSS
.psdthumb2 ul
{
list-style: none;
}
li.qq2
{
height: 400px;
width: 400px;
background-color: red;
display: table-cell;
vertical-align: middle;
}
HTML
<div class="psdthumb2">
<ul>
<li>111111</li>
<li class="qq2">
<img src="http://mat1.qq.com/www/images/allskin/wmlogo.gif">
</li>
</ul>
<ul>
<li>222222</li>
<li class="qq2">
<img src="http://img11.360buyimg.com/n4/3445/522086b7-dc0a-432c-b027-7b2a80c79f29.jpg">
</li>
</ul>
</div>
Basically you just need to add display: table-cell; vertical-align: middle;
to your css class.
Hope it helps!
Upvotes: 2
Reputation: 3404
li.qq2{
display : table-cell;
vertical-align : middle;
text-align : center;
}
This should work.
Tested in Chrome, Safari, FF and IE 9.
Upvotes: 2