Hello Friends, I have recently started using CSS. I wanted to know that if i wanted to centre align the div like if i have a 102x786 resolution byt the div is only 780 px and want to centre align the div, then what shoulld i do? How can we centre align the layers?? Could someone please guide me ?? its urgent. Thanks Jyot Vakharia www.jchem.info
I'm not sure i understand what you want to accomplish here. To center the div itself, set the left and right margins to auto (ie: margin: 0 auto). To center the text within the div, use text-align:center on the div.
Hi JC. To center align a layer, you'll need to set its margin to 0px auto. Here is a small example: [code div.main { width: 780px; background-color:#f0f0f0; margin:0px auto } [/code] Inside the body, you may have <div class="main">Something something</div> Code (markup): If you try this under firefox, you'll see it works as planned where as it doesnt in Internet Explorer. The work around for IE is to add a text-align:center to the body class and then you'll need to add text-align:left to the main class. Here is the modified code. Works well for both IE and FF. body {text-align:center} div.main { width:780px; background-color:#f0f0f0; margin:0px auto; text-align:left} Code (markup):
This sample should work in standard-compliant browsers and IE6+ (don't bother wasting your time on taking care of IE5/5.5): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Sample</title> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <style type="text/css"> #box { width: 200px; height: 200px; margin: 0 auto; background-color: #EAF4E9; border: 1px solid #333333; } </style> </head> <body> <div id="box"></div> </body> </html> Code (markup):
do u mean align a single div on centre of screen? if so then set left and right margins to auto and you will have a centred div.