Centering whole page in CSS

S

Scott

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>
 
N

Nico Schuyt

Scott said:
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>
 
D

DJ2

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,147
Latest member
CarenSchni
Top