Jump to content

Align Image In Center Of Brwoser Window


waynemac
 Share

Recommended Posts

Gidday all, Im wanting to align an image in the center (vertical and horizontal) of the user's browser window.

 

How would I go about this? Using XHTML.

 

Regards, Wayne :)

Link to comment
Share on other sites

I would use CSS rather than XHTML. To align an image in the middle of the browser window, I always use the following.

><img src="location/of/your/image.gif" alt="Some image text" style="margin: 0 auto;" />

 

This should center the image nicely. Description of margin is a shorthand rule that says, "make the top and bottom margin of the image 0 pixels tall, and automatically determine the left and right margins." When the auto determination is made, the margins will be set to the same width using the formula:

 

width (of left or right margin) = (browser_width - image_width)/2

 

(If my algebra skills are still up to par.)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...