+ Reply to Thread
Results 1 to 5 of 5

Thread: Centering my website...

  1. #1
    vrufusx65v's Avatar
    vrufusx65v is offline x10Hosting Member vrufusx65v is an unknown quantity at this point
    Join Date
    Aug 2009
    Location
    Dublin, Ireland
    Posts
    74

    Question Centering my website...

    i have a website whose width is 1280px wide and trying to look at it from a 1024x768 res PC i was wondering if i was able to (upon loading the website) center itself, or even better just get rid of the bottom scroll bar...

    here's the code i have for the container the website is all in:

    Code:
    .container {
    	margin: 0 auto;
    	position:static;
    	width:1280px;
    	height:2060px;
    	background: #2a2a2a;
    }
    Last edited by vrufusx65v; 12-21-2010 at 03:22 PM.

  2. #2
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: Centering my website...

    No -- if you've set the width to 1280px, then the container div will always be at 1280px wide, so on any screen less than about 1310px wide there will be a horizontal scroll bar. (Don't forget that browsers have "chrome", like the vertical scroll bar and application window borders that take up some screen space as well.) If 1280px is the widest you want the page to go, then set 1280px as the max-width instead of the width.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  3. #3
    bunny.invasion76 is offline x10Hosting Member bunny.invasion76 is an unknown quantity at this point
    Join Date
    Dec 2010
    Posts
    12

    Post Re: Centering my website...

    If you want to center it it must be like this:
    Code:
    .container {
    	margin-left: auto;
    	margin-right: auto;
    	position:static;
    	width:1280px;
    	height:2060px;
    	background: #2a2a2a;
    }
    But if you use Internet Explorer be sure you have the next on top of your HTMLscript ;D
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    Greets Magdy,

  4. #4
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: Centering my website...

    Quote Originally Posted by bunny.invasion76 View Post
    If you want to center it it must be like this:...
    Wrong. The CSS in the original posting, margin: 0 auto;, is a short form for this:
    Code:
    margin-top: 0;
    margin-right: auto;
    margin-bottom: 0;
    margin-left: auto;
    The order of attributes for the short form is Top, Right, Bottom, Left (remember TRouBLe as a mnemonic). There is absolutely no need to set the doctype to XHTML, since HTML 4.01 in standards mode (that is, with a full doctype declaration) and HTML 5 accomplish the same thing (and XHTML is a dead technology; XML dialects are great data transport containers, but they are lousy document markup languages for a number of reasons, not least of which is that they are sibling-order-agnostic). Finally, if you set a width for the page that is wider than the viewport, there will be a horizontal scroll bar -- and that was the original problem.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  5. #5
    bunny.invasion76 is offline x10Hosting Member bunny.invasion76 is an unknown quantity at this point
    Join Date
    Dec 2010
    Posts
    12

    Re: Centering my website...

    :D I always use the long code

    PS: In Internet Explorer 8 it wont work when you don't put the doctype :O (On my pc) ;D

    ---------- Post added at 10:24 AM ---------- Previous post was at 10:23 AM ----------

    Quote Originally Posted by essellar View Post
    Wrong. The CSS in the original posting, margin: 0 auto;, is a short form for this:
    Code:
    margin-top: 0;
    margin-right: auto;
    margin-bottom: 0;
    margin-left: auto;
    The order of attributes for the short form is Top, Right, Bottom, Left (remember TRouBLe as a mnemonic). There is absolutely no need to set the doctype to XHTML, since HTML 4.01 in standards mode (that is, with a full doctype declaration) and HTML 5 accomplish the same thing (and XHTML is a dead technology; XML dialects are great data transport containers, but they are lousy document markup languages for a number of reasons, not least of which is that they are sibling-order-agnostic). Finally, if you set a width for the page that is wider than the viewport, there will be a horizontal scroll bar -- and that was the original problem.
    OW, ok sorry, you're right ;D
    My mistake :P

+ Reply to Thread

Similar Threads

  1. Centering Div content
    By nmgod in forum Programming Help
    Replies: 3
    Last Post: 05-18-2010, 12:21 AM
  2. Centering website using css
    By wiileg3nd in forum Programming Help
    Replies: 8
    Last Post: 08-23-2008, 01:58 PM
  3. centering websites
    By mikel2k3 in forum Scripts & 3rd Party Apps
    Replies: 2
    Last Post: 02-21-2007, 11:46 AM
  4. centering a banner
    By RollerC in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 07-04-2005, 05:54 PM
  5. Centering ads
    By Ericsson in forum Free Hosting
    Replies: 2
    Last Post: 03-20-2005, 12:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers