Centering whole page in CSS

Discussion in 'HTML' started by Scott, Jul 16, 2004.

  1. Scott

    Scott Guest

    Hi, I've tried centering a div on the page, which works in both MSIE and
    FireBird. However, make the window any less than 730px and the text either
    side goes off the screen and the scrollbars can't find it - anyone know a
    work-around?

    Also, ignore the copy I used to demonstrate it!

    Cheers,

    Scott

    =============================

    <html>
    <head>

    <style>
    div#container {
    width:730px;
    position:absolute;
    top:0;
    left:50%;
    margin-left:-365px;
    }
    </style>
    </head>
    <body>



    <div id="container">
    <div style="text-align:center;margin:auto;width:730px;">
    <div style="text-align:left;">



    HTML tables are the darlings of many Web designers, but the original intent
    of these tables was the tabular display of data (Excel-like format for
    easier reading). Designers quickly realized it was hard to control the
    placement of data within an HTML page, and tables provided the answer.
    Cascading Style Sheets (CSS) offer an alternative. A style sheet contains
    definitions of how content should be rendered on a page. The best way to
    approach the subject is to convert an HTML page that's laid out with tables
    to a page that uses style sheets. Let's get started.

    Layout with tables
    Tables allow items to be laid out according to columns and rows within a Web
    page. Figure A displays the conversion starting point for this article. It
    is a simple page that uses a table to display a picture, text message, and
    e-mail link on the screen. The image spans two rows, with the text and
    e-mail link displayed next to it.

    HTML tables are the darlings of many Web designers, but the original intent
    of these tables was the tabular display of data (Excel-like format for
    easier reading). Designers quickly realized it was hard to control the
    placement of data within an HTML page, and tables provided the answer.
    Cascading Style Sheets (CSS) offer an alternative. A style sheet contains
    definitions of how content should be rendered on a page. The best way to
    approach the subject is to convert an HTML page that's laid out with tables
    to a page that uses style sheets. Let's get started.

    Layout with tables
    Tables allow items to be laid out according to columns and rows within a Web
    page. Figure A displays the conversion starting point for this article. It
    is a simple page that uses a table to display a picture, text message, and
    e-mail link on the screen. The image spans two rows, with the text and
    e-mail link displayed next to it.

    HTML tables are the darlings of many Web designers, but the original intent
    of these tables was the tabular display of data (Excel-like format for
    easier reading). Designers quickly realized it was hard to control the
    placement of data within an HTML page, and tables provided the answer.
    Cascading Style Sheets (CSS) offer an alternative. A style sheet contains
    definitions of how content should be rendered on a page. The best way to
    approach the subject is to convert an HTML page that's laid out with tables
    to a page that uses style sheets. Let's get started.

    Layout with tables
    Tables allow items to be laid out according to columns and rows within a Web
    page. Figure A displays the conversion starting point for this article. It
    is a simple page that uses a table to display a picture, text message, and
    e-mail link on the screen. The image spans two rows, with the text and
    e-mail link displayed next to it.

    HTML tables are the darlings of many Web designers, but the original intent
    of these tables was the tabular display of data (Excel-like format for
    easier reading). Designers quickly realized it was hard to control the
    placement of data within an HTML page, and tables provided the answer.
    Cascading Style Sheets (CSS) offer an alternative. A style sheet contains
    definitions of how content should be rendered on a page. The best way to
    approach the subject is to convert an HTML page that's laid out with tables
    to a page that uses style sheets. Let's get started.

    Layout with tables
    Tables allow items to be laid out according to columns and rows within a Web
    page. Figure A displays the conversion starting point for this article. It
    is a simple page that uses a table to display a picture, text message, and
    e-mail link on the screen. The image spans two rows, with the text and
    e-mail link displayed next to it.

    HTML tables are the darlings of many Web designers, but the original intent
    of these tables was the tabular display of data (Excel-like format for
    easier reading). Designers quickly realized it was hard to control the
    placement of data within an HTML page, and tables provided the answer.
    Cascading Style Sheets (CSS) offer an alternative. A style sheet contains
    definitions of how content should be rendered on a page. The best way to
    approach the subject is to convert an HTML page that's laid out with tables
    to a page that uses style sheets. Let's get started.

    Layout with tables
    Tables allow items to be laid out according to columns and rows within a Web
    page. Figure A displays the conversion starting point for this article. It
    is a simple page that uses a table to display a picture, text message, and
    e-mail link on the screen. The image spans two rows, with the text and
    e-mail link displayed next to it.

    HTML tables are the darlings of many Web designers, but the original intent
    of these tables was the tabular display of data (Excel-like format for
    easier reading). Designers quickly realized it was hard to control the
    placement of data within an HTML page, and tables provided the answer.
    Cascading Style Sheets (CSS) offer an alternative. A style sheet contains
    definitions of how content should be rendered on a page. The best way to
    approach the subject is to convert an HTML page that's laid out with tables
    to a page that uses style sheets. Let's get started.

    Layout with tables
    Tables allow items to be laid out according to columns and rows within a Web
    page. Figure A displays the conversion starting point for this article. It
    is a simple page that uses a table to display a picture, text message, and
    e-mail link on the screen. The image spans two rows, with the text and
    e-mail link displayed next to it.


    HTML tables are the darlings of many Web designers, but the original intent
    of these tables was the tabular display of data (Excel-like format for
    easier reading). Designers quickly realized it was hard to control the
    placement of data within an HTML page, and tables provided the answer.
    Cascading Style Sheets (CSS) offer an alternative. A style sheet contains
    definitions of how content should be rendered on a page. The best way to
    approach the subject is to convert an HTML page that's laid out with tables
    to a page that uses style sheets. Let's get started.

    Layout with tables
    Tables allow items to be laid out according to columns and rows within a Web
    page. Figure A displays the conversion starting point for this article. It
    is a simple page that uses a table to display a picture, text message, and
    e-mail link on the screen. The image spans two rows, with the text and
    e-mail link displayed next to it.

    HTML tables are the darlings of many Web designers, but the original intent
    of these tables was the tabular display of data (Excel-like format for
    easier reading). Designers quickly realized it was hard to control the
    placement of data within an HTML page, and tables provided the answer.
    Cascading Style Sheets (CSS) offer an alternative. A style sheet contains
    definitions of how content should be rendered on a page. The best way to
    approach the subject is to convert an HTML page that's laid out with tables
    to a page that uses style sheets. Let's get started.

    Layout with tables
    Tables allow items to be laid out according to columns and rows within a Web
    page. Figure A displays the conversion starting point for this article. It
    is a simple page that uses a table to display a picture, text message, and
    e-mail link on the screen. The image spans two rows, with the text and
    e-mail link displayed next to it.

    HTML tables are the darlings of many Web designers, but the original intent
    of these tables was the tabular display of data (Excel-like format for
    easier reading). Designers quickly realized it was hard to control the
    placement of data within an HTML page, and tables provided the answer.
    Cascading Style Sheets (CSS) offer an alternative. A style sheet contains
    definitions of how content should be rendered on a page. The best way to
    approach the subject is to convert an HTML page that's laid out with tables
    to a page that uses style sheets. Let's get started.

    Layout with tables
    Tables allow items to be laid out according to columns and rows within a Web
    page. Figure A displays the conversion starting point for this article. It
    is a simple page that uses a table to display a picture, text message, and
    e-mail link on the screen. The image spans two rows, with the text and
    e-mail link displayed next to it.


    HTML tables are the darlings of many Web designers, but the original intent
    of these tables was the tabular display of data (Excel-like format for
    easier reading). Designers quickly realized it was hard to control the
    placement of data within an HTML page, and tables provided the answer.
    Cascading Style Sheets (CSS) offer an alternative. A style sheet contains
    definitions of how content should be rendered on a page. The best way to
    approach the subject is to convert an HTML page that's laid out with tables
    to a page that uses style sheets. Let's get started.

    Layout with tables
    Tables allow items to be laid out according to columns and rows within a Web
    page. Figure A displays the conversion starting point for this article. It
    is a simple page that uses a table to display a picture, text message, and
    e-mail link on the screen. The image spans two rows, with the text and
    e-mail link displayed next to it.

    HTML tables are the darlings of many Web designers, but the original intent
    of these tables was the tabular display of data (Excel-like format for
    easier reading). Designers quickly realized it was hard to control the
    placement of data within an HTML page, and tables provided the answer.
    Cascading Style Sheets (CSS) offer an alternative. A style sheet contains
    definitions of how content should be rendered on a page. The best way to
    approach the subject is to convert an HTML page that's laid out with tables
    to a page that uses style sheets. Let's get started.

    Layout with tables
    Tables allow items to be laid out according to columns and rows within a Web
    page. Figure A displays the conversion starting point for this article. It
    is a simple page that uses a table to display a picture, text message, and
    e-mail link on the screen. The image spans two rows, with the text and
    e-mail link displayed next to it.

    HTML tables are the darlings of many Web designers, but the original intent
    of these tables was the tabular display of data (Excel-like format for
    easier reading). Designers quickly realized it was hard to control the
    placement of data within an HTML page, and tables provided the answer.
    Cascading Style Sheets (CSS) offer an alternative. A style sheet contains
    definitions of how content should be rendered on a page. The best way to
    approach the subject is to convert an HTML page that's laid out with tables
    to a page that uses style sheets. Let's get started.

    Layout with tables
    Tables allow items to be laid out according to columns and rows within a Web
    page. Figure A displays the conversion starting point for this article. It
    is a simple page that uses a table to display a picture, text message, and
    e-mail link on the screen. The image spans two rows, with the text and
    e-mail link displayed next to it.



    </div>
    </div>
    </div>


    </body>
    </html>
     
    Scott, Jul 16, 2004
    #1
    1. Advertising

  2. Scott

    Els Guest

    Scott wrote:

    > Hi, I've tried centering a div on the page, which works in
    > both MSIE and FireBird. However, make the window any less
    > than 730px and the text either side goes off the screen and
    > the scrollbars can't find it - anyone know a work-around?


    http://locusmeus.com/html-css/pageslipping.html

    [snip loooong stuff]

    --
    Els http://locusmeus.com/
    Sonhos vem. Sonhos vão. O resto é imperfeito.
    - Renato Russo -
    Now playing: Cliff Richard & The Shadows - Be Bop A Lula
     
    Els, Jul 16, 2004
    #2
    1. Advertising

  3. Scott

    Nico Schuyt Guest

    Scott wrote:
    > Hi, I've tried centering a div on the page, which works in both MSIE
    > and FireBird. However, make the window any less than 730px and the
    > text either side goes off the screen and the scrollbars can't find it
    > - anyone know a work-around?


    Think it was a suggestion of brucie:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
    <style type="text/css">
    body{height:100%;}
    div{width:50%;height:50%;top:25%;left:25%;position:absolute;border:2px solid
    lime;}
    </style>
    </head>
    <body>
    <div>Xxxxx</div>
    </body
    </html>
     
    Nico Schuyt, Jul 16, 2004
    #3
  4. Scott

    DJ2 Guest

    "Nico Schuyt" <> wrote in message news:<40f78110$0$239$>...
    > Scott wrote:
    > > Hi, I've tried centering a div on the page, which works in both MSIE
    > > and FireBird. However, make the window any less than 730px and the
    > > text either side goes off the screen and the scrollbars can't find it
    > > - anyone know a work-around?

    >



    Many thanks for the kind help from both of you. Does the trick
    perfectly!

    I've been using HTML for many years, but still seem to get into a few
    bits of bother with CSS. Would never go back to all-tables sites now
    though!


    Best wishes,

    Mike
     
    DJ2, Jul 18, 2004
    #4
    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. OM
    Replies:
    3
    Views:
    11,929
    Phrederik
    Sep 3, 2003
  2. Lenny
    Replies:
    1
    Views:
    465
    Andy Holmes
    Oct 16, 2003
  3. Replies:
    5
    Views:
    24,863
  4. ppcguy
    Replies:
    7
    Views:
    773
    Toby Inkster
    Aug 26, 2005
  5. \A_Michigan_User\
    Replies:
    2
    Views:
    938
    \A_Michigan_User\
    Aug 21, 2006
Loading...

Share This Page