lonewolf217 Posted August 26, 2008 Share Posted August 26, 2008 I am very new to CSS and trying to learn my way around. I have a simple layout of a banner and 3 columns under it but I cannot figure out a couple things. Here is my CSS #banner { height: 50px; border: 1px solid #000; background:#fff; z-index:-1; } #leftcontent { position: absolute; left:10px; top: 50px; width:200px; background:#fff; border: 1px solid #000; } #centercontent { top: 50px; background:#fff; margin-left: 199px; margin-right: 199px; border: 1px solid #000; } #rightcontent { position: fixed; right: 10px; top: 50px; width: 200px; background: #fff; border: 1px solid #000; } and my simple page <html> <head> <link rel="stylesheet" type="text/css" href="format.css" /> </head> <body> <div id="banner">Text</div> <div id="leftcontent">Text</div> <div id="centercontent"> Text </div> <div id="rightcontent">Text</div> </body> </html> 2 things I cannot figure out: 1) #leftcontent and #rightcontent are floating above the banner. the banner height is 50px and the top margin on the left and right is 50px, so I cannot figure out why they are overlapping 2) the #centercontent is properly aligned with the banner, however it seems their borders are "merged" creating a doublethick line. How do I clean this up? Quote Link to comment https://forums.phpfreaks.com/topic/121400-solved-new-to-css-question-regarding-positioning/ Share on other sites More sharing options...
TheFilmGod Posted August 26, 2008 Share Posted August 26, 2008 I was bored so I coded the whole thing for you. The problem with your code was the use of absolute positioning. It is a no-no. Feel free to use/modify the attached code I provided. If you choose not to use it, at least look at the underlying code to see how I did it without using absolute positioning. I will send the bill in the mail. hehe. (just kidding). NOTE: The formating of the whitespace got screwed up when I copied and pasted. Sorry. HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> @import url("test.css"); </style> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Title of Page</title> </head> <body> <!-- Html Page Div --> <div id="html_page"> <!-- Header --> <div id="header"> <div class="banner"> <p>Banner</p> </div> </div> <!-- Body --> <div id="body"> <div class="left_column"> <p>Left Column</p> </div> <div class="main_column"> <p>Main Column</p> </div> <div class="right_column"> <p>Right Column</p> </div> </div> <!-- Footer --> <div id="footer"> <p>Copyright 2008 Greg Solak</p> </div> </div> <!-- End of Html Page Div --> </body> </html> test.css /* Css for the Homepage - Copyright ProfileTwist.com */ body{margin: 10px auto 30px 0; font-family: Arial, Helvetica, sans-serif; font-size: 12px;} a {text-decoration: none;} a:hover {text-decoration: underline;} * {margin: 0;padding:0} /* Layout Div */ #html_page {margin: auto; width: 1000px;} .clear {clear: both; height: 0px;} #html_page { width: 1000px; border: 1px solid #000; } #header .banner { height: 50px; border: 2px solid #ccc; } #body .left_column { width: 200px; float: left; background: #ababab; height: 500px; } #body .main_column { width: 600px; float: left; background: #efefef; height: 500px; } #body .right_column { width: 200px; float: left; background: #ababab; height: 500px; } #footer { padding: 15px 0 5px 0; text-align: center; font-weight: bold; } Quote Link to comment https://forums.phpfreaks.com/topic/121400-solved-new-to-css-question-regarding-positioning/#findComment-625941 Share on other sites More sharing options...
lonewolf217 Posted August 26, 2008 Author Share Posted August 26, 2008 I am trying to get it so that the left and right columns are fixed at 200px and the center column auto-sizes in between. I dont think this will handle that condition #body .main_column { width: 600px; float: left; background: #efefef; height: 500px; } since you have a fixed width for the main column Quote Link to comment https://forums.phpfreaks.com/topic/121400-solved-new-to-css-question-regarding-positioning/#findComment-625943 Share on other sites More sharing options...
TheFilmGod Posted August 26, 2008 Share Posted August 26, 2008 Sorry about that! Here's the revised code: html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> @import url("test.css"); </style> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Title of Page</title> </head> <body> <!-- Html Page Div --> <div id="html_page"> <!-- Header --> <div id="header"> <div class="banner"> <p>Banner</p> </div> </div> <!-- Body --> <div id="body"> <div class="left_column"> <p>Left Column</p> </div> <div class="right_column"> <p>Right Column</p> </div> <div class="main_column"> <p>Main Column</p> </div> </div> <!-- Footer --> <div id="footer"> <p>Copyright 2008 Greg Solak</p> </div> </div> <!-- End of Html Page Div --> </body> </html> test.css /* Css for the Homepage - Copyright ProfileTwist.com */ body{margin: 10px auto 30px 0; font-family: Arial, Helvetica, sans-serif; font-size: 12px;} a {text-decoration: none;} a:hover {text-decoration: underline;} * {margin: 0;padding:0} /* Layout Div */ #html_page {margin: auto; width: 90%; } .clear {clear: both; height: 0px;} #html_page { border: 1px solid #000; } #header .banner { height: 50px; border: 2px solid #ccc; } #body { } #body .left_column { width: 200px; float: left; background: #ababab; } #body .main_column { margin: 0 200px 0 200px; background: #efefef; } #body .right_column { width: 200px; float: right; background: #ababab; } #footer { padding: 15px 0 5px 0; text-align: center; font-weight: bold; } Quote Link to comment https://forums.phpfreaks.com/topic/121400-solved-new-to-css-question-regarding-positioning/#findComment-625970 Share on other sites More sharing options...
lonewolf217 Posted August 26, 2008 Author Share Posted August 26, 2008 thanks, this will get me started Quote Link to comment https://forums.phpfreaks.com/topic/121400-solved-new-to-css-question-regarding-positioning/#findComment-625983 Share on other sites More sharing options...
lonewolf217 Posted August 26, 2008 Author Share Posted August 26, 2008 it is behaving wierd in firefox. when I add content to the left and right columns, it will overflow onto the footer. if i add content to the middle column it will push the footer down. but it seems to work properly in IE .. go figure ? How would I get it so that the footer would align itself after the entire Body div ends ? Quote Link to comment https://forums.phpfreaks.com/topic/121400-solved-new-to-css-question-regarding-positioning/#findComment-626011 Share on other sites More sharing options...
TheFilmGod Posted August 26, 2008 Share Posted August 26, 2008 you need to clear the floated divs. Add "<div class="clear"></div>" after the three main column divs. This should fix the issue. Some other css gurus might come on and yell at me for using this clearing method. If you are interested to do it the "better" way search clearfix on google. I use the old fashion clearing way as it's consistent and enables me to clear everything from divs to images... - Hope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/121400-solved-new-to-css-question-regarding-positioning/#findComment-626114 Share on other sites More sharing options...
lonewolf217 Posted August 26, 2008 Author Share Posted August 26, 2008 thanks, that'll work just fine Quote Link to comment https://forums.phpfreaks.com/topic/121400-solved-new-to-css-question-regarding-positioning/#findComment-626135 Share on other sites More sharing options...
bronzemonkey Posted August 26, 2008 Share Posted August 26, 2008 Some other css gurus might come on and yell at me for using this clearing method. If you are interested to do it the "better" way search clearfix on google. I use the old fashion clearing way as it's consistent and enables me to clear everything from divs to images... The better clearing methods not only do all that, but avoid you having to go into the markup to clear. Quote Link to comment https://forums.phpfreaks.com/topic/121400-solved-new-to-css-question-regarding-positioning/#findComment-626426 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.