English 中文(简体)
如何垂直对齐 <li> 中间的图像?
原标题:How to vertically align image middle in <li>?
  • 时间:2012-05-23 03:43:22
  •  标签:
  • html
  • css

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>

提前感谢。

最佳回答

更新代码见演示文稿 : - http://jsbin.com/ozixop/edit#javascript,html,live

您只需更新您的 cs 并添加以下垂直中点的几处属性:-

    li.qq2{
background-color: red;
display: table-cell;
height: 400px;
text-align: center;
vertical-align: middle;
width: 400px;
    }
问题回答
li.qq2{
   display : table-cell;
   vertical-align : middle;
   text-align : center;
}

这应该行得通。

在铬、Safari、FF和IE 9测试。

.qq2 img{vertical-align:middle;}

应该工作。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签