The main page div container isn't centering when I add float: center to the CSS. When I add something like this in the CSS margin: 150px; It'll be centered in IE8 on my PC, but not centered in IE8 on a laptop. Help please
I wish they did have center. Unfortunately, you can only float left or right. Normally, you add a width and margin: 0 auto; to the container. Try that, but remove float: center and the margin first.
There's no such thing as float:center. If you want to centre a block level element, give it a width and margin:0 auto.
<div style="position:absolute; text-align:left; background-colorrenge; left:190px; top:100px; width:100px; height:100px;z-index:99; visibility:visible">your content hear<div> set the left,top,according to your requirement .it works try this code...
I've researched centering a div exhaustively. Many say that "width" and/or "margin: 0 auto" and/or "text-align:center" are required, but I don't think that's true. I have found that the following will work in ALL cases: CSS .outer {text-align:center} .inner {display:table; margin-left:auto; margin-right:auto} /* - \*/ * html .inner {display:inline; zoom:1} /* - */ HTML <div class="outer"> <div class="inner"> your content </div></div> If you don't care about IE, it gets even simpler: You would not need the outer div (only IE requires text-align) and you would not need the display:inline and zoom:1.
Comical genius Hey, who needs markup anyway. Let's do it all in Javascript. <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'> <head profile='http://gmpg.org/xfn/11'> <meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> <title>Center Demo</title> <script type='text/javascript'> window.onload = function () { var div = document.createElement('div'); div.id = 'container'; div.style.background = '#eee'; div.style.height = '600px'; div.style.margin = '0 auto'; div.style.width = '600px'; document.body.appendChild(div); } </script> </head> <body> </body> </html> Code (markup):