Previous Message
Next Message

Centering a div with an image

Sent by Jan_Erik_Moström on 20 December 2007 22:10


OK, this is probably really, really simple but I can't for the 
life of me figure out how to do it, my only excuse is that I'm 
no CSS expert.

The effect I'm trying to achieve is a photo page. It should have 
a dark background color, a "photo background" in a lighter color 
with the image and caption text.

What I've done is this:

<div id="singlephoto">
     <div id="photobackground">
         <img 
src="foto5/2007/2007-05-10_fritids/2007-05-10_09-46-46_549.jpg" 
alt="" width="800" height="535" />
         <h1>Någon rubrik</h1>
         <p>
             Här kommer nu själva beskrivningen
         </p>
     </div>
</div>

My problem is how I center the photobackground div, I've played 
with various way of doing it but I can only figure out how to do 
it if I know the width of the of the photo (this is going to be 
used in a gallery generating program over which I have no control):

singlephoto
{
     position: absolute;
     left: 50%;
     margin-left: -410px;
}

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?

                         jem
-- 
Jan Erik Moström, www.mostrom.pp.se

______________________________________________________________________
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: