I'm using the Strict doctype for the first time and I'm having difficulty getting things to center align. The align attribute is not allowed in XHTML 1.0 Strict, and I've tried both text-align: center; Code (markup): and margin-left: auto; margin-right: auto; Code (markup): in the hope that it would get Internet Explorer to centrally align. Unfortunately it doesn't . Can anyone point me in the right direction? Note: The above CSS acheives the desired effect in both Firefox and Opera.
I've found a slightly messy solution in that the content can be contained with a 100% wide table with one cell that is text-aligned to center. Still, if anyone knows of a better way, that would be great.
I have yep (found that page on Google too ), but unfortunately it doesn't appear to be working. It's a <div> that I need centrally aligned, and text-align seems to work for things like text, images etc. only.
Put your div in a container div and center align the container: <html> <head> <style> .container{ background: green; padding: 20px; border: 1px solid black; text-align:center } .mydiv{ border=1px solid blue; background: red; font-weight: bold; padding: 20px; } </style> <head> <body> <div class="container"> <div class="mydiv">some text</div> </div> </body> </html> HTML:
A bit of a warning about using xhtml strict - the document will not get properly parsed unless you use a proper DOCTYPE declaration - and IE does not support xhtml - it parses it as html and implements some bug fixes brought about in IE6. If you use a proper http header (application/html+xml) ie will not display it at all.