centreing a whole page with layers

This is a discussion on "centreing a whole page with layers" within the Web Page Design section. This forum, and the thread "centreing a whole page with layers are both part of the Design Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Aug 31st, 2007, 23:28
Up'n'Coming Member
Join Date: Jan 2007
Location: England
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Smile centreing a whole page with layers

Hi gang,
I know I should know this, but this late at night it's got me on a go slow.
I've built a page in dreamweaver with layers (divs) and now I want the whole page to centre in the browser, but it wont do it.

I have hand coded another div in the code

Code: Select all
 
<body>
<div class="container" id="container">
 
whole page content here
 
</div>
</body>
then, with css, styled the container as follows

Code: Select all
 
.container {
 text-align: center;
 margin: 0 auto;
 padding: 0px;
}
I have layers/divs within the main body that have absolute positions, but didn't think that would be a problem as they are all within the container....could it be they are positioning themselves absolutely to the top and left even though the containing div is centred as a whole?

any suggestion would be very welcomed
much appreciated

(I'd rather not turn it into tables and cells, and it needs to work as a template with regions added to numerous pages, as it will be edited via contribute eventually)

Last edited by Gerry; Aug 31st, 2007 at 23:33. Reason: last sentence added
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Sep 1st, 2007, 00:19
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: centreing a whole page with layers

this is css not html
why do you have a class and id defined for container
you only need one
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Sep 1st, 2007, 00:50
Most Reputable Member
Join Date: May 2006
Location: North West, UK
Age: 22
Posts: 1,173
Thanks: 0
Thanked 0 Times in 0 Posts
Re: centreing a whole page with layers

I don't think this will work if it's absolutely positioned. Absolute positioning (like all other positioning) takes the elements it is applied to out of the flow of the document. The thing is with absolute positioning is that it is just that, absolute. It won't move anywhere, that's the point.

Pete.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Sep 1st, 2007, 13:14
Up'n'Coming Member
Join Date: Jun 2007
Location: Birmingham, UK
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Re: centreing a whole page with layers

To make the layer centred on the page you need to put the text-align: center in the CSS of the body.

Quote:
Originally Posted by Gerry View Post
I have layers/divs within the main body that have absolute positions, but didn't think that would be a problem as they are all within the container....could it be they are positioning themselves absolutely to the top and left even though the containing div is centred as a whole?
If you want those layers to be absolute but relative to the container, you need to specify position:relative in the container. So the whole thing should look like this

Code: Select all
 
body {
  text-align: center;
}

.container {
 position: relative;
 margin: 0 auto;
 padding: 0px;
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Sep 4th, 2007, 11:17
Junior Member
Join Date: Aug 2007
Location: UK
Age: 25
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: centreing a whole page with layers

Dont need to text align anything centered!

You would need 2 wrappers. One being width:100%; and the other inside this being the width of the site and margin 0 auto (width:600px; margin:0 auto
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Sep 4th, 2007, 15:25
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: centreing a whole page with layers

You can't center an object if it has no width. Add a width and margin:0 auto; will work. And you certainly don't need to contain the div in another 100% wrapper. All you need is the container and then put everything in that.

The only reason you would need text-align:center; on the body is for IE 5.x as it won't read margin:0 auto;

IE 5.x compatible.

Code: Select all
body {
text-align:center;
}

.container {
text-align:left;
width:770px;
margin:0 auto;
}
Correcting your existing code.

Code: Select all
.container {width:770px;text-align: center;margin: 0 auto;padding: 0px;}
__________________

Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)

Last edited by moojoo; Sep 4th, 2007 at 15:28.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
page, layers, centre, center

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Real problem centreing images in Firefox/Safari... JamesHatter Web Page Design 2 Apr 10th, 2008 15:14
How to create a centered page with layers. sgbrix Web Page Design 7 Mar 11th, 2008 15:36
Layers that go the entire Height of the page. briandina Web Page Design 0 Dec 31st, 2006 21:01
Need help with layers davidsnave Web Page Design 0 Aug 29th, 2005 23:26
Centering layers in a page gwx03 Web Page Design 9 Nov 26th, 2003 19:55


All times are GMT. The time now is 21:34.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved