-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,367
  • 23
  • 82
  • 138

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
  • 35,662
  • 8
  • 61
  • 98
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
  • 64,660
  • 17
  • 133
  • 135
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,083
  • 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,599
  • 3
  • 14
  • 31