Jump to content

How to align an image to the center?


Norman

Recommended Posts

It doesn't work. Here my code (not the entire code):

<!-- Start Personal Navigator Content Code --><table border="1" align="right" height="100px" width="100px" background="newvbstyle/misc/avatarhomebg.gif"><tr>   <td>  <img src="http://localhost/vbstyles/images/icons/icon1.gif" alt="Avatar" style="margin: 0 auto; text-align:center;" />   </td></tr>   </table><p style="font-size:10px; font-weight: bold;">Hi, {$bbuserinfo['username']}! This is your Personal $vboptions[bbtitle]'s Navigator!</p><!-- / End Personal Navigator Content Code -->

Link to comment
Share on other sites

CSS :
img {margin: 0 auto;text-align:center // for older browsers}

or in-line:

style="margin: 0 auto; text-align:center;"

img is inline by default, inline elements are centered via text align.for the purpose you're most likely using it,img{display:block;margin:0 auto;} should do it. depending on your doctype, add "text-align:center;"
Link to comment
Share on other sites

  • 6 months later...

Excuse me guys if I bump this thread, but I have the same problem. I want to align to the center an image, but if I put this code, it still remain on the left of the page. What's wrong?

<img src="images/skullheader.gif" style="text-align:center; margin: 0 auto;" border="0" align="middle" width="638" height="104" alt="Skullheader"  />

Link to comment
Share on other sites

Excuse me guys if I bump this thread, but I have the same problem. I want to align to the center an image, but if I put this code, it still remain on the left of the page. What's wrong?
<img src="images/skullheader.gif" style="text-align:center; margin: 0 auto;" border="0" align="middle" width="638" height="104" alt="Skullheader"  />

Here are some things I see potentially wrong.You're aligning text in an image tag. That won't fly.What's your doctype? I would just use relative positioning with a parent wrapper and the same margin:0 auto.
Link to comment
Share on other sites

Well, make the parent of the table have text-align:center; ...

<div style="text-align:center; "><table><!-- Table cells here --></table></div>

Link to comment
Share on other sites

Man, it doesn't work. And this put me crazy. Check my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><!-- Skullhead --><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><link href="style.css" rel="stylesheet" type="text/css"  /><title>Skullmonkeys</title></head><!-- / Skullhead --><body><div style="text-align: right;"><table border="0"><tr>  <td><img src="images/skullheader.gif" border="0" width="638" height="104" alt="Skullheader" /></td></tr></table></div><!-- / Skullmonkeys Official Web Site --></body></html>

Link to comment
Share on other sites

Ops, my mistake. I have changed it and I have forgot to set it again to the center. However, it still doesn't work. I have a flash menu in my page. Could be that create this error?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...