body tag for width and centering

S

Sally West

Hi

Is there a tag for the body element to fix the width of the page?

And how do you center a page if it is narrower than the screen width?

It seems to default to the left.

Thanks
 
W

Webcastmaker

Is there a tag for the body element to fix the width of the page?
And how do you center a page if it is narrower than the screen width?
It seems to default to the left.

The first thing you need to do is go to www.w3schools.com and run
through the HTML and CSS tutorials. It will take you an hour or so,
and it will be more valuable than any answer you get for your
questions.

Oh yea, one way is use CSS to make the body center everything and put
a div in the body that uses CSS to set the width of the div.
 
R

rf

Sally said:
Hi
G'day.

Is there a tag

You mean attribute.
for the body element to fix the width of the page?

No. The body element *is* the page.

You would have to enclose your content in, say, a div element and set the
width of that, but you would not use the width attribute, you would use some
CSS.

<head>
<style type="text/css">
..content {width: 600px;}
</style>
</head>
<body>
<div class="content">
your content goes here.
And how do you center a page if it is narrower than the screen width?

by specifying margin: auto

..content {width: 600px; margin: auto;}

However this does not work in IE6 in quirks mode and prior versions of IE,
5.5 or below, so you need to also specify

body {text-align: center}

to utilize a bug in IE where it this not only aligns the text but also the
block level elements like divs. But then your text is centred so you also
need to cancel thus in the div by specifying text-align: left;

body {text-align: center}
..content {width: 600px; margin: auto; text-align: left;}

However, why do you want to fix the size of you page anyway? It's best to
let the page flow to the size of your users canvas:

http://allmyfaqs.com/faq.pl?AnySizeDesign
 
S

Spartanicus

rf said:
You mean attribute.


No. The body element *is* the page.

Incorrect, the body element is a block level element that can be given a
width and centered.
 
R

rf

Spartanicus wrote
Incorrect, the body element is a block level element that can be given a
width and centered.

I stand corrected.

I was experimenting with IE in quirks mode, maybe that is what confused me.

In any case, even though the body element can be sized and centred this does
not work with IE in quirks mode (or IE<6 I presume) so my solution still
stands, I think :)
 
C

C A Upsdell

Spartanicus said:
Incorrect, the body element is a block level element that can be given a
width and centered.

But not with older versions of IE. So putting a DIV inside the BODY is the
best way to do it if you want it to work with older browsers.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top