CSS - How To Center <div> Tags.
I want to center and element, more specifically div elements with css. I have looked through source code from many websites. It seems there is not a simple solution to centering text. I have tried using:
Code: .content { align: center; } I would like my content to remain centered even when the browser is resized. Instead for using "right: 400px" this works however for my resolution but not for the next guy. I am lost and would like an explanation. For other thread there were vague mentions about rightmargin and left margin. Unfortunately experimenting proved unsuccessful; therefore, leading me to write this thread. I greatly appreciate all help provided. Thanks Similar TutorialsI have a problem and I need some help on centering the UL,LI menus instead of having it stick to the left... Code: #dmenu { /* font-family: Arial, Helvetica, Sans-Serif; */ /* font-size: 12px; */ } #dmenu li ul { /* top: auto; */ /* left: auto; */ } #dmenu li:hover ul { /* lists nested under hovered list items */ display: block; } #dmenu li.over ul { display: block; } .xMenuUl { text-align: center; /* for IE stupidity */ background-color: #FFFFFF; list-style-type: none; /* hide the bullet icon */ margin: 0; padding: 0; } .xMenuLi { list-style-type: none; /* hide the bullet icon */ float: left; } .xMenuTitle { display: block; width: 100px; text-indent: 0px; text-decoration: none; border: 1px solid #000000; padding: 4px; line-height: 14px; } .xSubmenuUl { list-style-type: none; position: absolute; margin: 0; padding: 0; display: none; margin-top: -1px; background-color: #E7F7FF; background-position: top left; background-repeat: repeat-x; border-top: 1px solid #000000; border-bottom: 2px solid #000000; border-right: 2px solid #000000; border-left: 7px solid #FF0000; } .xSubmenuLi a { padding: 3px; text-decoration: none; color: #000000; display: block; width: 250px; } .xSubmenuLi a:hover { text-decoration: none; background: #336699; color: #FFFFFF; } Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> </head> <body> This is a test...<br>sdfsdf<br> <ul class="xMenuUl" id="dmenu"> <li class="xMenuLi"><a href="" class="xMenuTitle">Home</a> <ul class="xSubmenuUl"> <li class="xSubmenuLi"><a href="">Frequently asked questions</a></li> <li class="xSubmenuLi"><a href="">Impressum - Required by Law</a></li> <li class="xSubmenuLi"><a href="">Links and whos better than me</a></li> <li class="xSubmenuLi"><a href="">Sitemap - quick list of all links</a></li> </ul> </li> <li class="xMenuLi"><a href="" class="xMenuTitle">Perl</a> <ul class="xSubmenuUl"> <li class="xSubmenuLi"><a href="">Trees, Twigs and XML</a></li> <li class="xSubmenuLi"><a href="">Perl Data Types and using Hashes</a></li> <li class="xSubmenuLi"><a href="">XML Data and how to write it</a></li> <li class="xSubmenuLi"><a href="">XML Data and why I love it</a></li> </ul> </li> <li class="xMenuLi"><a href="" class="xMenuTitle">SVG</a> <ul class="xSubmenuUl"> <li class="xSubmenuLi"><a href="">Interactive with the mouse</a></li> <li class="xSubmenuLi"><a href="">Basic objects and which software</a></li> <li class="xSubmenuLi"><a href="">Interactive does not mean it is Flash</a></li> <li class="xSubmenuLi"><a href="">Animated ECMA and generating objects on the fly</a></li> <li class="xSubmenuLi"><a href="">Clipart and Popart</a></li> </ul> </li> </ul> this is a test....<br> asdf<br> </body> </html> Hi all, http://www.jaysonsgroup.com/zpip2/z.html - please see the bottom four links (home, glossary, contact, credits) The HTML is as follows: Code: <div class="centerlinks"> <table align='center'> <tr> <td> <ul> <li><a href='#'>Home</a></li> <li><a href='#'>Glossary</a></li> <li><a href='#'>Contact</a></li> <li><a href='#'>Credits</a></li> </ul> </td> </tr> </table> </div> The CSS: Code: .centerlinks { float: left; width: 550px; text-align: center; } .centerlinks ul { list-style-type: none; } .centerlinks li { float: left; padding-left: 10px; padding-right: 10px; } As you can see, what I want is a simple UL list that is horizontal, plain text, and centers within the 550px div that surrounds it , even if I add a fifth <li> link in the future. On Internet Explorer, the <table align='center'> hacks fixes the problem. But it doesn't work on Firefox. Any ideas how I can center this? (I know I can use padding-left or margin-left but then this isnt a good solution when more menu items are added to that list) Thanks in advance!! I'm wondering how to "vertical-align: middle" the text in the anchor tags. I haven't got that part to work. Code: a.aMenuLinks:link { color: #666666; font-family: tahoma, sans-serif; font-size: 8pt; font-style: normal; font-weight: bold; text-decoration: none; text-indent: 15px; width: 100%; height: 25px; display: block; } Thanks... I am using the following code how do I change it so that it would show up in the center of the brower window? Thanks Tim PHP Code: <div style="position: absolute; left: 0px; z-index: 1; top: 0px; align: center\"> <object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0 ,0\" width=\"544\" height=\"396\" id=\"cardio\" align=\"middle\"> <param name=\"allowScriptAccess\" value=\"sameDomain\" /> <param name=\"movie\" value=\"ads/cardio3.swf\" /> <param name=\"loop\" value=\"false\" /> <param name=\"quality\" value=\"high\" /> <param name=\"wmode\" value=\"transparent\" /> <param name=\"bgcolor\" value=\"#ffffff\" /> <embed src=\"ads/cardio3.swf\" loop=\"false\" quality=\"high\" wmode=\"transparent\" bgcolor=\"#ffffff\" width=\"544\" height=\"396\" name=\"cardio\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /> </object> </div> I need to center an img that I have fade in how do i change the below code so that it centers in the page STYLE=\"POSITION: absolute; HEIGHT:75%;WIDTH:75%;TOP:5;LEFT:0;VISIBILITY:VISIBLE; ZINDEX:1\" thanks tim for some reason the text inside the item class will not center. see the attachment. the top is how this code renders, the bottom is how i'd like it to look. i'm sure this is something simple that i'll end up slapping myself fore later Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <html> <head> <title> new document </title> <style type="text/css"> #ticker { background: #00f; overflow: auto; margin-left: 20px; margin-top: 10px; width: 835px; height: 52px; } #ticker #items { position: relative; top: 0px; } #ticker .cell { display: table-cell; vertical-align: middle; height: 51px; overflow: hidden; border-right: 3px solid #01364d; text-align: center; } #ticker .item { float: left; padding: 0 10px 0 10px; font: bold 10pt Arial; color: #fff; } </style> </head> <body> <div id="ticker"> <div id="items"> <div class="cell" id="item_01" style="width: 160px"><div class="item">Lorem: XXX%</div></div> <div class="cell" id="item_02" style="width: 160px"><div class="item">Lorem: XXX%</div></div> <div class="cell" id="item_03" style="width: 160px"><div class="item">Lorem: XXX%</div></div> <div class="cell" id="item_04" style="width: 160px"><div class="item">Lorem: XXX%</div></div> <div class="cell" id="item_05" style="width: 160px; border: 0"><div class="item">Lorem: XXX%</div></div> </div> </div> </body> </html> I'm strugling with this code. The homepage is http://thebeadingsite.com and I can't get this to line up properly. Here's my code, any suggestions?? Code: <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>The Beading Site</title> <style type='text/css'> body { background-color: black; } #bg-right { background-color: white; position: absolute; top: 0; bottom: 0; left: 50%; right: 0; z-index: -1; } #content { position: relative; top: 0; bottom: 0; left: 25%; right: 0; z-index: 0; } </style> </head> <body> <div id="bg-right"></div> <div id="content"><table id="Table_01" width="800" height="601" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="5"> <img src="images/bnt-site-final_01.jpg" width="800" height="158" alt=""></td> </tr> <tr> <td colspan="2" rowspan="2"> <img src="images/bnt-site-final_02.jpg" width="623" height="421" alt=""></td> <td><a href="http://www.etsy.com/shop/mixaleena" target="_blank"> <img src="images/bnt-site-final_03.jpg" width="72" height="38" border="0" alt="Click here to order online at Etsy!"></a></td> <td colspan="2" rowspan="2"> <img src="images/bnt-site-final_04.jpg" width="105" height="421" alt=""></td> </tr> <tr> <td> <img src="images/bnt-site-final_05.jpg" width="72" height="383" alt=""></td> </tr> <tr> <td> <img src="images/bnt-site-final_06.jpg" width="526" height="21" alt=""></td> <td colspan="3"> <a href="mailto:mixaleena@thebeadingsite.com?subject=Comments from the front page"> <img src="images/bnt-site-final_07.jpg" width="247" height="21" alt="" border="0"></a></td> <td> <img src="images/bnt-site-final_08.jpg" width="27" height="21" alt=""></td> </tr> <tr> <td> <img src="images/spacer.gif" width="526" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="97" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="72" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="78" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="27" height="1" alt=""></td> </tr> </table> </div> </body> </html> Hi all, I've got a table here and can't seem to get text-align:center in the cells that have colspan='2' (f1s, f2s...) as an attribute. HTML Code: Original - HTML Code <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Game</title> <style type='text/css'> table { border: 1px solid black; } tr.top { font-size:10px; } tr.tall { height:50px; } td { width:20px; border: 1px solid black; text-align:center; } td.name { font-size:18px; width:100px; height:50px; } td.finalscore { color:red; font-size:18px; width:40px; } </style> </head> <body> <table cellpadding=0 cellspacing=0> <tr class='top'> <td rowspan='2' colspan='2' class='name'>Name </td> <td> f1a </td> <td> f1b </td> <td> f2a </td> <td> f2b </td> <td> f3a </td> <td> f3b </td> <td> f4a </td> <td> f4b </td> <td> f5a </td> <td> f5b </td> <td> f6a </td> <td> f6b </td> <td> f7a </td> <td> f7b </td> <td> f8a </td> <td> f8b </td> <td> f9a </td> <td> f9b </td> <td> f10a </td> <td> f10b </td> <td> f10c </td> <td style="background-color:black"> </td> </tr> <tr class='tall'> <td colspan='2'>f1s</td> <td colspan='2'>f2s</td> <td colspan='2'>f3s</td> <td colspan='2'>f4s</td> <td colspan='2'>f5s</td> <td colspan='2'>f6s</td> <td colspan='2'>f7s</td> <td colspan='2'>f8s</td> <td colspan='2'>f9s</td> <td colspan='2'>f10s</td> <td colspan='2'>Score</td> </tr> </table> </body> </html> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Game</title> <style type='text/css'> table { border: 1px solid black; } tr.top { font-size:10px; } tr.tall { height:50px; } td { width:20px; border: 1px solid black; text-align:center; } td.name { font-size:18px; width:100px; height:50px; } td.finalscore { color:red; font-size:18px; width:40px; } </style> </head> <body> <table cellpadding=0 cellspacing=0> <tr class='top'> <td rowspan='2' colspan='2' class='name'>Name </td> <td> f1a </td> <td> f1b </td> <td> f2a </td> <td> f2b </td> <td> f3a </td> <td> f3b </td> <td> f4a </td> <td> f4b </td> <td> f5a </td> <td> f5b </td> <td> f6a </td> <td> f6b </td> <td> f7a </td> <td> f7b </td> <td> f8a </td> <td> f8b </td> <td> f9a </td> <td> f9b </td> <td> f10a </td> <td> f10b </td> <td> f10c </td> <td style="background-color:black"> </td> </tr> <tr class='tall'> <td colspan='2'>f1s</td> <td colspan='2'>f2s</td> <td colspan='2'>f3s</td> <td colspan='2'>f4s</td> <td colspan='2'>f5s</td> <td colspan='2'>f6s</td> <td colspan='2'>f7s</td> <td colspan='2'>f8s</td> <td colspan='2'>f9s</td> <td colspan='2'>f10s</td> <td colspan='2'>Score</td> </tr> </table> </body> </html> Any pointers? Thanks for taking the time to read my question. I have a div that has a specified width, and if I put margin-left: auto; and margin-right: auto; the div centers with in the parent div. I have another div that I don't want to have a specified width, and as a result the auto's don't center the div. How can I center my div? I've tried display: block; and that just makes it as wide as the parent div. If I remove display and put float: left, it sizes properly (shrinks to fit the contents), but floats left and doesn't heed the margin auto's. The colors are there to see the containers... I don't plan on keeping them.. please see http://www.scopicdesigns.com/LisaCl..._Portfolio1.htm for example. Thanks, Brad Hello, I have a container div and i want to put some fixed-width left-floated divs inside it. The problem is i want to make them appear in the center of the container, instead of left. The problem is i don't know how many of them there's going to be, therefore i can't just put them inside of another fixed-width container and set it's margin to auto. I could probably do it with tables easily, but how would i do it in css? I am having a small problem with centering a main container div.. The main div is 700 pixels wide .. I have numerous divs inside this container div. Everything is peachy, but I cant seem for the life of me to get the container div centered in the browser window... I tried <div align="center"> even tried text-align:center; any thoughts? I'm not quite sure how to do this: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> #content { float: left; width: 437px; margin: 10px; margin-top: 0; } /* end #content */ #content ul { list-style-type: none; margin-top: auto; padding-bottom: 1em; background-color: #00ff00; } /* end #content ul */ #content ul li { float: left; } /* end #content ul li */ #content ul li a { position: relative; left: 1px; top: 1px; text-decoration: none; color: #ff0000; } /* end #content ul li a */ #content p { clear: both; } .shadow { color: blue; position: absolute; left: -1px; top: -1px; } /* end .shadow */ </style> </head> <body> <div id="content"> <ul> <li><a href="#">Link 1<span class="shadow">Link 1</span></a></li> <li><a href="#">Link 2<span class="shadow">Link 2</span></a></li> <li><a href="#">Link 3<span class="shadow">Link 3</span></a></li> <li><a href="#">Link 4<span class="shadow">Link 4</span></a></li> </ul> </div> </body> </html> I need the text to be centered in the green box. Not sure the best way to do that. I have a div that I am using as a pop up layer. I just set the visible attribute on mouseover and mouseout. I want to have that dic pop up in the center of the screen vertically and horizontally. I have not had much luck with other examples but this is what I have: Div Code: <div class="popbox" id="1" onMouseover="showpop('1');" onMouseout="hidepop('1');"> <p class="popboxheader">HEADER</p> <p class="popboxcontent"> <table> <tr> <td class="popboxcontentleft" valign="top"><p>some content here</p></td> <td class="popboxcontentright" valign="top"><p>more content</p></td> </tr> </table> </p> </div> CSS Code: div.popbox { text-align: left; background-color:#ffffff; border: 1px solid black; padding: 5px; width: 570px; visibility: hidden; margin:0 auto; } .popboxheader { padding: 5px; color: white; letter-spacing: 2pt; background-color: #003399; font-family: Verdana, san-serif; font-size:16px; color:#ffffff; color:#ffffff; font-weight:bold; text-align:left; } .popboxcontent { font-size: 10pt; font-weight: normal; text-align: left; font-family: Verdana, san-serif; color:#4074b7; color:#0349A3; } .popboxright { font-size: 9pt; font-weight: normal; text-align: left; width:200px; font-family: Verdana, san-serif; color:#4074b7; color:#0349A3; } Script Code: function showpopp(cid){ var obj = document.getElementById(cid); obj.style.visibility = "visible"; } function hidepop(cid){ var obj = document.getElementById(cid); obj.style.visibility = "hidden"; } I am not sure, but I am writingthe div at the end of the content that is always shown on the screen, just for some info. Any help is appreciated. Thanks for reading my question Why does this not center the contents of my page in Firefox but it does in IE? This code is in my linked CSS file. Code: body { text-align: center; margin-top: 10px; background-image: url(images/fall-leaves.jpeg); background-attachment: fixed; /*background-color: #d8d8d8;*/ } Hello again CSS experts! I know this question gets asked a lot but I have had a search on here and google and can't seem to get it working for me. My page has a sidebar div which contains a UL menu (SpryMenuBar from Dreamweaver) I would like to center the menu within the div. I have tried putting it within a child div and playing with auto margins and left 50%, etc. but no joy. If anyone could point out what I'm doing wrong I'd would be very grateful. Another small issue (which I suspect is related) is the <p> in between the two menus wraps around the right of the first menu when viewed in IE. Jez index.php: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Mseis</title> <link href="includes/layout.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="container"> <div id="header"> <?php include("includes/header.php"); ?> <!-- end #header --></div> <div id="sidebar1"> <?php include("includes/menu.php"); ?> <!-- end #sidebar1 --> </div> <div id="mainContent"> <div id="navbar"> <a href="index.php">Home</a> <!-- end #navbar --></div> <div id="pageContent"> <h1> Main Content </h1> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam, justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at, odio. Donec et ipsum et sapien vehicula nonummy. Suspendisse potenti. Fusce varius urna id quam. Sed neque mi, varius eget, tincidunt nec, suscipit id, libero. In eget purus. Vestibulum ut nisl. Donec eu mi sed turpis feugiat feugiat. Integer turpis arcu, pellentesque eget, cursus et, fermentum ut, sapien. Fusce metus mi, eleifend sollicitudin, molestie id, varius et, nibh. Donec nec libero.</p> <h2>H2 level heading </h2> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam, justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at, odio.</p> <h3>H3 level heading </h3> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam, justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at, odio.</p> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam, justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at, odio.</p> <!-- end #pageContent --></div> <!-- end #mainContent --></div> <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --> <br class="clearfloat" /> <div id="footer"> <?php include("includes/footer.php"); ?> <!-- end #footer --></div> <!-- end #container --></div> </body> </html> menu.php: Code: <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script> <link href="SpryAssets/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" /> <div class="menu"> <p> <ul id="RootMenu" class="MenuBarVertical"> <li><a href="index.php">Home</a></li> <li><a href="about.php">About Us</a></li> <li><a href="#" class="MenuBarItemSubmenu">Services</a> <ul> <li><a href="#">Passive Acoustic Monitoring</a></li> <li><a href="#">Training</a></li> </ul> </li> <li><a href="#" class="MenuBarItemSubmenu">Personnel</a> <ul> <li><a href="#">Mseis</a></li> <li><a href="#">3rd Party</a></li> </ul> </li> <li><a href="#">Contact Us</a></li> </ul> </p> <p> The menu should be centered like this text, but looks odd in IE </p> <p> <ul id="StaffMenu" class="MenuBarVertical"> <li><a href="webmail.php">Webmail</a> </li> <?php if (strpos($_SESSION["permissions"], "upload") !== false) { echo "<li><a href=\"resources.php\" class=\"MenuBarItemSubmenu\">Operator Resources</a> <ul> <li><a href=\"upload.php\">Upload A File</a></li> <li><a href=\"uploads.php\">View Uploaded Files</a></li> </ul></li>"; } else { echo "<li><a href=\"resources.php\">Operator Resources</a></li>"; } ?> <li><a href="client.php">Client Resources</a></li> <?php if ($_SESSION['loggedin'] == true) { echo "<li><a href='logout.php'>Logout</a></li>"; } ?> </ul> </p> </div> <script type="text/javascript"> <!-- var MenuBar1 = new Spry.Widget.MenuBar("RootMenu", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"}); var MenuBar2 = new Spry.Widget.MenuBar("StaffMenu", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"}); //--> </script> layout.css: Code: @charset "utf-8"; @import url("reset.css"); html, body { font: 100% Verdana, Arial, Helvetica, sans-serif; background-color: #666666; margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */ padding: 0; text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */ color: #633C91; } #container { width: 80%; /* this will create a container 80% of the browser width */ background-color: #FFFFFF; margin: 1px auto; /* the auto margins (in conjunction with a width) center the page */ border: 1px solid #000000; text-align: left; /* this overrides the text-align: center on the body element. */ min-width: 800px; } #header { margin: 0; background-color: #DDDDDD; padding: 5px 20px; } #header img { vertical-align: middle; } /* Tips for sidebar1: 1. Since we are working in relative units, it's best not to use padding on the sidebar. It will be added to the overall width for standards compliant browsers creating an unknown actual width. 2. Since em units are used for the sidebar value, be aware that its width will vary with different default text sizes. 3. Space between the side of the div and the elements within it can be created by placing a left and right margin on those elements as seen in the ".twoColHybLtHdr #sidebar1 p" rule. */ #sidebar1 { float: left; width: 15%; /* since this element is floated, a width must be given */ background-color: #EBEBEB; /* the background color will be displayed for the length of the content in the column, but no further */ padding: 0; /* top and bottom padding create visual space within this div */ margin: 0; text-align: center; } #menu { margin: 0 auto; } /* Tips for mainContent: 1. The space between the mainContent and sidebar1 is created with the left margin on the mainContent div. No matter how much content the sidebar1 div contains, the column space will remain. You can remove this left margin if you want the #mainContent div's text to fill the #sidebar1 space when the content in #sidebar1 ends. 2. Be aware it is possible to cause float drop (the dropping of the non-floated mainContent area below the sidebar) if an element wider than it can contain is placed within the mainContent div. WIth a hybrid layout (percentage-based overall width with em-based sidebar), it may not be possible to calculate the exact width available. If the user's text size is larger than average, you will have a wider sidebar div and thus, less room in the mainContent div. You should be aware of this limitation - especially if the client is adding content with Contribute. 3. In the Internet Explorer Conditional Comment below, the zoom property is used to give the mainContent "hasLayout." This may help avoid several IE-specific bugs. */ #mainContent { margin: 0; /* the right margin can be given in percentages or pixels. It creates the space down the right side of the page. */ padding: 0; width: 85%; float: left; } #pageContent { margin: 0; padding: 10px; } #navbar { background-color: #AAAAAA; margin: 0; padding: 1px 10px; } #navbar, #navbar a { color:#FF0000; font-size: small; } #navbar a:link, #navbar a:visited { text-decoration:none; } #navbar a:hover, #navbar a:active { text-decoration:underline; } #footer { padding: 10px; /* this padding matches the left alignment of the elements in the divs that appear above it. */ background:#DDDDDD; } #footer p { margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */ padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */ } /* Miscellaneous classes for reuse */ .fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */ float: right; margin-left: 8px; } .fltlft { /* this class can be used to float an element left in your page */ float: left; margin-right: 8px; } .clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain a float */ clear: both; height: 0; font-size: 1px; line-height: 0px; } /* Custom CSS */ .msgreen { color: #BEDA57; } .msblue { color: #81C4E2; } .mspurple { color: #633C91; } .failed { color: #FF0000; } h1 { color: #BEDA57; font-size: 150%; font-weight: bolder; margin-top: 5px; margin-bottom: 5px; } h2 { color: #81C4E2; font-size: 140%; font-weight: bold; margin-top: 3px; margin-bottom: 3px; } h3 { color: #633C91; font-size: 140%; margin-top: 2px; margin-bottom: 2px; } p { margin-top: 10px; margin-bottom: 10px; } small { font-size: 60%; } fieldset { margin: 1.5em 0 0 0; padding: 0; background-color: #81C4E2; } legend { margin-left: 1em; color: #633C91; font-weight: bold; } fieldset ol { padding: 1em 1em 0 1em; list-style: none; } fieldset li { padding-bottom: 1em; } fieldset.submit { border-style: none; background-color: transparent; } label { display: block; color: #633C91; } input.btn { border: 1px solid; background-color: #81C4E2; color: #633C91; font: bold 80%; } input.btnhov{ border-color: #FF0000; } SpryMenuBarVertical.css Code: @charset "UTF-8"; /* SpryMenuBarVertical.css - version 0.6 - Spry Pre-Release 1.6.1 */ /* Copyright (c) 2006. Adobe Systems Incorporated. All rights reserved. */ /******************************************************************************* LAYOUT INFORMATION: describes box model, positioning, z-order *******************************************************************************/ /* The outermost container of the Menu Bar, a fixed width box with no margin or padding */ ul.MenuBarVertical { margin: 0; padding: 0; list-style-type: none; font-size: 100%; cursor: default; width: 8em; } /* Set the active Menu Bar with this class, currently setting z-index to accomodate IE rendering bug: http://therealcrisp.xs4all.nl/meuk/IE-zindexbug.html */ ul.MenuBarActive { z-index: 1000; } /* Menu item containers, position children relative to this container and are same fixed width as parent */ ul.MenuBarVertical li { margin: 0; padding: 0; list-style-type: none; font-size: 100%; position: relative; text-align: left; cursor: pointer; width: 8em; } /* Submenus should appear slightly overlapping to the right (95%) and up (-5%) with a higher z-index, but they are initially off the left side of the screen (-1000em) */ ul.MenuBarVertical ul { margin: -5% 0 0 95%; padding: 0; list-style-type: none; font-size: 100%; position: absolute; z-index: 1020; cursor: default; width: 8.2em; left: -1000em; top: 0; } /* Submenu that is showing with class designation MenuBarSubmenuVisible, we set left to 0 so it comes onto the screen */ ul.MenuBarVertical ul.MenuBarSubmenuVisible { left: 0; } /* Menu item containers are same fixed width as parent */ ul.MenuBarVertical ul li { width: 8.2em; } /******************************************************************************* DESIGN INFORMATION: describes color scheme, borders, fonts *******************************************************************************/ /* Outermost menu container has borders on all sides */ ul.MenuBarVertical { border: 1px solid #CCC; } /* Submenu containers have borders on all sides */ ul.MenuBarVertical ul { border: 1px solid #CCC; } /* Menu items are a light gray block with padding and no text decoration */ ul.MenuBarVertical a { display: block; cursor: pointer; background-color: #EEE; padding: 0.5em 0.75em; color: #333; text-decoration: none; } /* Menu items that have mouse over or focus have a blue background and white text */ ul.MenuBarVertical a:hover, ul.MenuBarVertical a:focus { background-color: #33C; color: #FFF; } /* Menu items that are open with submenus are set to MenuBarItemHover with a blue background and white text */ ul.MenuBarVertical a.MenuBarItemHover, ul.MenuBarVertical a.MenuBarItemSubmenuHover, ul.MenuBarVertical a.MenuBarSubmenuVisible { background-color: #33C; color: #FFF; } /******************************************************************************* SUBMENU INDICATION: styles if there is a submenu under a given menu item *******************************************************************************/ /* Menu items that have a submenu have the class designation MenuBarItemSubmenu and are set to use a background image positioned on the far left (95%) and centered vertically (50%) */ ul.MenuBarVertical a.MenuBarItemSubmenu { background-image: url(SpryMenuBarRight.gif); background-repeat: no-repeat; background-position: 95% 50%; } /* Menu items that are open with submenus have the class designation MenuBarItemSubmenuHover and are set to use a "hover" background image positioned on the far left (95%) and centered vertically (50%) */ ul.MenuBarVertical a.MenuBarItemSubmenuHover { background-image: url(SpryMenuBarRightHover.gif); background-repeat: no-repeat; background-position: 95% 50%; } /******************************************************************************* BROWSER HACKS: the hacks below should not be changed unless you are an expert *******************************************************************************/ /* HACK FOR IE: to make sure the sub menus show above form controls, we underlay each submenu with an iframe */ ul.MenuBarVertical iframe { position: absolute; z-index: 1010; filter:alpha(opacity:0.1); } /* HACK FOR IE: to stabilize appearance of menu items; the slash in float is to keep IE 5.0 from parsing */ @media screen, projection { ul.MenuBarVertical li.MenuBarItemIE { display: inline; f\loat: left; background: #FFF; } } reset.css Code: @charset "utf-8"; /* CSS Document */ html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td { margin: 0; padding: 0; border: 0; outline: 0; font-weight: inherit; font-style: inherit; font-size: 100%; font-family: inherit; vertical-align: baseline; } /* remember to define focus styles! */ :focus { outline: 0; } body { line-height: 1; color: black; background: white; } ol, ul { list-style: none; } /* tables still need 'cellspacing="0"' in the markup */ table { border-collapse: separate; border-spacing: 0; } caption, th, td { text-align: left; font-weight: normal; } blockquote:before, blockquote:after, q:before, q:after { content: ""; } blockquote, q { quotes: "" ""; } Thanks for taking the time to read my question. I have a 19 in CRT and a 22 in wide screen LCD monitor. I am trying to make my content center on the page, regardless of the monitor. As it stands, it looks to be centered on teh 19 in, but on the 22 in, it is very much to the left side of the screen. I just got the 22 in. Is there something different you have to do for wide screen monitors? I'm using margin: auto 0px; I have margin and padding off for my Body {} and have set marging and padding on all appropreate elements so that they work the same in IE and FF. In my html page, I'm using xhtml strict. Thanks, Brad Hi, I have some code that looks like this . #nav,#nav ul which puts all the listed elements in a vertical list. Now if I do ths #nav ul.. this changes all the elemnts to a horizontal list. What does the ',' do for the id css tags exactly as i thought it refered to nested <ul> lists but is doesn't. I've used css to change my alt tag text to be consistent in size and font to the rest of the site, however, a couple of my images are relatively thin, but are tall. It seems that the alt tags get centered to the image, so you only see the middle of the tag, not the beginning and the end. Is there a way to wrap the text within the confines of the image. Thanks. I need to center a div which contains two columns. Its important that the div encapsulates the content within. This is what I've done so far: CSS: Code: * { margin: 0; padding: 0; } #container { float: left; width: 960px; border: 1px solid #000000; } .left { float: left; width: 650px; } .right { float: left; width: 250px; } HTML: Code: <div id="container"> <div class="left"> left content goes here </div> <div class="right"> right content goes here </div> </div> Question: Is it possible to center #container to the middle of the page? Using margin: 0 auto; doesnt work with floating divs. Its very important that #container has a border around .left and .right. Any help will be appreciated Hi, I am looking to move my nav bar into the center www.leehughes.co.uk Am not sure how to do this, am worried about messing up the IE hacks.. Code: ul#nav { height:1.75em; border-top:1px solid #000; border-bottom:1px solid #646060; list-style:none; margin:0; /* reset the default left margin in IE */ padding:0 .5em 0 0; /* reset the default left padding in good browsers */ background:#000; font-size:1em; } #nav li { position:relative; /* establish stacking context for the AP'd dropdown sublist */ float:right; padding:0; line-height:1.75em; } #nav li a { float:left; padding:0 .5em; border-right: 1px solid #333; color: #CCCCCC; text-decoration: none; } #nav li a.first {border:none;} #nav li:hover, #nav li.sfhover{ background:#transparent;/* background for all links on hover */ visibility:visible;/* makes IE7 think something changes on hover, fixes IE sticking dropdown */ } #nav li:hover a, #nav li.sfhover a {color:#FFF;}/*1st level font color on hover*/ /*=== All Sublist Styles ===*/ #nav ul { position:absolute; /* position the sublist to nearest positioned ancestor, the (#nav li) in this case*/ width:12em; /*150px*/ margin-left:-999em;/* hide the sublist */ padding:0; left:0; /* IE6/7 need this to position the sublist correctly on hover*/ top:1.75em; background: url(fake-image.jpg);/* IE needs some sort of BG on the nested ul */ } #nav li li { float: none;/*reset the float from #nav li*/ display:block; height:auto; line-height:1.5; border:none;/*reset borders from #nav li*/ } #nav li li a { float: none;/*reset the float from #nav li*/ display:block; width:11em;/*IE6 needs a width (12em total with padding)*/ padding:0 .5em; border:0; } * html #nav li li a {display:inline-block;} /*hide an overflow bug in IE6*/ *+html #nav li li a {display:inline-block;} /*hide same overflow bug in IE7*/ /*=== Hide All Sublists ===*/ #nav li:hover ul, #nav li.sfhover ul { margin-left:-999em; } /*=== Sublist Font Colors ===*/ #nav li:hover li a, #nav li.sfhover li a {color:#FFF;} /*2nd level font color*/ #nav li li:hover a, #nav li li.sfhover a {color:#003366;} /*2nd level font color on hover*/ /*=== Second Level UL position on hover ===*/ #nav li:hover ul, #nav li.sfhover ul { margin-left: 0; /* show the sublist (line up with left border on main list items)*/ } Thanks |