13 replies [Last post]
ntrg
Offline
newbie
Last seen: 17 years 19 weeks ago
Joined: 2005-11-13
Posts: 3
Points: 0

I would like to put <center></center> between <body></body> tags (how to do this: <body><center>.........</center></body>) in a stylesheet. This is because FireFox don't center the body's content with the attribute text-align: center in body definition ({body tex--align:center }.I must manually enter the <center> ... </center> tags in every one of 30 web pages!
If you know how to do, you can help me for saving time. Thanks!

n8gz4ez
n8gz4ez's picture
Offline
Leader
Last seen: 14 years 8 weeks ago
Timezone: GMT-6
Joined: 2005-06-13
Posts: 802
Points: 0

How to put &lt;center&gt;&lt;/center&gt; between body tags

Use CSS instead of <center>.

body {
margin: 0 auto;
}

edit: Shame on me

CSS:

.container {
  margin: 0 auto;
}

HTML:

<div class="container">
 <!-- content goes here -->
</div>

This is my big chance . . . yep, I blew it . . .

ClevaTreva
ClevaTreva's picture
Offline
Guru
A hilly place, UK
Last seen: 4 years 20 weeks ago
A hilly place, UK
Joined: 2004-02-05
Posts: 2902
Points: 0

How to put &lt;center&gt;&lt;/center&gt; between body tags

Hi

I may be wrong (I often am), but I think you need to have a fixed width defined in order that the auto thing will work. So, either the body has a width (of, say 760px), or you make a pagecontainer div (or somesuchlike) and do the same.

Trevor
PS, this centering method won't work for IE5, which needs text-align:center

ntrg
Offline
newbie
Last seen: 17 years 19 weeks ago
Joined: 2005-11-13
Posts: 3
Points: 0

How to put &lt;center&gt;&lt;/center&gt; between body tags

You are wright. I must have a width for the body (600px) for {body margin: 0 auto} to work. Excellent idea! Thanks!

Alexx
Offline
newbie
The Hague
Last seen: 17 years 20 weeks ago
The Hague
Joined: 2005-11-07
Posts: 2
Points: 0

How to put &lt;center&gt;&lt;/center&gt; between body tags

do not give body fixed witdh.
first DIV "box or Container"..
<div align="center">
.. content..
next one (div) you give fixed width..
</div>

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 8 years 23 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

How to put &lt;center&gt;&lt;/center&gt; between body tags

Alexx wrote:
do not give body fixed width.

Why not?

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

ntrg
Offline
newbie
Last seen: 17 years 19 weeks ago
Joined: 2005-11-13
Posts: 3
Points: 0

How to put &lt;center&gt;&lt;/center&gt; between body tags

FireFox centers quite well with a width to the body! I confirm.

ClevaTreva
ClevaTreva's picture
Offline
Guru
A hilly place, UK
Last seen: 4 years 20 weeks ago
A hilly place, UK
Joined: 2004-02-05
Posts: 2902
Points: 0

How to put &lt;center&gt;&lt;/center&gt; between body tags

Hi

Tyssen, what happens to a repeating background image if the body is width-restricted?

Trevor

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 8 years 11 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

How to put &lt;center&gt;&lt;/center&gt; between body tags

What on earth is this thread on about :? it looks like a good candidate or the prize of "posts most at cross purposes"

Why are we trying to center the 'body'? and why are we giving it fixed width? (not that it's not possible)

I think what Alexx was trying to say was not to center the body but to center a container within body as is normal practise.

@ntrg why do feel the need to work on the body tag in this fashion? rather than center a container/wrapper div using fixed width and auto margins and text-align:center on the body tag.

Trevor wrote:
Tyssen, what happens to a repeating background image if the body is width-restricted?


It would just repeat over the declared body width, wouldn't it?

But we haven't mentioned the html tag.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

n8gz4ez
n8gz4ez's picture
Offline
Leader
Last seen: 14 years 8 weeks ago
Timezone: GMT-6
Joined: 2005-06-13
Posts: 802
Points: 0

How to put &lt;center&gt;&lt;/center&gt; between body tags

Hugo wrote:
I think what Alexx was trying to say was not to center the body but to center a container within body as is normal practise.

@ntrg why do feel the need to work on the body tag in this fashion? rather than center a container/wrapper div using fixed width and auto margins and text-align:center on the body tag.


:oops: What I meant to say in the first place, I did not intend to center a the body, but a container in it.

This is my big chance . . . yep, I blew it . . .

ClevaTreva
ClevaTreva's picture
Offline
Guru
A hilly place, UK
Last seen: 4 years 20 weeks ago
A hilly place, UK
Joined: 2004-02-05
Posts: 2902
Points: 0

How to put &lt;center&gt;&lt;/center&gt; between body tags

Hi Hugo

That was why I made my first post.

Hugo wrote:
It would just repeat over the declared body width, wouldn't it?

Then there was a suggestion of a fixed width on the body, to which my answer was to pose that question, because the answer, which I knew (thanks) would probably not be what anyone would want to do.

I thought my first answer was what ntrg wanted. The rest was superfluous.

But this could go on like the Monty Python Cheese Shop sketch.

Trevor

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 8 years 11 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

How to put &lt;center&gt;&lt;/center&gt; between body tags

Phew I'm glad you knew that then Smile

I see now that it was one of those rehetetorical jobbies

Yes your first post did answer the question though ntrg did seem to take you up on the offer of playing with the body element.

Of course an image could be tiled across the html element.

This does have the feel of a Python sketch, lets see how far we can take it, never know we could start a sketch show for coders.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

ClevaTreva
ClevaTreva's picture
Offline
Guru
A hilly place, UK
Last seen: 4 years 20 weeks ago
A hilly place, UK
Joined: 2004-02-05
Posts: 2902
Points: 0

How to put &lt;center&gt;&lt;/center&gt; between body tags

I'll have spam, spam, spam, spam, eggs and spam.

thepineapplehead
thepineapplehead's picture
Offline
Moderator
Last seen: 47 weeks 5 days ago
Timezone: GMT+1
Joined: 2004-06-30
Posts: 9683
Points: 819

How to put &lt;center&gt;&lt;/center&gt; between body tags

Hugo wrote:
Of course an image could be tiled across the html element.

Thereby making my Divitis article even better Laughing out loud

Verschwindende wrote:
  • CSS doesn't make pies