Previous Message
Next Message

Centering a div with an image

Sent by Gunlaug_Sørtun on 20 December 2007 23:11


Jan Erik Moström wrote:

> So my question is: Is it possible to center the photobackground 
> without knowing the size of the image? If so, can anyone please 
> give me an hint on how to do it?

Centering an element is easy enough, but the actual solution depends on 
whether you want to center only the image or the entire div.

Block-elements - preferably non-positioned (no 'position: absolute;' 
used) - can be horizontally centered by declaring 'margin: 0 auto;' on 
the element itself.

Inline-elements - that's what an image is by default - can be centered 
by declaring 'text-align: center;' on the container for that image. 
That's then often followed by declaring 'text-align: left;' on any 
text-carrying elements inside the same container, so only the image gets 
centered.


If you want an exact solution for your case, then you must provide a 
link to a live example. We need to see what other styles and conditions 
it's subjected to.

As an example of how you can manipulate positioning/centering of images, 
the following may be of some use...
<http://www.gunlaug.no/contents/wd_chaos_19.html>

regards
	Georg
-- 
http://www.gunlaug.no
______________________________________________________________________
css-discuss [EMAIL-REMOVED]]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
List policies -- http://css-discuss.org/policies.html
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/
Previous Message
Next Message

Message thread: