Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 438
  • Last Modified:

how to center an image

Hi
I want to center an image . Here is part of my code :

<body>
test
<div><img src="image.jpg"  align="center"> </div>
</div>

It is always on the left. I want the image in the center of my html page.

Thanks for your help
0
workflow80
Asked:
workflow80
2 Solutions
 
Tom BeckCommented:
You could try this, but it may affect other elements on the page.

<body style="margin:0 auto;padding:0;">
test
<div><img src="image.jpg"  align="center"> </div>
</div>
0
 
Greg AlexanderLead DeveloperCommented:
try this

<div style="width: 50%; margin: auto;"><img src="image.jpg"></div>

Open in new window

0
 
jrwarrenCommented:
Maybe for kicks and giggles....
   Add :
align to the div:
<body style="margin:0 auto;padding:0;">
test
<div align="center"><img src="image.jpg"  align="center"> </div>
</div>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Paul SauvéRetiredCommented:
<body>
test
<div><img src="image.jpg"  align="center"> </div>
</div>


Have you tried getting rid of the final </div>?
0
 
jrwarrenCommented:
@paulsuave :
   I just tested yoru suggestion.. getting rid of the extra div does nothing in ie9 or FF4..
  Interested to know if it affects ie7/8 or FF3, can you feed back on that?
Excellent catch on the redundant /div, though!

  I still think you should simply add align="center" in the div tag... solves a lot with little fuss.
0
 
jrwarrenCommented:
oh and btw - I built a head and closed the body and head in my test, just to make sure it was reading it proper.  Just FYI.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now