Jump to content

Replacement for <center>


Recommended Posts

I understand that the use of <center> is no longer encouraged. I tried this:<span style="align:center;">This text is centered</a> but it didn't work. I also tried<span style="text-align:center;">This text is centered</a> but that too didn't work.So what is the replacement for <center>?TIA

Link to comment
Share on other sites

div {margin-left: auto;margin-right:auto;}

Or some Browsers need this:

div {margin-left: auto;margin-right:auto;text-align:center;}

That first block of code you posted will in fact just center the div, and in so doing you'll probably and most likely center the text as a result. The other block on the other hand will both center-align the div and the text within. What you should do is use text-align: center; on the parent element, and margin: auto; on the child elementbody {text-align: center;}div {margin-left: auto;margin-right: auto;text-align: left;}That should do the following
  1. center all text AND elements in older versions of IE
  2. center the div element for newer browsers
  3. re-align the text in the centered element to the left (granted the element only was what you wanted aligned)

Simply for centering text you'd use the container element and give it the text-align: center; css info. I believe it needs to have a default or set value of display: block; for it to work though, which would explain why <span style="text-align: center;">Text</span> doesn't work, because the span element is by default displayed inline.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...