-1

Possible Duplicate:
How to center image inside div

I need to be able to put the image in the center of the div. My image needs to be in the center in whatever resolution.

Code:

<div style="width:100%; height:20%;">
    <img src="images/pic.png" id="image"  style="width: 208px; height: 75px;margin-left: 42%;" alt=""/>
</div>

This is not working as it should.

Community
  • 1
  • 1
user123_456
  • 5,635
  • 26
  • 84
  • 140

4 Answers4

4
<div style="width:100%; height:20%; text-align:center">
    <img src="images/pic.png" id="image"  style="width: 208px; height: 75px; margin:0 auto;" alt=""/>
</div>

Should work for ya

George
  • 36,413
  • 9
  • 66
  • 103
3

Try this:

<div style="width:100%; height:20%;text-align:center;"> 
<img src="images/pic.png" id="image style="width:208px; height:75px; margin-left:42%;" alt=""/>
</div>
dsgriffin
  • 66,495
  • 17
  • 137
  • 137
G . R
  • 543
  • 1
  • 6
  • 12
0
#Sample
{
background:url(your_image.jpg) no-repeat center center;
height:200px;
width:200px;
}

(Assumes a div with id="sample" as you are already specifying height and width adding a background shouldn't be an issue)

Akhil
  • 1,073
  • 1
  • 9
  • 28
-1

This is because you have a margin-left of 42% set to the image. Try this on the image style:

display:block;margin:0 auto;
randomizer
  • 1,619
  • 3
  • 15
  • 31