使图像在html中对齐屏幕的中心 [英] Making image align center of screen in html
本文介绍了使图像在html中对齐屏幕的中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
html:
< table width = 100%height = 100%>
< tr>
< td style =text-align:center; vertical-align:middle;>
< img src =/>
< / td>
< / tr>
< / table>
css:
html,body
{
height:100%;
解决方案
用 div
和 img
HTML
< div>< img src =http://placehold.it/350x150>< / div>
CSS
html,body
{
height:100%;
保证金:0;
padding:0;
}
div {
position:relative;
身高:100%;
宽度:100%;
}
div img {
position:absolute;
top:0;
剩下:0;
right:0;
bottom:0;
margin:auto;
}
I am loading image on iOS device. I want my image to be centered horizontally as well vertically center with all screens and orientation . I have tried it using table and td , It is aligning horizontally center but not aligning vertically middle . This is what I have tried html:
<table width=100% height=100%>
<tr>
<td style="text-align: center; vertical-align: middle;">
<img src="" />
</td>
</tr>
</table>
css:
html, body
{
height: 100%;
}
解决方案
Instead of Table, You can achieve the same with div
and img
HTML
<div><img src="http://placehold.it/350x150"></div>
CSS
html, body
{
height: 100%;
margin:0;
padding:0;
}
div {
position:relative;
height: 100%;
width:100%;
}
div img {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
margin:auto;
}
这篇关于使图像在html中对齐屏幕的中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文