Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align image in center and middle within div

Tags:

html

css

I have following div

<div id="over" style="position:absolute; width:100%; height:100%>  <img src="img.png"> </div> 

How to align the image so as to be located in the middle and center of div ?

like image 922
Dro1n2 Avatar asked Feb 03 '11 15:02

Dro1n2


People also ask

How do I align an image to a div?

Aligning an image means to position the image at center, left and right. We can use the float property and text-align property for the alignment of images. If the image is in the div element, then we can use the text-align property for aligning the image in the div.

Can you put an image inside a div?

To auto-resize an image or a video to fit in a div container use object-fit property. It is used to specify how an image or video fits in the container. object-fit property: This property is used to specify how an image or video resize and fit the container.

How do I align an image in the middle of CSS?

To center an image with CSS Grid, wrap the image in a container div element and give it a display of grid . Then set the place-items property to center. P.S.: place-items with a value of center centers anything horizontally and vertically.


1 Answers

body {    margin: 0;  }    #over img {    margin-left: auto;    margin-right: auto;    display: block;  }
<div id="over" style="position:absolute; width:100%; height:100%">    <img src="http://www.garcard.com/images/garcard_symbol.png">  </div>

JSFiddle

like image 162
Gurpreet Singh Avatar answered Nov 28 '22 20:11

Gurpreet Singh