Centering with CSS

Discussion in 'HTML' started by somebody, Jan 9, 2004.

  1. somebody

    somebody Guest

    I want to center a div using CSS. Is it possible? Horizontal centering that
    is.

    See I have a div that is 700px wide, and I want to center it in the middle
    of the page.
     
    somebody, Jan 9, 2004
    #1
    1. Advertising

  2. somebody wrote:
    > I want to center a div using CSS. Is it possible? Horizontal centering that
    > is.


    <http://www.google.com/search?q=centering%20with%20css> says it's possible.


    Matthias
     
    Matthias Gutfeldt, Jan 9, 2004
    #2
    1. Advertising

  3. somebody

    Dylan Parry Guest

    somebody wrote:

    > I want to center a div using CSS. Is it possible? Horizontal centering that
    > is.


    Yes. Try:

    <url:http://bluerobot.com/web/css/center1.html>
    or
    <url:http://bluerobot.com/web/css/center2.html>

    HTH

    --
    Dylan Parry
    http://www.webpageworkshop.co.uk - FREE Web tutorials and references
     
    Dylan Parry, Jan 9, 2004
    #3
  4. somebody

    somebody Guest

    "Matthias Gutfeldt" <> wrote in message
    news:btmieu$8s5kb$-berlin.de...
    > somebody wrote:
    > > I want to center a div using CSS. Is it possible? Horizontal centering

    that
    > > is.

    >
    > <http://www.google.com/search?q=centering%20with%20css> says it's

    possible.

    I come here because I CBF reading. Just give me the answer.
     
    somebody, Jan 9, 2004
    #4
  5. somebody wrote:
    > "Matthias Gutfeldt" <> wrote in message
    > news:btmieu$8s5kb$-berlin.de...
    >
    >>somebody wrote:
    >>
    >>>I want to center a div using CSS. Is it possible? Horizontal centering

    >
    > that
    >
    >>>is.

    >>
    >><http://www.google.com/search?q=centering%20with%20css> says it's

    >
    > possible.
    >
    > I come here because I CBF reading. Just give me the answer.


    You asked whether it's possible. The answer is yes. Next question?


    Matthias
     
    Matthias Gutfeldt, Jan 9, 2004
    #5
  6. somebody

    somebody Guest

    "Matthias Gutfeldt" <> wrote in message
    news:btmjsh$8qrpu$-berlin.de...
    > somebody wrote:
    > > "Matthias Gutfeldt" <> wrote in message
    > > news:btmieu$8s5kb$-berlin.de...
    > >
    > >>somebody wrote:
    > >>
    > >>>I want to center a div using CSS. Is it possible? Horizontal centering

    > >
    > > that
    > >
    > >>>is.
    > >>
    > >><http://www.google.com/search?q=centering%20with%20css> says it's

    > >
    > > possible.
    > >
    > > I come here because I CBF reading. Just give me the answer.

    >
    > You asked whether it's possible. The answer is yes. Next question?


    Ok, how do i do it? I tried Google before posting of course and tried using
    padding 20% on the block or margin 20% on the body and it wasn't working.
     
    somebody, Jan 9, 2004
    #6
  7. somebody

    Dylan Parry Guest

    somebody wrote:

    > Ok, how do i do it? I tried Google before posting of course and tried
    > using padding 20% on the block or margin 20% on the body and it wasn't
    > working.


    If you bother to read the other reply in the thread you will find the
    answer.

    --
    Dylan Parry
    http://www.webpageworkshop.co.uk - FREE Web tutorials and references
    Now playing: Travis - Flowers in the Window from "The Invisible Band"
     
    Dylan Parry, Jan 9, 2004
    #7
  8. somebody wrote:
    > See I have a div that is 700px wide, and I want to center it in the middle
    > of the page.


    div {
    margin : auto;
    }

    But you shouldn't have a fixed-width div.
     
    Leif K-Brooks, Jan 9, 2004
    #8
  9. On Sat, 10 Jan 2004 02:26:24 +1030, "somebody" <> wrote:

    >"Matthias Gutfeldt" <> wrote in message
    >news:btmieu$8s5kb$-berlin.de...
    >> somebody wrote:
    >> > I want to center a div using CSS. Is it possible? Horizontal centering

    >that
    >> > is.

    >>
    >> <http://www.google.com/search?q=centering%20with%20css> says it's

    >possible.
    >
    >I come here because I CBF reading. Just give me the answer.


    CBF?? = can't breast feed?

    Nick


    --
    Nick Theodorakis

    nicholas_theodorakis [at] urmc [dot] rochester [dot] edu
     
    Nick Theodorakis, Jan 10, 2004
    #9
  10. somebody

    somebody Guest

    "Nick Theodorakis" <> wrote in message
    news:...
    > On Sat, 10 Jan 2004 02:26:24 +1030, "somebody" <> wrote:
    >
    > >"Matthias Gutfeldt" <> wrote in message
    > >news:btmieu$8s5kb$-berlin.de...
    > >> somebody wrote:
    > >> > I want to center a div using CSS. Is it possible? Horizontal

    centering
    > >that
    > >> > is.
    > >>
    > >> <http://www.google.com/search?q=centering%20with%20css> says it's

    > >possible.
    > >
    > >I come here because I CBF reading. Just give me the answer.

    >
    > CBF?? = can't breast feed?


    Yeah. It sux.
     
    somebody, Jan 10, 2004
    #10
  11. somebody

    somebody Guest

    Thanks everyone.
     
    somebody, Jan 10, 2004
    #11
  12. Toby A Inkster, Jan 10, 2004
    #12
  13. On Sat, 10 Jan 2004 02:14:08 +1030, "somebody" <> wrote:

    >I want to center a div using CSS. Is it possible? Horizontal centering that
    >is.
    >
    >See I have a div that is 700px wide, and I want to center it in the middle
    >of the page.
    >


    if you do

    text-align: center;

    in the body class, you can. Thats the only way I know of.


    :: Jeremy Morgan ::
    Self Proclaimed Expert
    Web Developer
    http://www.webfootcentral.com
     
    Jeremy C. Morgan, Jan 23, 2004
    #13
  14. somebody

    Steve Pugh Guest

    Jeremy C. Morgan <> wrote:
    >On Sat, 10 Jan 2004 02:14:08 +1030, "somebody" <> wrote:
    >
    >>I want to center a div using CSS. Is it possible? Horizontal centering that
    >>is.
    >>
    >>See I have a div that is 700px wide, and I want to center it in the middle
    >>of the page.


    And if the browser window is less than 700 pixels wide? Do you want to
    the div to still be centered?

    >if you do
    >
    >text-align: center;
    >
    >in the body class, you can. Thats the only way I know of.


    That only works in buggy browsers. Good browsers would center the
    contents of the div within the div but leave the div itself in its
    default left alignment.

    The standard compliant way would be to apply margin-left: auto; and
    margin-right: auto; to the div to be centered. This will work in
    Gecko, Opera, IE5 Mac and IE6 Win (assuming Standards mode is
    triggered by an appropriate Doctype). To make it work in IE5 we do
    indeed need to add text-align center to the div's parent element, but
    we then need to add text-align: left; to the div itself in order to
    keep the text within the div left aligned in browsers that actually
    properly understand basic CSS.

    Steve

    --
    "My theories appal you, my heresies outrage you,
    I never answer letters and you don't like my tie." - The Doctor

    Steve Pugh <> <http://steve.pugh.net/>
     
    Steve Pugh, Jan 23, 2004
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lenny
    Replies:
    1
    Views:
    451
    Andy Holmes
    Oct 16, 2003
  2. Replies:
    5
    Views:
    24,756
  3. Mopar

    centering and css

    Mopar, Dec 1, 2003, in forum: HTML
    Replies:
    7
    Views:
    552
    brucie
    Dec 1, 2003
  4. Will

    CSS centering

    Will, Apr 27, 2004, in forum: HTML
    Replies:
    11
    Views:
    838
    Nik Coughin
    Apr 29, 2004
  5. Scott

    Centering whole page in CSS

    Scott, Jul 16, 2004, in forum: HTML
    Replies:
    3
    Views:
    4,839
Loading...

Share This Page