blogsmith Posted December 30, 2006 Share Posted December 30, 2006 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 More sharing options...
jlhaslip Posted December 30, 2006 Share Posted December 30, 2006 div {margin-left: auto;margin-right:auto;} Or some Browsers need this: div {margin-left: auto;margin-right:auto;text-align:center;} Link to comment Share on other sites More sharing options...
Jonas Posted December 30, 2006 Share Posted December 30, 2006 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 followingcenter all text AND elements in older versions of IE center the div element for newer browsers 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now