Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making image align center of screen in html

Tags:

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%; } 
like image 461
V-Xtreme Avatar asked Jan 02 '14 07:01

V-Xtreme


People also ask

How do I align an image to the center right in HTML?

In order to center an image in HTML either use the text-align property or the margin-right and margin-left property.

How do you center align an image in HTML 5?

An <img> element is an inline element (display value of inline-block ). It can be easily centered by adding the text-align: center; CSS property to the parent element that contains it. To center an image using text-align: center; you must place the <img> inside of a block-level element such as a div .

How do I center align an image in CSS?

To center an image, we have to set the value of margin-left and margin-right to auto and make it a block element by using the display: block; property. If the image is in the div element, then we can use the text-align: center; property for aligning the image to center in the div.

How do I center align in HTML code?

The <center> tag was used in HTML4 to center-align text.


1 Answers

Instead of Table, You can achieve the same with div and img

Working Demo

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; } 
like image 134
Surjith S M Avatar answered Nov 09 '22 12:11

Surjith S M