最代码官方的gravatar头像
最代码官方 2015-11-18 00:11:53

html网页中设置图片img标签垂直居中的代码

今天在实现wap版本的最代码发现logo图片通过css语法:vertical-align:middle;实现垂直居中,搜索了半天总结分享下靠谱的答案:

<style type="text/css">
#box{
width:500px;height:400px;
display:table;
text-align:center;
background-color: #29A7E1;
}
#box span{
display:table-cell;
vertical-align:middle;
}
</style>

1.使用table

<div id="box">
    <table width="100%" height="100%">
        <tr>
            <td align="center">
                <img src="http://static.zuidaima.com/resource/img/logo.png" />
            </td>
        </tr>
    </table>
</div>

2.使用display:table和display:talbe-cell

<div id="box">
  <span><img src="http://static.zuidaima.com/resource/img/logo.png" alt="" /></span>
</div>

效果如下图

html网页中设置图片img标签垂直居中的代码


打赏

文件名:html网页中设置图片img标签垂直居中的代码.rar,文件大小:0.635K 下载
  • /
    • /html网页中设置图片img标签垂直居中的代码.html
最代码最近下载分享源代码列表最近下载
511076827  LV33 2022年4月6日
wxsuperwx  LV17 2017年12月3日
雪初寒  LV2 2017年6月25日
qwerasdQQ  LV13 2017年5月31日
zt1992810  LV1 2017年3月2日
18523528882  LV1 2017年2月28日
dagf113225  LV68 2016年10月24日
xiaojiao  LV1 2016年6月17日
wyb  LV8 2015年12月3日
最代码最近浏览分享源代码列表最近浏览
kiko28 1月8日
暂无贡献等级
淡凉123456  LV9 2022年12月14日
moomin709  LV24 2022年7月6日
511076827  LV33 2022年4月6日
深夜猫头鹰  LV14 2020年12月7日
银河系浪漫小赵  LV1 2020年12月1日
云键仙 2020年11月25日
暂无贡献等级
31318757 2020年11月9日
暂无贡献等级
lj402301  LV1 2020年10月13日
lichengai  LV7 2020年6月15日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友