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 > CSS centering elements question

CSS centering elements question
Thread Tools
Professional Poster
Join Date: Jan 2001
Location: Salt Lake City, UT USA
Status: Offline
Reply With Quote
Apr 1, 2006, 05:55 PM
 
I'm building a webpage for a client. They want the page essentially to be centered all the time, just a slice of the browser window will be the page. Like this: http://www.aspentitle.com/
No matter the width of the window, the table which contains the 'page' remains center. Those guys did it with a <table align="center" /> tag, which works just fine. I could use it, but I'd prefer to use valid html with CSS. According to W3, the align attribute is old school.

Is there an equivalent CSS solution?
Thanks
2008 iMac 3.06 Ghz, 2GB Memory, GeForce 8800, 500GB HD, SuperDrive
8gb iPhone on Tmobile
     
Grizzled Veteran
Join Date: Oct 2002
Status: Offline
Reply With Quote
Apr 1, 2006, 06:58 PM
 
Code:
table {text-align: center;}
BayBook (13" MacBook Pro, 2.4GHz Core 2 Duo, 4GB RAM, 1TB HD) // BayPhone (iPhone 4, 32GB, black)
     
Dedicated MacNNer
Join Date: Nov 2001
Location: Are Eye
Status: Offline
Reply With Quote
Apr 1, 2006, 07:16 PM
 
margin: auto;

use with xhtml doctype
     
Professional Poster
Join Date: Jan 2001
Location: Salt Lake City, UT USA
Status: Offline
Reply With Quote
Apr 1, 2006, 09:23 PM
 
Thanks, precisely what I needed.
2008 iMac 3.06 Ghz, 2GB Memory, GeForce 8800, 500GB HD, SuperDrive
8gb iPhone on Tmobile
     
Mac Elite
Join Date: Dec 2004
Status: Offline
Reply With Quote
Apr 2, 2006, 03:52 AM
 
Don't forget to test in IE If IE messes it up you also have to add

body {
text-align:center;
}

in addition to margin:auto to your css box elements
Anyone who denies climate changes naturally is a Climate Change Skeptic.
     
Professional Poster
Join Date: Jan 2001
Location: Salt Lake City, UT USA
Status: Offline
Reply With Quote
Apr 2, 2006, 06:13 AM
 
I don't want the text in the table to be centered though.
2008 iMac 3.06 Ghz, 2GB Memory, GeForce 8800, 500GB HD, SuperDrive
8gb iPhone on Tmobile
     
Dedicated MacNNer
Join Date: Nov 2001
Location: Are Eye
Status: Offline
Reply With Quote
Apr 2, 2006, 06:29 AM
 
table? huh? If you're going to use tables for layout, I take my post back.
     
Mac Elite
Join Date: Dec 2004
Status: Offline
Reply With Quote
Apr 2, 2006, 07:14 AM
 
Originally Posted by SirCastor
I don't want the text in the table to be centered though.
Using

body {
text-align:center;
}

won't center your text throughout your layout. Your layout ids will override it with their own margin:auto and text alignment properties. The above is just an IE hack not relevant to other browsers.
Anyone who denies climate changes naturally is a Climate Change Skeptic.
     
Professional Poster
Join Date: Jan 2001
Location: Salt Lake City, UT USA
Status: Offline
Reply With Quote
Apr 2, 2006, 02:32 PM
 
I'm not using tables, it was a temporary example to associate with the situation. I swear I am not using tables for layout.

And, for the sake of reiteration... I hate IE
(I know, we all do, and it was hardly necessary for me to state the obvious...)
2008 iMac 3.06 Ghz, 2GB Memory, GeForce 8800, 500GB HD, SuperDrive
8gb iPhone on Tmobile
     
Baninated
Join Date: Mar 2005
Location: An asteroid remanent of Tatooine.
Status: Offline
Reply With Quote
Apr 2, 2006, 03:34 PM
 
Agree with the mushroom jumper. Some hacks are necassary to make your 'CSS LAYOUT' work in IE Always cross browser check.
     
   
Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:35 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2