CSS - Center A Div Inside Another Div
I have a fixed-width site and the content is enclosed inside a 750px div. I need to center a div inside that main container. I know I can use margin and text-align but then all of the divs in the main container will be centered where I only want one div to be centered. Any help would be much appreciated. Thanks!
Similar TutorialsCode: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 4.01 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> <title>Can I put my BAR in your FOO?</title> <style type="text/css"> body { margin: 0px; padding: 0px; } div#contents { width: 90%; margin-left: 5%; margin-right: 5%; border: 1px solid black; /* visual aid */ } div#thumbnails { border: 1px solid red; /* visual aid */ } div#thumb { float: left; } </style> </head> <body> <div id="contents"> <div id="thumbnails"> <div id="thumb"><img src="image1.jpg" /></div> <div id="thumb"><img src="image2.jpg" /></div> <div id="thumb"><img src="image3.jpg" /></div> <div id="thumb"><img src="image4.jpg" /></div> </div> </div> </body> </html> What I am trying to do is have the collection of "thumb" divs align in the center of the "contents". The number of "thumb"s will vary and I want them to fill the width of the screen no matter what width that may be, and change when the size of the window is changed. I realize that the float: left is pushing them to the left, but it's my understand that is how you get divs to appear side-by-side. So I figured I could enclose them in another div ("thumbnails") and then center it inside "contents", but "thumbnails" doesn't even seem to enclose the "thumb"s unless I specify a width, which I can't do because the number of thumbnails changes, and if I specify a width that is too big, the thumbs float back to the left and the extra containing div "thumbnails" is pointless. So, how do I get the "thumb"s to be side-by-side and have that collection of "thumbnail"s centered on the page, while still keeping things liquid? Currently working in IE6, but looking for support in IE5x, Opera, and Gecko based browsers. It seems I get one or the other, but not all. I've been trying to find a "solution" that allows me to have a parent <div> (with a fixed position-centered) on a browser page, and have it contain multiple nested <div> tags. I want to be able to do this so it works on both IE and FF, as well MAC. Through several attempts I've utilized a background-image--but don't believe that is compliant with "all" recent platforms, etc. I've also been able to place the nested <div> tags but then shove the parent div's image down ... Does anyone have thoughts, links, suggestions or a quick example to toss my way? Thanks Much and Happy New Year! Des I'm using a relative-positioned div as a container for an image, which is absolute-positioned. I'm doing this so that the image will automatically scale down to fit inside the containing div (nothing else I've tried has done this for me- so if there is another way to achieve this, please fill me in). This part works fine, but the image isn't as wide as the containing div, so I would like to center the image inside the div- but I can't seem to get it to work. I tried the obvious text-align:center in the div. That actually worked... kinda. The image's left-side was in the center of the div, but obviously isn't the 'centering' that I'm looking for. I then tried setting margin-left and margin-right on the image to auto, and that did nothing. I suspect that the fact that I have my image absolute-positioned is the culprit here, but I don't know how to get around it- or IF I can get around it without drastically changing my approach. Admittedly, the container div resides inside a table cell. I know that isn't the best practice, but I spent so much time trying a div-only approach only to waste time and become frustrated that I went back to what I know works- at least for now. I tried removing the container div from the table and inserting the image directly to the table cell- but encountered more issues with the sizing of the image. Essentially, my code is something like this: CSS: Code: td#CONTENTDISPLAY { width: 100%; height: 100%; text-align: left; vertical-align: top; padding: 0 0 0 0; margin: 0 0 0 0; } div#CONTENTBANNER { position: relative; height: 100%; padding: 0 0 0 0; } img.CONTENTIMG { position: absolute; height: 100%; } HTML: Code: ... <td id="CONTENTDISPLAY"> <div id="CONTENTBANNER"> <img class="CONTENTIMG" /> </div> </td> ... Nothing flashy, I know. One thing I should mention, however, is that the image is ALWAYS placed inside the container div using a Javascript function (it's a dynamic image). I doubt that makes a difference, but I figure it's worth mentioning. Can anyone help point me in the right direction? Thanks! - skubik 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> 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? 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 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 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: "" ""; } 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 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> 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> 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;*/ } 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 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. 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. 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've tried the usual trick of setting the width and margin-left and right to auto but it just doesnt work. If someone could please help with this, that would be great. This is all the code in my css file as of now, i'm using an img tag as my bacground incase people were wondering, so that it would resize to fit the window. the #content block is the one that i'm referring to. css Code: Original - css Code body { font-family: Verdana, Tahoma, Arial; color: #FFFFFF; text-align: center; margin-left: auto; margin-right: auto; } .bg { width: 100%; position: absolute; top: 0; left: 0; z-index: 5000; } #content { width: 800px; height: 600px; top: 0px; left: 0px; position: absolute; z-index: 6000; border: 1px solid #FFFFFF; margin-left: auto; margin-right: auto; } .nav { background-image: url('images/blank.jpg'); background-repeat: no-repeat; } a:link { text-decoration: none; color: #0066CC; font-size: 9px; } a:hover { text-decoration: underline; color: #0066CC; font-size: 9px; } a:visited { text-decoration: none; color: #0066CC; font-size: 9px; } a:active { text-decoration: none; color: #0066CC; font-size: 9px; } body { i am trying to get the list to show over two lines like so (using _ as multiple spaces get turned on to one) how do i get both centered. _____item1____item2____item3 item4____item5____item6____item7 Code: <div class="homebodytext"> <ul> <li class="homebodylifloat">item1</li> <li class="homebodylifloat">item2</li> <li class="homebodylifloat">item3</li><br style="clear: both;"><br> <li class="homebodylifloat">item4</li> <li class="homebodylifloat">item5</li> <li class="homebodylifloat">item6</li> <li class="homebodylifloat">item7</li><br style="clear: both;"> </ul> </div> Code: .homebodytext { border: 0px solid #0000; text-align: center; width: 900px; padding-left: 20px; font-weight:bold; } .homebodylifloat { float: left; width: 220px; } 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 |