Hello I have a div with fix height and width, All my content is there. What I want is to center that div so that regardless of what the resolution of the monitor is that div will still be on the center of the body. How will I able to this? Thanks!
For a more accurate answer, you should provide your code, both the HTML and the CSS. However, I think that simply adding the following CSS to the styling of your div should do it. First, give your div an ID, thus: <div id="div_id"></div> Code (markup): Then, add this to your CSS: #div_id { margin: 0 auto; } Code (markup): You can also use absolute or relative positioning, but I would avoid doing so. Note that the method above won't work on IE 5. But, then, who cares, right?
Do this with CSS: .center-div { margin-left: auto; margin-right: auto; } That's how I do it, and it should work EDIT: Masterful beat me to it, so know you have two possible solution
Yet another way, probably the laziest... <div align="center"> <div>content</div> </div> Code (markup):
Hello I still cant get it can you guys pls. fix this here my css and html code. Css Code body{ margin: 0 auto; padding: 0; background-image:url(../Image/bg.jpg); background-repeat:repeat-x; font-family:Verdana,Arial,Sans-Serif; font-size:90%; color:#ccc; text-align: center; } #MainDiv{ background-color: #FFFFFF; height: 900px; width: 850px; margin-left: 70px; padding-left: 7px; padding-right: 7px; padding-top: 10px; border-style: none; } Html code: <body> <div id="MainDiv"> divs inside contents </div> </body> What I want to center is the main div where my content is located. Thanks!
Did you try my lazy method? <body> <div align="center"> <div id="MainDiv"> divs inside contents </div> </div> </body>
or everything you want in the center in <center></center> who cares if its deprecated if people still use it the browsers will still render it
You mean like the 'layer' element? It was deprecated but I would hate to be one who learned and depended on it. There are lots of obsolete elements you can learn that could disappear on you with the very next version of any browser. I think 'marquee' doesn't work in IE8, for example. Do not learn and do not use deprecated elements.
Or you can try this: <body> <div id="center"> <div id="MainDiv"> divs inside contents </div> </div> </body> CSS: #center{margin:0 auto;width:934px;} The width comes from: #MainDiv width+margin+padding. But for sure, your content won't exatly in the center because you applied the margin-left to the #MainDiv.