6 Replies - 534 Views - Last Post: 25 November 2011 - 05:12 AM

#1 IT student-Oman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 17-November 11

Is this code correct to center fixed width page?

Posted 17 November 2011 - 03:07 PM

Is this code correct for centering fixed width page?
.container {position:relative; width:900px; margine:0 auto;
text-align:left;}
Is This A Good Question/Topic? 0
  • +

Replies To: Is this code correct to center fixed width page?

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3047
  • View blog
  • Posts: 4,562
  • Joined: 08-June 10

Re: Is this code correct to center fixed width page?

Posted 17 November 2011 - 03:23 PM

You've got the right idea, but there is a typo. margine should be margin.
Was This Post Helpful? 1
  • +
  • -

#3 IT student-Oman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 17-November 11

Re: Is this code correct to center fixed width page?

Posted 18 November 2011 - 04:17 AM

yes u r right
thanks
Was This Post Helpful? 0
  • +
  • -

#4 jwmollman  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 12
  • Joined: 30-November 10

Re: Is this code correct to center fixed width page?

Posted 19 November 2011 - 08:25 PM

This is my method:

#main {
    width: 700px;
    margin: 25px auto 25px auto;
    padding: 15px;
    border: 1px solid #848484;
}



For me, that's the quickest way for making a fixed-width container centered on the page.
Was This Post Helpful? 0
  • +
  • -

#5 Lemur  Icon User is offline

  • OpenBSD Head
  • member icon


Reputation: 1111
  • View blog
  • Posts: 3,061
  • Joined: 28-November 09

Re: Is this code correct to center fixed width page?

Posted 20 November 2011 - 12:06 AM

You might be careful of IE, it has a tendency not to center a page unless a text-align: center; is present. This also means making a left align in every other sub element or another container, but that's unfortunately how IE works.

@jw - Why not 25px auto instead of using all 4? Specifying 2 is the same as top/bottom left/right, 1 is all.
Was This Post Helpful? 1
  • +
  • -

#6 jwmollman  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 12
  • Joined: 30-November 10

Re: Is this code correct to center fixed width page?

Posted 24 November 2011 - 11:49 AM

View PostLemur, on 20 November 2011 - 03:06 AM, said:

@jw - Why not 25px auto instead of using all 4? Specifying 2 is the same as top/bottom left/right, 1 is all.

You are right, but I guess that's just the way I learned. It just became a habit on me. I guess it's easier to read for me.
Was This Post Helpful? 0
  • +
  • -

#7 Shane Hudson  Icon User is offline

  • D.I.C Technophile
  • member icon

Reputation: 341
  • View blog
  • Posts: 1,281
  • Joined: 06-December 09

Re: Is this code correct to center fixed width page?

Posted 25 November 2011 - 05:12 AM

View Postjwmollman, on 20 November 2011 - 03:25 AM, said:

This is my method:

#main {
    width: 700px;
    margin: 25px auto 25px auto;
    padding: 15px;
    border: 1px solid #848484;
}



For me, that's the quickest way for making a fixed-width container centered on the page.



This completely depends on the design. If you want one with top and bottom margin then of course it is correct. But as the question was how to centre, without showing any design it is safer to just do:

#main    {
    margin: 0 auto;
    width: 900px;
}



By the way, if anyone ever needs it centred absolutely rather than relatively...

#main    {
    left: 50%;
    position: absolute;
    margin-left: -450px;
    width: 900px;
}



I had a complicated design lately which that was the best way to do, took me a while to figure it out as it is not normal practise!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1