centered css site in all screen resolutions

This is a discussion on "centered css site in all screen resolutions" within the Web Page Design section. This forum, and the thread "centered css site in all screen resolutions 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 Feb 19th, 2008, 11:16
Junior Member
Join Date: Sep 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
centered css site in all screen resolutions

Hi, i have recently built a site using html and css.
When i view the site on a screen resolution of 1024px and above it looks fine and the site is centered on the screen.

Whoever, when i view the site in 800px by 600px screen res the site moves to the right and you have to scroll over the the right and down to view the page.

I have used absolute positioning for all elements of the site images, navigation etc.

Is there a way to allow my site to be centered in every screen resolution.

I have tried using a container but it didnt work. does my positioning of all the site elements need to be changed in the style sheet to accomodate the container.

Thanks
Forry
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 Feb 19th, 2008, 11:30
Aso's Avatar
Aso Aso is offline
Moderator

SuperMember
Join Date: Oct 2007
Location: UK
Posts: 1,339
Blog Entries: 2
Thanks: 11
Thanked 49 Times in 46 Posts
Re: centered css site in all screen resolutions

Is your site wider than 800px? If so, all browsers whose window is smaller than the site in question, will render it to the left with the ability to scroll right.
Last Blog Entry: The Google Misconception (Feb 3rd, 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 Feb 19th, 2008, 11:42
Junior Member
Join Date: Sep 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Re: centered css site in all screen resolutions

No the site is 800px by 600px.
When its viewed in an 800 by 600 screen res it moves the whole site to the right. its not centered

Thanks
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 Feb 19th, 2008, 11:45
Aso's Avatar
Aso Aso is offline
Moderator

SuperMember
Join Date: Oct 2007
Location: UK
Posts: 1,339
Blog Entries: 2
Thanks: 11
Thanked 49 Times in 46 Posts
Re: centered css site in all screen resolutions

Is it possible for you to host the site / send a link? Or if not, post your HTML and CSS.
Last Blog Entry: The Google Misconception (Feb 3rd, 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
  #5  
Old Feb 19th, 2008, 11:48
Junior Member
Join Date: Sep 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Re: centered css site in all screen resolutions

ye sure the link is http://www.3dgardendesign.co.uk/

I have just tried it in all res below my screen res of 1280 by 1024.

It looks to me like the site is positioned to absolute position i entered in the css code.

It looks like it doesnt move form its position in 1280 on other screen res
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 Feb 19th, 2008, 11:55
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: centered css site in all screen resolutions

Drop the absolute positioning, and use the CSS margin: 0 auto; on your main container.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Feb 19th, 2008, 13:43
Junior Member
Join Date: Sep 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Re: centered css site in all screen resolutions

Hi, i tried that but still doesnt work.

I dont know if i am doing soemthing wrong in the rest of my css to make the container not work properly

This is my style in the css for the container

#container {
background-color: #232222;
padding: 0;
margin:0 auto;
position: relative;
width: 100%;
height:: 100%;
text-align: center;
}

In the html i have palced the div at beginning of the body and closed the div at end of the body
<body>
<div id="container">

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Feb 19th, 2008, 13:50
Jack Franklin's Avatar
Moderator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,402
Blog Entries: 8
Thanks: 18
Thanked 14 Times in 14 Posts
Re: centered css site in all screen resolutions

Drop the position: relative?
__________________
Jack Franklin - Webforumz Moderator
(x)HTML | CSS | PHP | MySQL | JQuery (Javascript)
Contact: My Blog | Twitter | Delicious
Want Lessons? PM me.
If you think I've helped, please press the 'Thanks' Button.
Last Blog Entry: A Week with VBulletin (Aug 28th, 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
  #9  
Old Feb 19th, 2008, 15:03
Junior Member
Join Date: Sep 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Re: centered css site in all screen resolutions

I tried dropping the position relative. still no joy.
I have been told to add a table and contain everything inside the table.
I dont really want to go down that road of using tables

does anyone have any links on how to design a website that is positioned centered in every screen resolution.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Feb 19th, 2008, 15:05
Jack Franklin's Avatar
Moderator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,402
Blog Entries: 8
Thanks: 18
Thanked 14 Times in 14 Posts
Re: centered css site in all screen resolutions

NO TABLES!

Just try dropping the text-align center bit.
__________________
Jack Franklin - Webforumz Moderator
(x)HTML | CSS | PHP | MySQL | JQuery (Javascript)
Contact: My Blog | Twitter | Delicious
Want Lessons? PM me.
If you think I've helped, please press the 'Thanks' Button.
Last Blog Entry: A Week with VBulletin (Aug 28th, 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
  #11  
Old Feb 19th, 2008, 15:19
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: centered css site in all screen resolutions

The auto margins method does work. But you need to understand what you're doing. You can't just apply it to any random box and expect it to work.
  • The things you want to centre must be inside the container <div>
  • You must specify a width for the container
  • Your must use a valid doctype
  • If you're using IE, you must be on IE6 or newer (doesn't work in IE5)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Feb 19th, 2008, 15:21
Reputable Member
Join Date: Oct 2007
Location: UK
Posts: 266
Thanks: 0
Thanked 0 Times in 0 Posts
Re: centered css site in all screen resolutions

Do u not have to define the width of a div in pxels for margin: 0 auto; to work?

Try changing width: 100%; to width: 800px;

Also, your css u have 2 ':' ----> height:: 100%;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Feb 19th, 2008, 17:09
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: centered css site in all screen resolutions

You can define the width in any unit (but 100% is obviously useless for centring!).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Feb 19th, 2008, 17:45
Jack Franklin's Avatar
Moderator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,402
Blog Entries: 8
Thanks: 18
Thanked 14 Times in 14 Posts
Re: centered css site in all screen resolutions

Yes I was about to say that, if it's width is 100% in essence it is always centered. But you say you have a large margin to the left?
Quote:
when i view the site in 800px by 600px screen res the site moves to the right and you have to scroll over the the right and down to view the page.
Can I see your entire CSS please? Plus the HTML?

Thanks!
__________________
Jack Franklin - Webforumz Moderator
(x)HTML | CSS | PHP | MySQL | JQuery (Javascript)
Contact: My Blog | Twitter | Delicious
Want Lessons? PM me.
If you think I've helped, please press the 'Thanks' Button.
Last Blog Entry: A Week with VBulletin (Aug 28th, 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
  #15  
Old Feb 20th, 2008, 01:31
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: centered css site in all screen resolutions

Don't set your content area a fixed width, make their width in percentage value instead
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old Feb 20th, 2008, 07:38
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: centered css site in all screen resolutions

Quote:
Originally Posted by Monie View Post
Don't set your content area a fixed width, make their width in percentage value instead
Even better, use ems.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #17  
Old Feb 20th, 2008, 07:52
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: centered css site in all screen resolutions

I usually do use em for my font size, but I never used them to specify any of my div elements
What's the advantage of using them Mike?
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #18  
Old Feb 20th, 2008, 08:02
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: centered css site in all screen resolutions

Quote:
Originally Posted by Monie View Post
I usually do use em for my font size, but I never used them to specify any of my div elements
What's the advantage of using them Mike?
The advantage of ems is that you can create layouts that fit any font size. So when users resize the font, everything remains in proportion.

This function is also provided by browser zoom features, but they zoom everything. The most common reason to want zoom is for reading text more easily, not for blowing up images. Font resizing provides a more efficient use of space than whole-page zoom (plus it's faster and doesn't look as ugly).

You don't often see these kinds of layouts, but I really like them. Go to my site, the Badminton Bible, and resize the text. Note how the layout adapts.

You can of course use a combination of layout units. I use mostly ems, then px (for image-related layout), and occasionally %.

Last edited by MikeHopley; Feb 20th, 2008 at 08:06.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!