CSS - Centering But Not Quite, Question
im updating a site, and figure ill start from scratch just using nice tidy css.
im keeping all the design elements (well for the most part), just updating the code.(its pretty cluncky and haphazard as it is) Its been hashed apart by different folks working on it. there is a design strip that's supposed to always sit on the left of the page, the menu bar and content is suposed to be centered but not cross over the design strip on the left. the design strip is styled in the body tag any help is appreciated william Similar TutorialsI will preface this with the fact I am a newbie with CSS. Site location - I would tell you where site was but against rules! Question - site looks OK on everything except IE6 and lower. The body should be centered under the header image however it is pushed/alligned left. The CSS is below. Can anyone see why this is happening and what a good fix would be? Thanks /* CSS Document */ body{ padding:0; margin:0;} form, div, p , ul, span, h2, h3, h4, h1,input, img{ padding:0; margin:0;} p{ color:#3D3B45; font: 12px/normal Verdana, Arial, Helvetica, sans-serif} ul{ list-style-type:none } img { border:none; } .spacer{ font-size:0; line-height:0; clear:both; } /*---------------header-------------------------------*/ #main{ width:780px; margin:0 auto 0 auto; background:#FFFCEC; } #main #header{ width:780px; height:175px; background:#FFFCEC url(images/header.jpg) no-repeat 0 5px; position:relative; } #header a.title{ position:absolute; left:23px; top:37px; width:228px; height:25px; display:block; } #header h1.title a{ display:block; text-decoration:none; } #header ul.nav{ position:absolute; left:566px; top:5px; background:url(images/nav.gif repeat-x 0 0 #FFFEE4; width:213px; padding:0px 0 18px 0; margin:0; } #header ul.nav li{ background:url(images/h_line.gif) repeat-x left bottom; font:bold 11px/normal Arial, Helvetica, sans-serif, Tahoma; color:#484848; width:197px; padding:5px 0 5px 0; } #header ul.nav li a{ background:url(images/arrow.gif) no-repeat 0 5px; margin:0 0 0 15px; font:bold 11px/normal Arial, Helvetica, sans-serif, Tahoma; color:#484848; text-decoration:none; padding:0 0 0 15px; } #header ul.nav li a:hover{ color:#000000; } /*------body-------*/ #main #left{ background:url(images/v_line.gif) repeat-y right top; width:543px; margin:0 0 0 0; padding:15px 0px 0px 23px; float:left; } #left h2.contact{ background:url(images/contact_wp.gif) no-repeat 0 0; width:518px; height:16px; text-indent:-200000px; } #left h2.survty{ background:url(images/survty.gif) no-repeat 0 0; width:518px; height:32px; text-indent:-200000px; } #left h2.welcome{ background:url(images/welcome_to_wp.gif) no-repeat 0 0; width:518px; height:35px; text-indent:-200000px; } #left p.weltxt{ font: 12px/normal Verdana, Arial, Helvetica, sans-serif; color:#3D3B45; text-align:justify; width:518px; margin:0px 0 0 0; } #left p.weltxtsp{ font: 12px/normal Verdana, Arial, Helvetica, sans-serif; color:#3D3B45; text-align:justify; width:518px; margin:16px 10px 10px 0; } #left p.headingtext{ font: 12px/normal Verdana, Arial, Helvetica, sans-serif; color:#3D3B45; text-align:justify; width:518px; margin:10px 0px 10px 0; } #left p.weltxt a.more{ float:right; padding:25px 0 21px 0; color:#3D3B45; text-decoration:none; font-weight:bold; } #left p.weltxt a:hover{ color:#990000; text-decoration:underline; } #left h2.rest{ background: url(images/catering.gif) no-repeat 0 0; width:516px; height:29px; line-height:0; font-size:0; margin:20px 0 0 0; text-indent:-200000px; clear:both; } #left div.menu{ background:url(images/menu_bg.gif) repeat-x 0 0; width:516px; height:123px; padding:11px 0 0 7px; } #left div.menu ul.brown{ float:left; width:94px; margin:0 8px 30px 0; display:block; } ul.brown li{ background:url(images/brown.gif) no-repeat 0 8px; padding:0 0 13px 10px; color:#3D3B45; } ul.brown li a{ text-decoration:none; color:#3D3B45; font:bold 11px/normal Arial, Helvetica, sans-serif, Tahoma; } ul.brown li a:hover{ color:#990000; text-decoration:underline; } #left h2.order{ background:url(images/directions2.gif) no-repeat 0 0; width:513px; height:26px; text-indent:-200000px; clear:both; } #left ul.image{ margin:15px 0 0 0; width:520px; } #left ul.image li{ height:153px; width:95px; text-align:center; margin:0 6px 0 0 ; background:url(images/order_now.gif) no-repeat 14px 134px; float:left; font:bold 11px/normal Arial, Helvetica, sans-serif, Tahoma; color:#3D3B45; } #left ul.image li span{ color:#B57D0A; } #left ul.image li a{ margin:0 0 0 0; text-decoration:none; color:#990000; } #left ul.image li a:hover{ color:#000000; text-decoration:underline;} /*------right----*/ #main #right{ width:200px; background:url(images/right_bg.gif) repeat-x left bottom #FFFEE4; float:left; padding:25px 0 97px 13px; } #right h2.our{ background: url(images/location.gif) no-repeat 0 0; width:145px; height:15px; text-indent:-200000px; } #right p.ourtxt{ font: 12px/normal Verdana, Arial, Helvetica, sans-serif; color:#3D3B45; text-align:justify; width:168px; margin:18px 0 0 0; } #right img{ margin:13px 0 0 0; } #right p.border{ width:178px; height:5px; margin:23px 0 0 0; font-size:0; line-height:0; background:#FCF2B8; } #right p.ourtxt span{ color:#8F1401; font:bold 12px/normal "Trebuchet MS",Helvetica, sans-serif, Tahoma; } #right p.ourtxt a{ color:#B57D0A; font:bold 12px/normal "Trebuchet MS",Helvetica, sans-serif, Tahoma; text-decoration:underline; } #right p.ourtxt a:hover{ color:#000000; } /*----footer-----*/ #footer{ width:780px; position:relative; background:url(images/footer_bg.gif) repeat-x 0 0 #FDF6D2 ; clear:both; height:168px; } #footer ul.foot{ position:absolute; top:21px; left:140px; width:522px; } #footer ul.foot li{ float:left; margin:0 14px 0 0; color:#232323; font:bold 11px/normal Arial, Helvetica, sans-serif, Tahoma; } #footer ul.foot li a{ text-decoration:none; text-transform:uppercase; color:#232323; } #footer ul.foot li a:hover{ color:#990000; } #footer p{ position:absolute; top:43px; left:324px; text-align:center; color:#232323; font:normal 11px/20px Arial, Helvetica, sans-serif, Tahoma; } #footer p a{ color:#232323; font:normal 11px/20px Arial, Helvetica, sans-serif, Tahoma; text-decoration:underline; } #footer p a:hover{ text-decoration:none; } For IE, I have used text-align:center; to define the body tag, which allows the entire website to be centered no matter the browser window size. That method doesn't seem to be working for Firefox, yet I have seen it done before. A few of my divs are using absolute positioning (NOT absolute to the document, mind you, but to a parent div). Could this affect anything? Again, it works fine in IE, but not in Firefox or Safari If body {text-align:center;} is not a good centering tool, I would love any other suggestions. Thanks! hi, just started with css and im having trouble centering 3 columns in a container. Code: <div id="container"> <div id="content"> <h1>Title Header</h1> <div id="top"> <div class="col"> <h2>Section Header</h2> <p>Lorem ipsum est cu voluptatum efficiantur deterruisset, nec et solum lucilius argumentum, eum ei regione bonorum suavitate. Lorem nonummy suscipiantur sit cu, id eum soluta putant. Sale porro rationibus mei no. Vis ut primis virtute nostrud, sea an malis menandri definiebas, his agam ancillae delectus ei. Ei deleniti noluisse interesset quo, vis at quem scriptorem cotidieque. Sit an virtute gubergren expetendis, at ludus dolor accusam per.</p> </div> <div class="col"> <h2>Section Header</h2> <p>Ferri docendi nec ut. Viris tamquam ad quo, nam admodum facilisis adolescens ut, usu meis iriure tractatos at. Ei duo eros qualisque elaboraret, paulo vivendo inciderint an duo, mea eius exerci constituam cu. Ne facer exerci appetere vis, id dicat malorum mel, an sed ferri ludus aliquyam. Ut omnis meliore praesent usu, te sit quas tempor moderatius, accusam voluptua eam at. Duo agam etiam facilisi eu, cum an aeque congue contentiones, id omnium persecuti sadipscing sit. Ne eum invidunt laboramus, eum error nostro ad.</p> </div> <div class="col"> <h2>Section Header</h2> <p>Quem feugiat adipisci no sed, simul solet mandamus ut sea, no vocent corrumpit argumentum per. Cu iisque facilisi insolens est, posse nonummy adipisci vel ut. An has nibh natum dissentias, te lorem legere posidonium eam, te quodsi prompta euripidis sed. Ne noluisse petentium cum, sed utroque offendit recteque eu. Te cum petentium disputando, id duo oratio fuisset gloriatur, in sed timeam ponderum.</p> </div> </div> <div class="clear"></div> </div> <div id="footer"> <h3>Footer Header</h3> </div> </div> css: Code: * { margin: 0; padding:0; border: 0; } body { background-color: gray; text-align:center; } #container { width: 900px; background-color:white; margin: auto; } #content { } #top { margin: auto; } .col { margin: auto; width: 267px; float: left; text-align: left; } .clear { clear: both; } #footer { clear: both; } this obviously doesnt work. and has some serious issues. if not, coded wrong altogether. im free to any suggestions as far as my div markups and what i should be doing to keep code efficient. i also am wondering what the keyword 'auto' mean in css. ive searched all around and never found a good exp or example explaining what it is. again, the css is pretty screwed. i added and deleted so much that i cant even remember what i did and getting a little frustrated in the process. thanks in advance for the response. This list is a navigation bar that displays tabs horizontally. I can't seem to figure out what properties I need to use to center it correctly. I have 2 problems: 1. How can I get these list items centered? 2. the second level seems to have problems displaying horizontally in IE. How can I fix it? Code: <div id="tablenavcontainer"> <div id="navcontainer"> <ul> <li><a href="/doctors/enroll/" rel="self" class="" id="purple" name="patientenroll">Enroll Patient</a></li> <li><a href="/doctors/patients/" rel="self" class="" id="current" name="doctorspatients">My Patients</a></li> <li><a href="/doctors/lab/" rel="self" class="" id="green" name="doctorlab">Lab</a></li> <li><a href="/doctors/pharmacy" rel="self" class="" id="yellow" name="doctorpharmacy">Pharmacy</a></li> <li><a href="/doctors/tools/" rel="self" class="" id="red" name="doctortools">My Office Tools</a></li> <li><a href="/doctors/home/" rel="self" class="" id="graphite" name="doctorhome">Home</a></li> <ul> <li><a href="/doctors/patients/currentchart.html" rel="self" id="currentchart" name="currentchart" >Current Chart</a></li> <li><a href="/doctors/patients/labhistory.html" rel="self" id="labhistory" name="labhistory" >Lab History</a></li> <li><a href="/doctors/patients/symptomhistory.html" rel="self" id="symptoms" name="symptoms" >Symptom History</a></li> <li><a href="/doctors/patients/prescriptionhistory.html" rel="self" id="prescriptions" name="prescriptions" >Prescription History</a></li> <li><a href="/doctors/patients/reports.html" rel="self" id="reports" name="reports" >Restore Reports</a></li> <li><a href="/doctors/lab/ordertesting.html" rel="self" id="ordertest" name="ordertest" >Order Testing</a></li> <li><a href="/doctors/pharmacy/prescribe.html" rel="self" id="orderrx" name="orderrx" >Prescribe</a></li> <li><a href="/logout.html" rel="self" id="" name="" >Log Out</a></li> </ul> </ul> <br style="clear: both;" /> </div> </div> Hi, I'm trying to design a web page and I want to center all the content (including the background), and have another background behind all of that. I can't figure out how to center everything. When I put a <div> around all the content and center it in CSS, only certain elements(some graphical buttons) get centered while all of the text stays lined up to the left. Any ideas? I'm sure I'm making a really silly mistake. Hey everyone, I am fairly comfortable with HTML, and even know a decent amount of PHP and Javascript. But sometimes trying to do the simplest things in CSS makes my head spin! (this is one of those times). I've got a "scrolling" header at the top of a page (stays visible even when scrolling), and am trying to center a DIV (which contains opt-in forms) inside that header. It looks good when my browser window is maximized (at 1280x1024 resolution). But when I minimize the browser or check it in other screen resolutions, the "centering" of the opt-in forms are off. Here is the page... www.wordflood.com/Test/Scrolling_Header.html And here are the CSS includes... www.wordflood.com/Test/style.css www.wordflood.com/Test/IE6_style.css This was really just a quick hack from a "scrolling header" demo I found online, so I must have overlooked something. Any ideas? Good day to you all, I'm working on a pop up css box. My problem is that I can't make it to be centered. Here is my code : PHP Code: echo "<a onmouseover=\"this.style.cursor='pointer'\" onfocus=\"this.blur();\" onclick=\"document.getElementById('$namess').style.display = 'block' \" >\r"; echo "<span><img src=\"http://ponder.peuplies.info/V_0-1/Art/".$imgdir."".$img."\" width=\"50\" border=\"0\" title=\"".$img."\" alt=\"".$img."\" /></span></a>\r"; echo "<div id=\"$namess\" align=\"center\" style='display: none; position: absolute; margin: auto; margin-left: auto; margin-right: auto; border: solid black 1px; padding: 10px; background-color: rgb(255,255,225); text-align: justify; color:#000000; font-size: 12px; '>\r"; echo "This is a CSS Popup that can be positioned anywhere you want on the page and can contain any test and images you want.\r"; echo "<img src=\"http://test.com/Art/".$imgdir."".$img."\" width=\"50\" border=\"0\" title=\"".$img."\" alt=\"".$img."\" />"; echo "<br />\r"; echo "<div style='text-align: right;'><a onmouseover='this.style.cursor=\"pointer\" ' style='font-size: 12px;' onfocus='this.blur();' onclick=\"document.getElementById('$namess').style.display = 'none' \" ><span style=\"text-decoration: underline; color:#000000;\">Close</span></a></div>\r"; echo "</div>\r"; Can somebody help me ? I was wondering how I could center a CSS div so I would have one column going thorugh the middle. I tryed using "center" in the CSS but that didn't work and then I read some where else about floats and how they will make every go to either the left or right. How would I go about centering a Div like that? Thankyou for any help. Hi, i am new to CSS and want to know about how to center a div tag for example i have the following code Code: <div style=""> </div> if i want to place this div in the middle of the browser window that is from equal distance from left right top bottom what will i have to put inside the style attributes. Please recommend Regards ltoso Hi there, I am trying to center a div within a div. The container div needs to stretch 100% width. It works in FF, but not IE. Any ideas? This is my code: PHP Code: #top_bar{ background-image: url('img/top_bar.jpg'); height: 54px; font-family: arial; font-size: 14px; color: #ffffff; width: 100%; } #top_bar_content{ padding: 18px 0 10px 0px; width: 870px; margin: 0 auto; position: relative; } Now while I did manage to work this out with margins and paddings, I have to ask how to do it properly. It's very basic. You have blank page. No wrappers no nothing. Then 1 div, holds, 1 ul, with 20 li. The div has specified width. How to center the ul inside the div? I need the UL to NOT have specified width since I'll be adding more items to it over time. Thanks! How can I, let's see how to say this. Align text to the middle of a div (up and down)... not really a center Normal: ________________________________ Text ________________________________ After: ________________________________ text ________________________________ THANKS Hi, This is my first css only layout and I am trying to centre the navigation. But it wont. Any suggestions? http://www.wnv2.com/v9.htm <<link here CSS File: Code: /* CSS Document */ body { background-image:url(bg.jpg); background-repeat: repeat-x; background-color:#65B240; margin:0; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; } /*---------- Divs ------------*/ #wrapper { margin: 0px; padding: 0px; width: 600px; } #header { margin: 0px; padding: 0px; width: 600px; height: 85px; background-image:url(top.jpg); } #navigation { margin: auto; padding-left: 30px; padding-right: 30px; padding-top: 0px; padding-bottom: 0px; width: 540px; height: 25px; text-align:center; } #navigation ul { margin: 0px; padding: 0px; list-style-type: none; background-color:#DDDDDD; } #navigation ul { display: block; float:left; } #navigation li, #navigation li a { color:#59933E; font-weight:bold; letter-spacing:1px; height: 25px; display: block; margin: 0 2 0 2; float:left; } #navigation .left_nav { width: 22px; height: 25px; display: block; background-image:url(nav_left.jpg); } #navigation .right_nav { width: 22px; height: 25px; display: block; background-image:url(nav_right.jpg); } #middle{ background-image:url(middle.jpg); background-repeat: repeat-y; width:600px; } #navigation .spacer { width: 5px; height: 5px; display: block; background-image:url(nav_spacer.gif); } #contentswrapper { margin: 0px; padding: 5 55 5 55; text-align: left; width: 490px; } #bottom { height:90px; width:600px; background-image:url(bottom.jpg); } HTML: View Cource Thanks Hey guys, I'm having trouble centering div boxes on my page, wondering if anyone can help. I have tried using {margin: 0 auto;} which works fine, but when the scrollbar appears on the page it knocks it off balance and the other content on the page becomes mis-aligned. I have also tried setting left margins to push the div to the middle, but I figured this would cause problems and wouldn't look right to people using higher than 1024x768 resolutions. Is there any other way? im trying to center this div but im not to sure on how to do it Code: <style type="text/css"> div.img { margin:2px; border:1px solid #0000ff; height:auto; width:auto; float:left; text-align:center; } div.img img { display:inline; margin:3px; border:1px solid #ffffff; } div.img a:hover img { border:1px solid #0000ff; } div.desc { text-align:center; font-weight:normal; width:120px; margin:2px; } </style> </head> <body> <div class="img"> <a target="_blank" href="klematis_big.htm"> <img src="klematis_small.jpg" alt="Klematis" width="110" height="90" /> </a> <div class="desc">Add a description of the image here</div> </div> <div class="img"> <a target="_blank" href="klematis2_big.htm"> <img src="klematis2_small.jpg" alt="Klematis" width="110" height="90" /> </a> <div class="desc">Add a description of the image here</div> </div> <div class="img"> <a target="_blank" href="klematis3_big.htm"> <img src="klematis3_small.jpg" alt="Klematis" width="110" height="90" /> </a> <div class="desc">Add a description of the image here</div> </div> <div class="img"> <a target="_blank" href="klematis4_big.htm"> <img src="klematis4_small.jpg" alt="Klematis" width="110" height="90" /> </a> <div class="desc">Add a description of the image here</div> </div> Hello, I have tried to use the auto margin to center a div within a div, but the auto margin only seems to work on the outermost div. Is there a workaround where I can center my content inside of a nested div? Take the example code: Code: <html> <head> <style type="text/css"> body { background-color: orange; } #container { width: 700px; margin: 0 auto; background-color: red; } #nested { width: 700px; margin: 0 auto; background-color: blue; } </style> </head> <body> <div id="container"> <div id="nested"> Text Here </div> </div> </body> </html> So I want the nested div to have its content centered, so "Text Here" is in the center. Hey. I'm having issues with getting my page to center in IE7 using margin: auto; It works fine in firefox. The page is at http://jbench.co.uk:81/. The CSS is at http://jbench.co.uk:81/css/css.php . The section where i think the problem is: CSS Code: Original - CSS Code #page { width: 900px; margin: 0 auto; padding: 14px 3px; min-height: 250px; font-size: 1.2em; } #page { Any help's appreciated. http://www.stevemedleyphotography.com/tempo/index.html What I am trying to do is make it so that the blue background is as it is already but the orange box is the full width of the window despite what resolution or window size the user has, and also is centered on the screen. -------BLUE--------- -------BLUE--------- -------BLUE--------- -----ORANGE------- -----ORANGE------- -------BLUE--------- -------BLUE--------- -------BLUE--------- Like that. I will be having some stuff within the orange div. I don't really know much CSS at all and am kinda guessing my way through it... poorly... Thanks for any help. |