center the page? help

Reply

Join Date: Nov 2008
Posts: 74
Reputation: sacarias40 is an unknown quantity at this point 
Solved Threads: 0
sacarias40's Avatar
sacarias40 sacarias40 is offline Offline
Junior Poster in Training

center the page? help

 
0
  #1
Dec 28th, 2008
i have a webpage that i built on my computer. a 1024x768 reslolution screen is what i used. but when i use a bigger monitor, the page is the same size, but its pushed up against the left side of the monitor.
could somebody tell me the way to always keep it in the center nomatter what size screen is being used to view the page?

thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 76
Reputation: ccube921 is an unknown quantity at this point 
Solved Threads: 6
ccube921 ccube921 is offline Offline
Junior Poster in Training

Re: center the page? help

 
0
  #2
Dec 28th, 2008
Using css, this code would do it:

position:absolute;
left:50%;
margin:The number here should be negative half your pages width;
Meaning if your page were 200px wide, the code would be:
margin:-100px;
If I have been helpful add to my reputation!
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 63
Reputation: cfajohnson is an unknown quantity at this point 
Solved Threads: 13
cfajohnson cfajohnson is offline Offline
Junior Poster in Training

Re: center the page? help

 
0
  #3
Dec 28th, 2008
Originally Posted by sacarias40 View Post
i have a webpage that i built on my computer. a 1024x768 reslolution screen is what i used. but when i use a bigger monitor, the page is the same size, but its pushed up against the left side of the monitor.

Why don't you just let the page fill the browser window no matter what size it is? That's what a browser does by default. If your page doesn't do that, you have done something to prevent it, like giving a fixed width for your content.

If you always want to have a margin on your page, give the body (or main div) a width and margin: auto:

  1. body
  2. {
  3. width: 80%;
  4. margin: auto;
  5. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 276
Reputation: kanaku is on a distinguished road 
Solved Threads: 15
kanaku's Avatar
kanaku kanaku is offline Offline
Posting Whiz in Training

Re: center the page? help

 
0
  #4
Dec 29th, 2008
The most popular way of centering your content is to put your whole body in one div with and id (ie container) and add this in your css code:
HTML and CSS Syntax (Toggle Plain Text)
  1. div#container
  2. {
  3. margin: 0 auto;
  4. width: (the width you want, could be in %, px, or em)
  5. }

The margin attribute can have 2, 3, or 4 values. If it contains just 2 values (like in the example above), the first value is for the top and bottom margins and the second value is for the left and right margins.

When you specify 'auto' whatever space is not used by your width gets divided into two. So if your layout is 800px and the screen width is 1000px, the 'auto' value makes a 100px margin on the left and right side.


FOR CURIOSITY'S SAKE...
Just for reference, the html's body looks like this:
HTML and CSS Syntax (Toggle Plain Text)
  1. <body>
  2. <div id="container">
  3.  
  4. ... all the content stuff here...
  5.  
  6. </div>
  7. </body>

When you use 4 values in your margin attribute, they are specified in the following order: top, right, bottom, left (clockwise from the top). I can't remember what's the 3-value for. hehe
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: center the page? help

 
0
  #5
Dec 29th, 2008
Hope this will help u up!

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta http-equiv="Content-Style-Type" content="text/css" />
  7. <title>Centering The Page</title>
  8. <style type="text/css" media="all">
  9. /* <![CDATA[ */
  10. @media screen {
  11. html, body {
  12. height: 100%;
  13. min-width: 800px;
  14. max-width: 1024px;
  15. width: 100%;
  16. }
  17.  
  18. body {
  19. background-color: #eee;
  20. color: #000;
  21. text-align: center;
  22. }
  23.  
  24. body #wrapper {
  25. background-color: #fff;
  26. border: 0;
  27. color: inherit;
  28. height: 100%;
  29. margin: 0 auto;
  30. max-width: 1000px;
  31. text-align: left;
  32. width: 100%;
  33. }
  34. }
  35. /* ]]> */
  36. </style>
  37. </head>
  38. <body>
  39. <div id="wrapper">
  40. </div>
  41. </body>
  42. </html>
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,193
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 162
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Sensei

Re: center the page? help

 
0
  #6
Dec 29th, 2008
Use the method in poist #4 for horizontal centering.

Negative values in styles are not standard, and don't always work.

There is no reliable way to center content vertically on a page that works on all browsers, screen resolutions, and window sizes. Stop trying to do that. Just put a top margin on the content, and let the bottom fall where it will.

Never use pixel sizes to define anything. Use points for text, and percent for object sizes.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 74
Reputation: sacarias40 is an unknown quantity at this point 
Solved Threads: 0
sacarias40's Avatar
sacarias40 sacarias40 is offline Offline
Junior Poster in Training

Re: center the page? help

 
0
  #7
Dec 30th, 2008
thank you guys for your help i believe i will try the 4th post because it looks most easy and practical.
once more thank you again.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 74
Reputation: sacarias40 is an unknown quantity at this point 
Solved Threads: 0
sacarias40's Avatar
sacarias40 sacarias40 is offline Offline
Junior Poster in Training

Re: center the page? help

 
0
  #8
Dec 30th, 2008
ahhggg i cant get it to work.
here is the link
www.livingandlegacy.com
if that could help me by posting it...
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 74
Reputation: sacarias40 is an unknown quantity at this point 
Solved Threads: 0
sacarias40's Avatar
sacarias40 sacarias40 is offline Offline
Junior Poster in Training

Re: center the page? help

 
0
  #9
Dec 30th, 2008
and help with positioning the google search bar would help too.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 73
Reputation: lio04 is an unknown quantity at this point 
Solved Threads: 4
lio04's Avatar
lio04 lio04 is offline Offline
Junior Poster in Training

Re: center the page? help

 
0
  #10
Dec 30th, 2008
Change your wrapper div on the page to <div id="wrapper"> and in the CSS file set fixed width and margin, which will have value 0 auto.

Try this:

  1. #wrapper {
  2. width: 1000px;
  3. height: auto;
  4. margin: 0 auto;
  5. }

Edit: I don't know, whether it will work, because on page is relative and absolute positioning for main parts of design.
Last edited by lio04; Dec 30th, 2008 at 1:48 pm.
Jabber: lio(at)jabbim(dot)sk
Sorry for my English, I am only an autodidact.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the HTML and CSS Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC