Go Back   SitePoint Forums > Forum Index > Design Your Site > Web Page Design
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Nov 11, 2009, 21:43   #1
Black Max
Lackey to Felines
 
Black Max's Avatar
 
Join Date: Apr 2007
Posts: 1,355
Centering an entire page

I've spent some time doing another freebie design for a nonprofit organization, this one a local animal rescue outfit with a truly awful site of their own. Here's the link to the demo. (Yes, their logo's ineffably cheesy, but their dogs can handle Photoshop with about the same skill as I have, so the logo stays unless someone wants to donate one. )

I looked at the site demo on a much larger display than I normally have access to, and was not pleased to see that it doesn't center, but lines up on the left. Of course it does, I didn't tell it to do otherwise.

My question is, what's an easy and (relatively) painless way to go back and center it? I'm familiar with the classic method from Dan Cederholm and others, but, perhaps because I'm not using a fixed layout, it doesn't work. Or I did something stoopid and it didn't work, always a possibility.

I know it's a duh! question with a simple answer, but hey, how do I learn if I don't ask the dumb questions?
Black Max is offline   Reply With Quote
Old Nov 11, 2009, 22:02   #2
pmw57
Unobtrusively zen
 
pmw57's Avatar
 
Join Date: Jan 2007
Location: Christchurch
Posts: 4,988
Setting the left/right body margin to auto should do the trick

css Code:
body {
    margin: 0 auto;
    ...
}
pmw57 is online now   Reply With Quote
Old Nov 11, 2009, 22:04   #3
Black Max
Lackey to Felines
 
Black Max's Avatar
 
Join Date: Apr 2007
Posts: 1,355
Paul, I thought that was too simple to actually work!

Edit: it works perfectly, of course. I was thinking less of Occam's Razor and more of Murphy's Law.
Black Max is offline   Reply With Quote
Old Nov 11, 2009, 22:31   #4
pmw57
Unobtrusively zen
 
pmw57's Avatar
 
Join Date: Jan 2007
Location: Christchurch
Posts: 4,988
It does seem though that the slugline is falling off to the side. This is because it's position is set as an absolute, which is in terms of the next higher up relatively positioned element.

As there is no parent element that is set to relative, the slugline is positioned according to the window itself.

You'll want to set the header to be the relative reference for positions within it. This doesn't affect the header itself, but it does mean that the slugline will be positioned relative to the header instead, properly as it should be.

css Code:
#header {
    position: relative;
    ...
}
pmw57 is online now   Reply With Quote
Old Nov 11, 2009, 23:21   #5
RyanReese
CSS Guru in Training
 
RyanReese's Avatar
 
Join Date: Oct 2008
Location: Whiteford, MD
Posts: 8,691
Hi, you should avoid auto margins on the body as IE7< have several bugs related to that.

You should instead make a wrapper div enclosing the entire page and give a width and auto margins to that instead .
RyanReese is offline   Reply With Quote
Old Nov 11, 2009, 23:47   #6
pmw57
Unobtrusively zen
 
pmw57's Avatar
 
Join Date: Jan 2007
Location: Christchurch
Posts: 4,988
Quote:
Originally Posted by RyanReese View Post
Hi, you should avoid auto margins on the body as IE7< have several bugs related to that.
He's right. You can use IETester to test multiple versions of IE at the same time, which really helps to spot potential issues.
http://my-debugbar.com/wiki/IETester/HomePage
pmw57 is online now   Reply With Quote
Old Nov 12, 2009, 02:58   #7
Erik J
SitePoint Mentor
 
Erik J's Avatar
 
Join Date: May 2007
Location: Countryside, Sweden
Posts: 2,976
Quote:
Originally Posted by Black Max View Post
...
My question is, what's an easy and (relatively) painless way to go back and center it? ...
Without any changes to the html; That would be to remove the float from the header, the colmask, the footer, and apply auto margins and widths on them (instead of on the body).
Code:
#header,
.colmask,
#footer {
	float: none;
	margin: 0 auto;
	min-width: 600px;
	max-width: 1200px;
}
Erik J is online now   Reply With Quote
Old Nov 12, 2009, 15:16   #8
Black Max
Lackey to Felines
 
Black Max's Avatar
 
Join Date: Apr 2007
Posts: 1,355
Quote:
Originally Posted by pmw57 View Post
It does seem though that the slugline is falling off to the side. This is because it's position is set as an absolute, which is in terms of the next higher up relatively positioned element. ... You'll want to set the header to be the relative reference for positions within it.
Paul, thanks for finding that and suggesting a fix. That was a blunt-force, quick-fix solution to a problem that I never went back and corrected.

Quote:
Originally Posted by Erik J View Post
Without any changes to the html; That would be to remove the float from the header, the colmask, the footer, and apply auto margins and widths on them (instead of on the body).
Erik, that's an excellent fix that I will implement. I have created about twelve pages of the site and didn't want to go back and adjust a boatload of HTML if I don't need to.

Ryan, thanks for your suggestion. I'm assuming that Erik's solution won't cause hiccups in IE6 and 7...?
Black Max is offline   Reply With Quote
Old Nov 12, 2009, 15:44   #9
pmw57
Unobtrusively zen
 
pmw57's Avatar
 
Join Date: Jan 2007
Location: Christchurch
Posts: 4,988
Quote:
Originally Posted by Black Max View Post
Ryan, thanks for your suggestion. I'm assuming that Erik's solution won't cause hiccups in IE6 and 7...?
Try them out with IETester and check to see how they look.
pmw57 is online now   Reply With Quote
Old Nov 12, 2009, 15:57   #10
Black Max
Lackey to Felines
 
Black Max's Avatar
 
Join Date: Apr 2007
Posts: 1,355
Can't install IETester because my Windows setup is old, creaky, and not quite kosher.

I'm running it through Browsershots now, and so far everything looks good.

Edit: There are minor issues with its display in IE6, but I just don't care.
Black Max is offline   Reply With Quote
Old Nov 12, 2009, 16:22   #11
RyanReese
CSS Guru in Training
 
RyanReese's Avatar
 
Join Date: Oct 2008
Location: Whiteford, MD
Posts: 8,691
It won't cause too many issues other then it not understanding min/max width ..
RyanReese is offline   Reply With Quote
Old Nov 12, 2009, 19:07   #12
Black Max
Lackey to Felines
 
Black Max's Avatar
 
Join Date: Apr 2007
Posts: 1,355
Quote:
Originally Posted by RyanReese View Post
It won't cause too many issues other then it not understanding min/max width ..
This will handle that, right...?

CSS Code:
* html #whatever {
   width: expression( document.body.clientWidth > 1199 ? "1200px" : "auto" );
}
Black Max is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting 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
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 03:59.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved