NameSilo

XHTML Centering

Spaceship Spaceship
Watch

WebmasterTalk.us

Account Closed
Impact
2
Hello,

In XHTML, the only way I can center content and such is using CSS right? Using any align (<p> or <div>) attributes seems to be invalid, and using the <center> tags seems to be invalid, also. :(

The only way I can do this properly is through CSS? :alien:
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
iHosty said:
Hello,

In XHTML, the only way I can center content and such is using CSS right? Using any align (<p> or <div>) attributes seems to be invalid, and using the <center> tags seems to be invalid, also. :(

The only way I can do this properly is through CSS? :alien:

Generally, CSS plays a powerful role in XHTML and try it in that way.
 
0
•••
if you wish to center the entire page just put <div align="center"> right after <body> then put </div> right before </body>.

If you wish to just center stuff, you could apply it using CSS via an external linked file... or you could include it in your header. An alternative is to do this:

<div style="align: center">Content </div>
 
0
•••
hey, I had the same problem for a long time, then I tried using <center></center> and it allowed it. I think <center> is a tag that IS allowed.
 
0
•••
To center the text inside a div:
text-align: center;

To center the div itself:
margin: auto;
 
0
•••
<center> is only invalid in XHTML 1.1. In XHTML 1.0 it's valid. I find XHTML 1.1 to be way to strict if you ask me.
 
0
•••
There are at least two proper ways to center an element using CSS, these include:
Code:
element {
	text-align: center; /* for aligning text */
}
and:
Code:
element {
	margin:0 auto; /* to align anything else */
}
edit: I should mention that transitional XHTML does allow older HTML 4 elements, but I wouldn't recommend using transitional anyway.
 
Last edited:
0
•••
Rowan W, what did I write?
 
0
•••
sorry, must have scanned over it, all those other replies had me going blind.
 
Last edited:
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back