Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > HTML, XHTML and CSS

Reply
 
LinkBack Thread Tools
Old August 31st, 2007, 07:28 PM   #1
WebForumz Member
 

Join Date: Jan 2007
Location: England
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Gerry will become famous soon enough
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:
 
<body>
<div class="container" id="container">
 
whole page content here
 
</div>
</body>
then, with css, styled the container as follows

Code:
 
.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)
__________________
maintain quality

Last edited by Gerry; August 31st, 2007 at 07:33 PM.. Reason: last sentence added
Gerry is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 31st, 2007, 08:19 PM   #2
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
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
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 31st, 2007, 08:50 PM   #3
Most Reputable Member
 

Join Date: May 2006
Location: North West, UK
Age: 23
Posts: 1,170
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 pa007 has a spectacular aura about pa007 has a spectacular aura about
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.
pa007 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 1st, 2007, 09:14 AM   #4
WebForumz Member
 

Join Date: Jun 2007
Location: Birmingham, UK
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Rep Altering Power: 0 hschmitz is on a distinguished road
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:
 
body {
  text-align: center;
}

.container {
 position: relative;
 margin: 0 auto;
 padding: 0px;
}
hschmitz is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 4th, 2007, 07:17 AM   #5
New Member
 

Join Date: Aug 2007
Location: UK
Age: 26
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Hardbyte is on a distinguished road
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
Hardbyte is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 4th, 2007, 11:25 AM   #6
Elite Veteran
 

Join Date: Aug 2005
Location: That Place
Posts: 2,081
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Rep Altering Power: 0 moojoo will become famous soon enough moojoo will become famous soon enough
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:
body {
text-align:center;
}

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

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


Last edited by moojoo; September 4th, 2007 at 11:28 AM..
moojoo is offline  
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

Bookmarks

Tags
page , layers , centre , center


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 HTML, XHTML and CSS 2 April 10th, 2008 11:14 AM
How to create a centered page with layers. sgbrix HTML, XHTML and CSS 7 March 11th, 2008 12:36 PM
Layers that go the entire Height of the page. briandina HTML, XHTML and CSS 0 December 31st, 2006 05:01 PM
Need help with layers davidsnave HTML, XHTML and CSS 0 August 29th, 2005 07:26 PM
Centering layers in a page gwx03 HTML, XHTML and CSS 9 November 26th, 2003 03:55 PM


Search Engine Optimization by vBSEO 3.2.0 RC8