Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Centering page content - Keeping it within compliance 1

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
Alright, it is time I curve myself and start adhering to using HTML compliant tags and use HTML validator to make sure my code is 100% complaint ... or as close as I can bring it.

I have been using <center> to center my page content. The validator picks up an error on this tag. I know it has been deprecated but I cannot find a remedy to replace it with.

I have tried:

Code:
<body style="margin-left: auto; margin-right: auto;">

AND

<body>
<div id="mainContainer" style="margin-left: auto; margin-right: auto;">

but nothing is centered. Content shows normal (left justified).

What is my solution?

For now, I am sticking to <center> until I learn what is now the "unknown".

Thanks,
 
Either:

1. Content is not really left justified but it fills up the entire space (unless you specify a width, div will take up entire width of its container).

2. You're not using a complete and valid doctype (to force your browser to use standards-compliance mode) or you're checking the code on an outdated browser (such as IE5.5 or earlier).


___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
I am using FF 2.0.0.16 and my DOCTYPE is

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]

To validate, I am using a plug in I just installed on my FF
Code:
[URL unfurl="true"]http://users.skynet.be/mgueury/mozilla/index.html[/URL]

What say you?

Thanks,
 
Like Vrag said:
Vragabond said:
(unless you specify a width, div will take up entire width of its container).

Perhaps setting a width to the mainContainer will show you centered content.
 
You have to understand that centring of blocks works different to how it used to in old quirks mode. Instead of specifying a container where everything inside that container will be centred, you're specifying which element should be moved to the centre. That means that your style on body is not needed and it probably plays no role in #mainContainer -- unless that is the actual element you're trying to centre.

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
This yielded the original results. I think it follows you just mentioned about centering the element intended to be centered.

Code:
<body>
<table cellpadding="0" cellspacing="0" style="margin-left: auto; margin-right: auto; width: 960px; border: 0px collapse #FFF;">

Thanks!
 
It also follows that you gave that element a width for which auto margins can be applied.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top