Filed under: 交互设计 |
Posted on 五月 27th, 2008 由 owen
很久以来,自己也有这个疑惑,由于很久没有专职做这个了,就没有深入的研究过重构方面的东西,只是一直关注着,不曾落下。
转载记录一下,以免自己遗忘。
转自:http://www.planabc.net/2008/05/26/img_vertical_center_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" />
- <title>Vertical Middle</title>
- <style>
- .box {
- /*非IE的主流浏览器识别的垂直居中的方法*/
- display: table-cell;
- vertical-align:middle;
- /*设置水平居中*/
- text-align:center;
- /* 针对IE的Hack */
- *display: block;
- *font-size: 175px;/*约为高度的0.873,200*0.873 约为175*/
- *font-family:Arial;/*防止非utf-8引起的hack失效问题,如gbk编码*/
- width:200px;
- height:200px;
- border: 1px solid #eee;
- }
- .box img {
- /*设置图片垂直居中*/
- vertical-align:middle;
- }
- </style>
- </head>
- <body>
- <div class="box">
- <img src="http://pics.taobao.com/bao/album/promotion/taoscars_180x95_071112_sr.jpg" />
- </div>
- </body>
- </html>
http://listenpro.googlepages.com/demo_vertical_css.html
- <!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" />
- <title>Vertical Middle</title>
- <style>
- .itm{border:2px solid #ccc;width:160px;height:160px;text-align:center;}
- .blank{width:0;height:160px;}
- .itm img{vertical-align:middle;}
- </style>
- </head>
- <body>
- <div class="itm">
- <img src="http://cn.yimg.com/i/comn/blank.gif" class="blank" />
- <a href=""><img src="http://cn.yimg.com/bookmark/yisou/mp3/m060616.jpg"/></a>
- </div>
- </body>
- </html>
阅读次数: 1279

曰:沙发空缺,还不快抢?
留下点什么吧