CSS - Problem With Floats; Get Both Divs At Maximum Height
Hello, not sure I know how to explain this. I have a page that I want to divide in two parts. To do so I am using floats. The problem is that the content in one div is not the same as the content in the other div and therefore the height of the two floated div is different from one another.
However, I want that the div's have a border that seperates them and I would like this border to be from top to bottom of the containing div regardless of which of the two floated div is the highest. I could do this with javascript but I would like to know if there is some pure html/css option. Here is my example; Code: <html> <head> <style> .main { margin: 0px auto; width: 800px; border: 2px solid red; } .wrap:after{ content: "."; display: block; position:relative; height: 0; clear: both; visibility: hidden; } .wrap{ display: inline-block; } /* Hides from IE-mac \*/ * html .wrap{height: 1%;} div.wrap{display: block;} /* End hide from IE-mac */ .left { float: left; width: 100px; } .right { float: left; width: 680px; border: 10px solid blue; } </style> </head> <body> <div class="main"> <div class="wrap"> <div class="left">My left div has more.<br/>more..<br /><br />more...<br /><br /><br />lines then the right one</div> <div class="right">My Right div has only one line but need border till down there ...</div> </div> </div> </body> </html> As you can see in the example the border of the right div does not go down till the bottom border of the main div. Similar TutorialsSo... I've got a page I'm working on where I can't seem to get to floats to clear without compromising the layout of the divs that are floating. http://www1.romenews-tribune.com/multimedia2/ http://www1.romenews-tribune.com/multimedia2/style.css If I try the clear:after class fix, it doesn't work. If I try the overflow: hidden fix, it looks fine until the page is resized - and the overflowing content is hidden. What I want is for the right and left div is to stretch to the bottom of the page regardless of the page height, and clear to the div they are floating in. Any suggestions? Let me know if I need to provide better examples or more info, as I'm stumped on this one and feel like I've been doing this for far too long. Dear CSS gurus, I have a problem that I have been wondering about for quite some time. I'm sure you have heard this one before, of which I apologise. The only thing I can find when searching for a solution to this is some JavaScript code. Ideally I would like to stay clear of JavaScript for this problem, as it would require script for every element within the site (a lot) which is a maintenance nightmare. Basically from the short and sweet example below, I would like div with id "test2" to expand to fill the height of the containing div, i.e. 100% - 25px. I have defined "test1" with a fixed pixel height and wish it to remain like that but have "test2" expand fully and resize whenever the browser window resizes. PHP Code: <html> <head> <style type="text/css"> .test_container { width: 100%; height: 50%; border: 1px solid red; } .test1 { width: 100%; height: 25px; background-color: grey; } .test2 { width: 100%; height: 100%; background-color: lightgrey; } </style> </head> <body> <div class="test_container"> <div class="test1"> test1 </div> <div class="test2"> test2 </div> </div> </body> </html> Any help would be much appreciated. Thanks. I'm having some issues with my images showing up properly in IE6. They look fine in Safari & Firefox. Basically there is a container div and then individual divs that display an album cover along with a description. In IE6, the images aren't in the divs, but are at the top. Anyone know what the fix is? #container { padding: 0px; margin-top: 10px; margin-bottom: 20px; margin-right: auto; margin-left: auto; background: #333; border: 0px; text-align:center; width: 635px; } #center { padding: 10px; margin-top: 10px; margin-bottom: 0px; margin-right: auto; margin-left: auto; background: #666; border: 2px solid #000000; text-align:left; width: 610px; } #container p.album-cover { float:left; padding:0; margin-top: 0px; margin-bottom: 0px; margin-right: 10px; margin-left: 0px; } #container .album-info { ... just font properties; } Code: <?php loop through albums to display each one; ?> <div id="center"> <p class="album-cover"> <?php <a href="..."><img src="..." ></a> ?> </p> <p class="album-info"> <?php ..description... ?> </p> </div> ?> I thought I'd got this CSS stuff figured out but now I'm stuck again. I want the last div on this page to be alongside the one above it, but can I get the b****** thing to go there? No! Link I just want them side-by-side with a nice centered gap between them. Can you help? Thanks, John. I swear that I really am learning a great deal about CSS but you wouldn't think so as many threads as I've started in the past few days... Anyhow, consider the following code: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>My site</title> <style type="text/css"> #base { clear: both; padding-top: 1px; border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; width: 100%; background: #00ff00; } /* end #base */ #main { background: #0000ff; margin: auto; text-align: left; width: 800px; } /* end #main*/ #content { background: #ffffff; border-left: 1px solid #0000ff; padding-top: 1em; padding-bottom: 1em; border-right: 1px solid #0000ff; } /* end #content */ #bottom_part { padding: 0; line-height: 130%; padding-left: 1em; padding-right: 1em; display: block; margin: 0; border: 0; clear: both; } /* end #bottom_part */ #column_a { padding: 1em; margin: 0; float: left; width: 33%; } /* end #column_a */ #column_b { margin-left: 33%; margin-right: 33%; padding: 1em; padding-right: 0; width: 25%; } /* end #column_b */ #column_c { display: block; float: right; padding: 1em; width: 33%; } /* end #column_c */ #bottom { background: #ff0000; border: none; } /* end #bottom */ .header { font-weight: bold; } </style> </head> <body> <div id="base"> <div id="main"> <div id="content"> <div id="bottom_part"> <div id="column_a"> <p class="header">Column A</p> <p>A - A</p> <p>A - B</p> <p>A - C</p> </div> <div id="column_c"> <p class="header">Column C</p> <p>C - A</p> <p>C - B</p> <p>C - C</p> <p>C - D</p> <p>C - E</p> <p>C - F</p> </div> <div id="column_b"> <p class="header">Column B</p> <p>B - A</p> <p>B - B</p> <p>B - C</p> </div> </div> </div> <div id="bottom"> </div> </div> </div> </body> </html> The problem is that the content in Column C does not completely render inside the white box. The same problem occurs when the content is really long in Column A. Column B will extend the height of the white box and I'm certain it is because there is no float style associated with it. How can I achieve this for the other two columns? Removing the floats will do the trick but will also place the columns on top of each other. I know this problem has been seen hundreds of times when you have floated columns and you want them to be the same height so that the background graphic is continuous down to the foot of the page. Well, I've got a slight variant on that: http://216.120.243.161/~h****ins/browse2.php (if the url doesn't show above it's because the name of the site happens to contain the letters d i c and k next to each other!) I have 4 columns of floated boxes, (row number varies) and after every four boxes (they are floated to the left) there is a br that clears them, and a new row starts underneath. My database system would allow the boxes to actually be quite tall if the name was the full 255 characters. So, I don't want to set a height for them, as most would look silly. I could do a faux-columns style background, but that requires more elements. Any ideas would be greatly appreciated, but in the end, I may have to use tables (Nooooo...! ;-) ) Thanks, Watters Hi all, I'm a beginner to floating divs etc. so I've been following a tutorial to get what I need and I'm tweaking it here and there. Trouble is I've obviously tweaked something incorrectly. The two column's in the contentHoldingDiv don't line up correctly. Does anyone feel like taking a look at my code and telling me what I've done wrong (any other comments freely welcomed - it's the only way I'll learn). Here's the HTML: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Test</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <link href="style.css" rel="stylesheet" type="text/css" media="screen"/> </head> <body> <div id="holdingDiv"> <div id="topDiv"><p>You are logged in as <strong>Guest</strong></p></div> <div id="headerPicDiv">Header Pic</div> <div id="navDiv"> <ul> <li><a href="#">Option 1</a></li> <li><a href="#">Option 2</a></li> </ul> </div> <div id="contentHoldingDiv"> <div id="contentDiv"> <h2>Column 1</h2><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit...</p> </div> <div id="rightDiv"> <h3>Column 2</h3><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit...</p> </div> </div> <div id="footerDiv"> <p> Site design by <a href="mailto:Lee@LTheobald.co.uk">Lee Theobald</a> </p> </div> </div> </body> </html> And here's the CSS Code: * { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; } body { background-color: #E6E6E6; margin: 0px; padding: 0px; min-width: 760px; } #holdingDiv { background-color: #F8F8F8; margin: 20px auto; width: 760px; } #topDiv { height: 25px; background-image: url(images/gradient25.jpg); border: 1px solid #D4D4D4; } #topDiv p, #topDiv strong { line-height: 25px; text-align: right; padding-right: 5px; margin: 0px; font-size: 10px; } #headerPicDiv { height: 125px; border: 1px solid #D4D4D4; } #navDiv { height: 25px; background-image: url(images/gradient25.jpg); border: 1px solid #D4D4D4; line-height: 25px; padding: 0 5px; } #navDiv ul { margin: 0px; padding: 0px; } #navDiv li { display: inline; list-style: none; margin: 0px; padding: 0px; } #contentHoldingDiv { border: 1px solid #D4D4D4; padding: 0px; margin: 0px; clear: both; } #contentDiv { background-color: red; width: 600px; float: left; } #contentDiv p { padding: 5px 3px; margin: 0px; #rightDiv { background-color: orange; width:157px; margin-left:600px; } html>body #rightDiv { width:160px; } #footerDiv { height: 15px; background-image: url(images/gradient15.jpg); border: 1px solid #D4D4D4; } #footerDiv p, #footerDiv a { line-height: 15px; text-align: center; font-size: 9px; margin: 0px; } Cheers, Lee Hi all, This is really annoying me and I don't think it should happen!! If you see this page, you will see one of the divs spans the whole page and it has gone behine the floated left element. Now if it wnt below it that would be OK as a block level element, but the content is in the right place. If you reduce the width it sits in its place OK. I think this is strange behavior.... is it correct????? http://www.wellandpower.net/website...req=www_contact Regards Charlie I have a positioning puzzle for you. It's as part of a web design assignment, so broad accessibility is not required. even working on IE is not required. YES! here is the problem, explained by means of an image. because a picture speaks a thousand words. so they say. [IMG](URL address blocked: See forum rules)[/IMG] Any assistance or suggestions are welcome. Thanks in advance. I tried to use height:auto, and put it into the main container, then I put it in the div that is floated. Nothing works in firefox for me. Ive tried searching on google but I cant find anything that works. Basically, its not just an issue with floats, in general, what is the correct way to set divs, to auto expand to cover what is inside and that works in IE, Firefox and safari, is there a way to ? Thanks in advanced. Hi Guys, I am having a problem with floats. Here is the code I am using: Code: <!DOCTYPE html> <html> <head> </head> <body> <div style="width:900px; border: 1px black solid; float:left;"> <div style="width:400px; height:100px; border: 1px black solid; float:left; display:inline; background-color:blue;"></div> <div style="width:400px; height:300px; border: 1px black solid; float:left; display:block; background-color:green;"></div> <div style="width:400px; height:100px; border: 1px black solid; float:left;display:inline; background-color:red;"></div> </div> </body> </html> I am trying to get the red box to appear right under the blue box. I don't want to use a 2 column layout. Is this possible? Thanks! Elad I'm trying to construct a simple navigation bar that looks like the attached image. It's a simple bar with rounded corners on the ends. If I where going to use tables, I would make one row with three cells. But I hear that these days, tables for positioning are out... I'm thinking two sets of DIVs where one contained the left end, and one the right. What's confusing me is how to get the images to line up right rather than looking "stacked". I imagine it has to do with the "float" attribute, but I can't seem to find the combination that does what I need. Code: <div> <div> Nav | Bar | Content </div> </div> As well, how to make the full height of the end images show? My experiments seem to truncate the image height at the height of the text. Pointers? Thanks... I've got two columns set-up using floats. They work fine in Firefox, Opera and Konqueror on my machine, but a friend with Windows informs me that it doesn't work properly in Internet Explorer. The code is as follows: Code: div.get_content_voc_left { width: 50%; float: left; clear: both; } div.get_content_voc_right { width: 50%; float: right; clear: none; } The results in IE can be seen in this screenshot and this screenshot. Those with IE can have a look at a live copy of the HTML here and the CSS here. Any help is appreciated i have 2 divs one is a navigation bar, the other is the pages main contents. the contents and navigation links changes from page to page so i need a method so if the content is long, the navigation will stretch down long too to be the same height of the content, and the same thing vice versa. how do i go about doing this? Hi all! After trying more then a few things I'm about to give up, so I hope someone here has the answer. The problem is the following: * A website contains 3 DIV columns and an header at the top, this is all inside a single wrapper DIV which centers the webpage. * All three columns should have the same length as the longest column. * When the content in the 3 DIV columns is shorter then the height of your browser window, the DIV elements should fill-out until the bottom of the screen. Point 2 is doable. Point 3 is doable. But the combination of point 2 and 3 seems quite hard. Hope someone has an idea . Thanks! Hey everyone, I'm having troubles with some DIVs. I'm trying to divide a page into 4 equal sections. If I remove the doctype declaration, it looks right in Firefox 3.5.2 In ie it is all sorts of crazy. 100% height of the inner objects seems to be referencing the window height and not the parent elements height. I'm more concerned about Firefox anyway. I expect IE to require some hacks. If I set an absolute size to the body, in px, everything works fine. But if I have the body set to %, things shrink. I tried creating a wrapper div and setting it's height/width to 50% but that didn't work either. I tried to find a solution on kravvitz and bon rouge's sites but I didn't find anything that was 100% fluid. Any ideas? HTML4Strict Code: Original - HTML4Strict Code <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <style> body{ width:100%; height:100%; padding:0; margin:0; color:#ffffff; background-color:#000000; } object{ float:left; clear:both; width:80%; height:100%; background-color:#cccccc; } .section{ float:left; clear:none; width:48%; height:48%; margin:1%; background-color:#333333; display:block; position:relative; } .panel{ float:left; clear:none; width: 16%; height:96%; margin:2% 2%; background-color:#cccccc; } #container{ float:left; clear:both; width:100%; height:100%; min-height:100%; background } </style> </head> <body> <div id="container"> <div class="section"> <object data="http://www.google.ca"> </object> <div class="panel"> <a href="#"> test </a> </div> </div> <div class="section"> <object data="http://www.google.ca"> </object> <div class="panel"> <a href="#"> test </a> </div> </div> <div class="section"> <object data="http://www.google.ca"> </object> <div class="panel"> <a href="#"> test </a> </div> </div> <div class="section"> <object data="http://www.google.ca"> </object> <div class="panel"> <a href="#"> test </a> </div> </div> </div> </body> </html>
What I have: I have a <div id="content"> that contains the main content of the site. In this <div> I have two other <div>s that are arranged in columns, using float. The left column forms the Navigation for the site and is surrounded by a black border. Here is the problem: If the content on the right is small, the border on the left stretches from top to bottom (since the left div controls the height). However, when there is a lot of content on the right, the border on the left only surrounds the content of the left div and leaves space underneath the bottom border-line. My question: Is there a way to "stretch" the left div so the border touches the top of its parent div on top and the bottom of its parent div on the bottom? Or in other words: Can I force the left div to have the same height as the right div? Here is an example of what I have right now (before tackling the problem): CSS: Code: #content { width: 800px; margin: 0; padding: 0; } #contentNav { width: 140px; float: left; border: thin solid black; margin: 0; padding: 0; } #contentMain { width: 600px; float: right; margin: 0; padding: 0; } HTML: Code: <div id="content"> <div id="contentNav"> <a href="">Link1</a><br /> <a href="">Link2</a><br /> <a href="">Link3</a><br /> </div> <div id="contentMain"> <p>Here comes a lot of text that spans over many lines. </div> </div> Here's the template I'm working on: http://dhost.info/justusvizslas/template.php Here's my problem: I'm trying to create a centered, two-column layout with a header and a footer, sort of like the tutorial he http://nemesis1.f2o.org/aarchive?id=7 I've got everything working correctly and it looks fine in IE. However, in FireFox, the container div doesn't automatically adjust its height to be the same as the height of the divs inside. Instead, I have to set the height at a certain number of pixils to even get the container div to show up. When I do that, in IE the container div defaults to the same height as the larger of the two inner divs, but in FireFox the container div just stays at whatever pixil height I specified. That becomes problematic because I don't plan on having all my pagecontent divs with the same height. Any insight will be greatly appreciated. I've been looking at this for hours and haven't gotten it to work like it should. Here's the relevant code too: CSS Code: #container { width:792px; height:50px; margin: auto auto; color:#000000; background-color:#FFFFFF; background-image:url(design/menuimage.gif); background-repeat:repeat-y; } #navigation { width:125px; height:auto; padding:0px; float:left; margin-top:auto; vertical-align:top } #pagecontent { width:667px; height:auto; padding:0px; float:left; margin-top:auto; color:#000000; background-color:#FFFFFF; text-align:center } PHP Code: <div id="container"> <div id="navigation"><?php include "nav.php"; ?></div> <div id="pagecontent"> <br />Some more content here<br /> </div> </div> Again, thank you in advance for any help with this. If you're stumped and think it should work as-is, go ahead and go to the actual template I'm working on (first http link in this post) and look at it in IE and in FireFox to note the difference. I have a 3 column layout. Each column may contain one or two articles with a border at the bottom of each article. The There are two borders between the three columns. I'm trying to use floated divs as containers for each of the columns, with a left-hand border in the center and right columns. You can see a non-css example at: http://www.sananselmopreschool.org/pilot/ Well, no matter what I do, I haven't been able to get the column containers to extend to the bottom of the page in IE. If I set them to height:100%, they seem to shoot out to 150% or so. body { height:100%; padding:0; margin:0; background-color:#ECF6DD; font-family: Tahoma; font-size: 11px; color: #707070; text-align:center; border: 1px solid purple; } .body_container { position: relative; height:100%; width:100%; left: 0px; border: 1px groove darkred; } .body_position_center { height:100%; position:relative; width:780px; margin-right: auto; margin-left: auto; border-collapse:collapse; border: 1px solid #999 ; } .header { padding:0; margin:0; position:relative; width:766px; height:195px; } .leftblock { position: relative; height:100%; border-left:3px dotted #228B22; float:left; width:250px; } .centerblock { position: relative; height:100%; border-left:3px dotted #228B22; float:left; width:250px; } .rightblock { position: relative; height:100%; border-left:3px dotted #228B22; float:left; width:250px; } .blockcontents { padding-top:14px; padding-bottom:14px; border-bottom : 3px dotted #228B22; text-align:left; } Any suggestions would be appreciated. I haven't used much javascript, so unless I can see an example, it might be tough to work out a javascript solution. Hey guys, so I've cleaned up my code a bit. Read up on semantic coding. I think it's a bit better. Anyways, I'm trying to make my right and left content div's the same height. I've tried the faux technique, and it doesn't seem to work. Anyways, I was wondering if it's worth the 5 hours of headache to avoid using tables to setup the layout? I think it would be nice to have it in DIV's, that way if I want to switch left to right, and vice versa, it would be a breeze. Also, for the content, I'd like the left (main) side to be the remainder of the page width, and I'd like the right side to be 260px. If it works better, I wouldn't mind having the main part 77% of the width and the right side be 23%. Anyways, here's my code: html4strict Code: Original - html4strict 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>Beta</title> <style type="text/css"> <!-- @import url("layout.css"); --> </style> </head> <body> <div id="container"> <!-- Site Head --> <div id="header"> <div id="banner"></div> <div id="head_user_container"> <div id="head_avatar"><img src="img/layout/avatar_test.jpg" alt="User Avatar" /></div> <div id="head_user_info">Welcome <a href="">Mike Jensen</a> (<a href="">Sign Out</a>)<br /><a href="">Edit Profile</a><br /><a href="">Message Center</a></div> </div> </div> <!-- End Site Head --> <!-- Menu --> <div id="menu"> </div> <!-- End Menu --> <!-- Start Top Ad Banner --> <div id="top_ad"> </div> <!-- End Top Ad Banner --> <!-- Main Content Container --> <div id="content_container"> <div id="main_content"> eh... </div> <div id="right_content">right content <br />yes sir</div> </div> <!-- End Main Content Container --> </div> </body> </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> and heres my css: Code: /*Basic Elements*/ body { font-family: "trebuchet MS", calibri, verdana, arial, sans-serif; font-size: 13px; color: #303030; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; padding: 0 20px; background-color: #d8d8d8; } p { margin-top: 10px; text-align: justify; font-family: "trebuchet MS", calibri, verdana, arial, sans-serif; font-size: 13pt; line-height: 10pt; } a:link { text-decoration: underline; color: #417cb3; } a:visited { text-decoration: underline; color: #417cb3; } a:hover, a:active { text-decoration: underline; color: #5e9cd5; } acronym { font-weight: bold; border-bottom: 1px dotted #417cb3; } /*Specific DIVs*/ #container { margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding: 0px; max-width: 1204px; min-width: 950px; height: 100%; clear: both; text-align: left; position: relative; } /*- Banner -*/ #header{ background-color: #417cb3; height: 74px; width: 100%; clear: both; float: left; border-left: solid 1px #496986; border-right: solid 1px #496986; } #banner{ background-image: url(img/layout/not_yet.jpg); background-repeat: no-repeat; float: left; width: 284px; height: 74px; } /*End Banner*/ /*Head User Info*/ #head_user_container{ background-image: url(img/layout/logged_info_bg.jpg); background-repeat: repeat-x; clear: both; height: 66px; position: absolute; right: 4px; top: 4px; } #head_avatar{ background-image: url(img/layout/ban_avatar_bg.jpg); height: 66px; width: 64px; float: left; background-repeat: no-repeat; padding-top: 1px; padding-left: 1px; } #head_user_info { background-image: url(img/layout/logged_info_end.jpg); background-position: right 0; background-repeat: no-repeat; min-width: 225px; max-width: 500px; float: left; height: 66px; margin-left: -1px; font-family: "trebuchet MS", calibri, verdana, arial, sans-serif; font-size: 13px; color: #FFFFFF; padding-top: 4px; padding-right: 3px; padding-bottom: 0px; padding-left: 5px; } #head_user_info a:link { text-decoration: none; color: #5dbdfa; } #head_user_info a:visited { text-decoration: none; color: #5dbdfa; } #head_user_info a:hover, a:active { text-decoration: none; color: #7fc9f8; } #head_user_end { float: left; background-image: url(img/layout/logged_info_end.jpg); background-repeat: no-repeat; height: 66px; width: 3px; } /*End Head User Info*/ /*Menu*/ #menu{ background-color: #417cb3; background-image: url(img/layout/menu_bg.jpg); background-repeat: repeat-x; height: 34px; width: 100%; clear: both; border-left: solid 1px #94aec5; border-right: solid 1px #94aec5; } /*End Menu*/ /* Top Ad Banner*/ #top_ad{ background-color: #ededed; height: 109px; width: 100%; clear: both; border-left: solid 1px #94aec5; border-right: solid 1px #94aec5; } /*End Top Ad Banner*/ /* Main Content */ #content_container{ width: 100%; overflow: hidden; clear: both; border-left: solid 1px #94aec5; border-right: solid 1px #94aec5; } #main_content{ background-color: #fff; clear: both; margin-right: 260px; } #right_content{ width: 260px; background-color: #ffead1; position: absolute; right: -1px; top: 217px; } /* End Main Content */ Here's the site, and what it looks like right now: http://24.16.238.252/sd_beta/working/layout2/ Anyways, thanks for all your help guys! If you need more info, let me know! |