Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Dead centering objects of variable size??

Dead centering objects of variable size??
Thread Tools
Apfhex
Mac Elite
Join Date: Dec 2000
Location: Northern California
Status: Offline
Reply With Quote
May 20, 2006, 08:55 PM
 
What I want to do is, for the "full view" of a paining gallery site, have the image set in the dead center of the page. I've followed the instructions at http://www.wpdfd.com/editorial/thebox/deadcentre4.html to get a fixed width/hight object to stay in the center of the page, however, I have over 50 images to do this with and I'm not going to get the pixel dimensions of each one and create a separate CSS entry for them all.

Given that each image is going to be a different size, is there a way to accomplish this? I thought about placing the image inside a div and centering the div, but I'm having troubles with that.
Mac OS X 10.5.0, Mac Pro 2.66GHz/2 GB RAM/X1900 XT, 23" ACD
esdesign
     
Obi Wan's Ghost
Baninated
Join Date: Apr 2005
Location: An asteroid remanent of Tatooine.
Status: Offline
Reply With Quote
May 21, 2006, 06:56 AM
 
     
registered_user
Dedicated MacNNer
Join Date: Nov 2001
Location: Are Eye
Status: Offline
Reply With Quote
May 21, 2006, 12:31 PM
 
Well that doesn't answer the question at all, now does it?

Yes, there is a way to do this. But it's not easy.

If you set html, body, and whatever container you are using to height: 100% then your container is the full height of the window. If you set the img within your container (it must be inline and not block) to vertical-align: middle, it will be centered within the container.

Or, you can use a table. It's not semantic as a table, but then, a one celled table can be considered to be always semantic depending on your point of view.

Alternatively, you can set your image to display none (keeping the image in the mark up to maintain semantics), and use the image as the background on the body positioned at 50% 50%
     
Apfhex  (op)
Mac Elite
Join Date: Dec 2000
Location: Northern California
Status: Offline
Reply With Quote
May 21, 2006, 02:11 PM
 
Thanks for the suggestions, I'll try them out later and see how it works out.
Mac OS X 10.5.0, Mac Pro 2.66GHz/2 GB RAM/X1900 XT, 23" ACD
esdesign
     
Apfhex  (op)
Mac Elite
Join Date: Dec 2000
Location: Northern California
Status: Offline
Reply With Quote
May 21, 2006, 08:50 PM
 
It sure it easy to center the image or anything else vertically, but neither of the first two methods you mention want to align anything horizontally. The image remains at the top of the page.

But the third method, setting it as the background, allowed it to be centered. And then I can include the image invisibly like you say. Seems to work.

Ultimately, I might go for a simpler solution (not trying to get the image centered), but this is good for now.
Mac OS X 10.5.0, Mac Pro 2.66GHz/2 GB RAM/X1900 XT, 23" ACD
esdesign
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 04:08 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,