View Full Version : Centering an image
Frog Brew
02-25-2007, 08:03 PM
Is there a way to have am Image always centered (using different resolutions) using CSS if so do I use relative or static or another ?
auntnini
02-25-2007, 08:23 PM
May I refer you to http://www.w3.org/Style/Examples/007/center.html#block.
The way I understand it, apply AUTO left/right margins (margin-left: auto; margin-right; or margin: 0 auto;). Then. because IE doesn't support AUTO margins, add text-align: center; (usually in body specs, and then apply text-align: left; for content div).
Frankly, I wish they would reinstate good old, no-nonsense CENTER.
mburt
02-25-2007, 08:29 PM
<div style="text-align:center;">
<img src="myimage.jpg" alt="text">
</div>
Frog Brew
02-25-2007, 08:47 PM
Thanks ...that worked well
Frankly, I wish they would reinstate good old, no-nonsense CENTER.We don't -- that there scurvy dog be bulk presentational markup :)
The way I understand it, apply AUTO left/right margins (margin-left: auto; margin-right; or margin: 0 auto. Then. because IE doesn't support AUTO margins, add text-align: center; (usually in body specs, and then apply text-align: left; for content div).It's not as simple as that. One centres a block-level element by making sure its left and right margins are equal and of the correct width to hold the element in the centre (which is what the margin:auto stuff is all about). However, images are inline elements, and so should be centred with text-align:center. Then IE comes along and treats certain elements (specifically, tables) as if they were inline, even though they're actually block-level, so we have to centre those with text-align as well.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.