How to center a page without use of a table

This is a discussion on "How to center a page without use of a table" within the Web Page Design section. This forum, and the thread "How to center a page without use of a table are both part of the Design Your Website category.



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

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 21st, 2007, 07:04
pdk pdk is offline
New Member
Join Date: Jan 2007
Location: ontairo
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
How to center a page without use of a table

hi, I'm sort of an off-and-on designer who does small pages mainly for friends and family, but I'm sort of learning CSS. I've got something started at

http://pdk.lolmaha.com/design

but I can't for the life of me figure out how to center it without the use of a table OR a container div as I've done in this.

if someone could tell me what i'm doing, it would be greatly appreciated
Reply With Quote

  #2 (permalink)  
Old Jan 21st, 2007, 12:15
SuperMember

SuperMember
Join Date: Sep 2006
Location: Pink House
Posts: 3,946
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to center a page without use of a table

Links not working so can't see your code!
Reply With Quote
  #3 (permalink)  
Old Jan 21st, 2007, 14:05
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: How to center a page without use of a table

Your combination of css styling code and the use of a container div is just fine.

Get into the habit of placing your css in a seperate file and <link... it into your pages.
Reply With Quote
  #4 (permalink)  
Old Jan 21st, 2007, 19:03
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to center a page without use of a table

Something has to be fixed width, but you can add margin: 0 auto; to an element.
Reply With Quote
  #5 (permalink)  
Old Jan 22nd, 2007, 13:18
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to center a page without use of a table

How to center your site horizontally

Last edited by karinne; Jan 22nd, 2007 at 13:32.
Reply With Quote
  #6 (permalink)  
Old Jan 22nd, 2007, 15:18
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,761
Blog Entries: 1
Thanks: 0
Thanked 18 Times in 18 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: How to center a page without use of a table

also text-align:center; the body and text-align:left; your container. IE7 doesn't seem to like margin:0 auto;
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Reply With Quote
  #7 (permalink)  
Old Jan 22nd, 2007, 17:05
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to center a page without use of a table

Quote:
Originally Posted by moojoo View Post
also text-align:center; the body and text-align:left; your container. IE7 doesn't seem to like margin:0 auto;
Hmm ... that's news to me ... I'm pretty sure only IE5 and IE5.5 possibly are the only ones that need the text-align:center; ... if you look at my portfolio site in IE7, it centers correctly and I don't have the text-align:center; anywhere in there.
Reply With Quote
  #8 (permalink)  
Old Jan 22nd, 2007, 18:03
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to center a page without use of a table

I heard that too, perhaps it was on one of the beta versions?
Reply With Quote
  #9 (permalink)  
Old Jan 22nd, 2007, 19:02
New Member
Join Date: Jul 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to center a page without use of a table

quick reply to you dude

use margin-left:auto;
and margin-right:auto to centre your divs
Reply With Quote
  #10 (permalink)  
Old Jan 22nd, 2007, 19:05
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,761
Blog Entries: 1
Thanks: 0
Thanked 18 Times in 18 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: How to center a page without use of a table

margin:0 auto is less code and works the same

Quote:
Originally Posted by barry View Post
quick reply to you dude

use margin-left:auto;
and margin-right:auto to centre your divs
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Reply With Quote
  #11 (permalink)  
Old Jan 22nd, 2007, 19:06
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,761
Blog Entries: 1
Thanks: 0
Thanked 18 Times in 18 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: How to center a page without use of a table

I test in IE 7 under Parallels and on IE 7 at work both XP Pro. Neither one supports it for me, perhaps I just need to update it. Will run sw update at home and see.

Quote:
Originally Posted by Ryan Fait View Post
I heard that too, perhaps it was on one of the beta versions?
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Reply With Quote
  #12 (permalink)  
Old Jan 22nd, 2007, 22:37
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to center a page without use of a table

Yep, that's good to know!
Reply With Quote
  #13 (permalink)  
Old Jan 23rd, 2007, 00:26
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to center a page without use of a table

The code I posted in my first reply, you'll notice I don't have the text-align: center in the body { }. Only margin: 0 auto; and a width in the #wrap.

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-CA" xml:lang="EN-CA">

<head>
    <title>Some title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    <style type="text/css">
    body {
        color: #fff;
    }
    
    #wrap {
        margin: 0 auto;
        width: 780px;
        background-color: #900;
    }
    </style>
</head>

<body>

<div id="wrap">
    this box is centered
</div>

</body>
</html>
This works in FF2, Opera 9 and IE6 and IE7.

You can test it here.
Reply With Quote
  #14 (permalink)  
Old Jan 23rd, 2007, 15:30
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,761
Blog Entries: 1
Thanks: 0
Thanked 18 Times in 18 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: How to center a page without use of a table

Yes centering only works with a width value specified. Good point =P.
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Reply With Quote
  #15 (permalink)  
Old Jan 30th, 2007, 20:56
pdk pdk is offline
New Member
Join Date: Jan 2007
Location: ontairo
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to center a page without use of a table

Okay, so I've solved that problem. How do I make column1 and column2 the same length no matter what?
Reply With Quote
  #16 (permalink)  
Old Jan 30th, 2007, 21:01
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to center a page without use of a table

Unforunately you can't.
Reply With Quote
  #17 (permalink)  
Old Jan 30th, 2007, 21:02
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,761
Blog Entries: 1
Thanks: 0
Thanked 18 Times in 18 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: How to center a page without use of a table

A bit of stuff I noticed:

Change this code:

Code: Select all

<P>HEADERHEADERHEADER
<P>HEADERHEADERHEADER
</div>            
<div id='column1'>
<li><a href='POKER'>OMAHA</a></li>
<li><a href='POKER'>STUD</a></li>
<li><a href='POKER'>LEE JONES</a></li>
<li><a href='POKER'>TEXAS FOLD THEM</a></li>
<li><a href='POKER'>POKER</a></li>
</div>
<div id='column2'>
this for news 
</div>
<div id='footer'>
this the footer
</div>
to:

Code: Select all

<h1>HEADERHEADERHEADER</h1>
<h1>HEADERHEADERHEADER</h1>
</div>            
<div id="column1">
<ul>
<li><a href="POKER">OMAHA</a></li>
<li><a href="POKER">STUD</a></li>
<li><a href="POKER">LEE JONES</a></li>
<li><a href="POKER">TEXAS FOLD THEM</a></li>
<li><a href="POKER">POKER</a></li>
</ul>
</div>
<!-- end column1 -->
<div id="column2">
<p>this for news</p>
</div>
<!-- end column2 -->
<div id="footer">
<p>this the footer</p>
</div>
<!-- end footer -->
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Reply With Quote
  #18 (permalink)  
Old Jan 30th, 2007, 21:06
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,761
Blog Entries: 1
Thanks: 0
Thanked 18 Times in 18 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: How to center a page without use of a table

Quote:
Originally Posted by Ryan Fait View Post
Unforunately you can't.
Well you can in ways..

1. Simulate the columns by using a background image repeating on the y axis of your container so a border whatever appears the entire height of the containing div or even on the body. Called "Faux Columns".

2. Specify them both the same height and use the over flow auto property

3. Give both the same amount of content

4. (This one is not recommended) use javascript to control them.
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Reply With Quote
  #19 (permalink)  
Old Jan 30th, 2007, 21:25
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to center a page without use of a table

Yes indeed. It's more of a trick, though, as the <div> won't actually extend to the bottom. As moojoo pointed out, "Faux Columns" are the best way to do this. A quick Google search will yield several results to help you out.
Reply With Quote
  #20 (permalink)  
Old Jan 30th, 2007, 22:06
pdk pdk is offline
New Member
Join Date: Jan 2007
Location: ontairo
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to center a page without use of a table

Okay, I'm not sure I "get" faux columns.

I tried messing around with a bunch of stuff, check it out.
Reply With Quote
Reply

Tags
center, css

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
Vertical alignment issues in IE6. IE7 Won't center my page! Itsumishi Web Page Design 5 Mar 24th, 2008 20:28
[SOLVED] background img center in table robertl Web Page Design 9 Oct 1st, 2007 05:27
IE pushing table down the page PeterBailey2 Web Page Design 14 May 3rd, 2007 13:57
center page in high res Colin Green Introduce Yourself 5 May 6th, 2006 15:44
Center slice table vertically Legacy_Staff Web Page Design 9 May 5th, 2006 18:48


All times are GMT. The time now is 07:59.


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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43