CSS - How To Make A Div With Floats Inside, Adapt To The Height Of The Heighest Float ?
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. Similar TutorialsSo I have a body div which has a left and right div(columns). I need to add 2 more divs inside the left div. But, these 2 divs have to unordered lists in them. I know my CSS is pretty average if not worse. My layout looks fine except for when I add 2 divs.. I have the float:left with %50 widths.. Screen shot of how my layout looks. img209.imageshack.us/img209/2913/idear.gif I did not add any clear tags to my css.. which I think might be what's causing the issue. Side note: In IE compatibility view the top of the page has a gap and so does the right of the page.. the logo and footer are both 100% width and the top div has a -negative margin to close the gap, it looks fine without compatibility view, and fine in firefox, and chrome. XHTML passed validation and so did CSS. This is before even messing with the columns. I didn't do anything with the unordered lists. Maybe i should ask how to correctly make my layout first.. Because what I've been doing is just adding new divs where I see fit, and then going back to edit the CSS till it works. Thanks for helping me out! BTW: what book would you recommend me getting.. I understand basics of CSS and I think I'm good with XHTML, I just need to get a better definition of CSS than w3schools has to offer. Thanks again. I have floating items inside of floating items. The problem is I cannot clear my floating items in the middle column because that ruins the other columns. How can I clear floats in the middle column? Do you have any better ideas to make my layout work? I have attached in image of how the layout should work. 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> <title>Title</title> <style type="text/css"> #content { display: block; margin: 0 5px; padding: 0 10px; border-top: 1px solid #0B4867; } .content100 { width: 100%; padding: 0px; margin: 0 .5% 0 .25%; display: inline; background: #ffeeee; } .content50 { width: 48.75%; display: block; float: left; margin: 0 .5% 0 .25%; padding: 0px; background: #eeffee; } .content33 { width: 32.25%; display: block; float: left; margin: 0 .5% 0 .25%; padding: 0px; background: #eeeeff; } </style> </head> <body> <div id="content"> <div style="margin: 0px 215px; padding: 0px; border: 0px; display: block;"> <div class="content100"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus viverra malesuada turpis. Sed iaculis justo sed turpis. Nulla malesuada turpis sed nibh. Mauris dui quam, cursus at, sollicitudin a, auctor quis, ligula. Vivamus varius blandit velit. Sed eu nibh. Vestibulum sit amet massa. Maecenas elementum massa ac ligula. In vitae massa ut dui facilisis lacinia. Maecenas tristique pede in elit. Duis ultricies aliquam metus. Mauris neque. Nunc nec lectus eu metus rhoncus imperdiet. Etiam egestas semper nunc. Nunc pretium tincidunt felis. </div> <div class="content50"> <h2>Row 1, Column 1</h2> In nec est pretium elit eleifend semper. Suspendisse potenti. Nunc bibendum sollicitudin ante. Aliquam facilisis mi quis turpis. Nullam aliquet. Sed eget urna in metus mattis luctus. Sed nunc. Maecenas est. Morbi ullamcorper eros non magna. Donec auctor, orci pretium rutrum eleifend, pede arcu pretium dui, vitae vestibulum ante odio sit amet dui. Aliquam fringilla velit sit amet magna. Proin cursus, elit quis faucibus fermentum, diam tellus rhoncus nulla, ut iaculis orci velit id metus. Pellentesque diam metus, dapibus eu, vestibulum quis, elementum id, turpis. Morbi elementum, quam non rhoncus hendrerit, metus lacus bibendum ante, vitae sodales velit est eu neque. </div> <div class="content50"> <h2>Row 1, Column 2</h2> This column is not very high. </div> <div class="content100"> Donec sed velit mollis erat consequat ornare. Donec accumsan, sapien a posuere tristique, felis turpis tristique odio, nec accumsan velit ipsum eu tellus. Duis vel felis. Maecenas in arcu nec nisi cursus consectetuer. Ut ac felis. Mauris aliquet lectus quis nisl. Aliquam quis urna quis diam facilisis imperdiet. Curabitur sit amet eros. Curabitur purus. In arcu magna, bibendum varius, elementum non, cursus eget, nulla. Etiam vulputate velit. Sed interdum leo in ligula. Sed non justo id odio bibendum tincidunt. Sed dictum, ipsum eget blandit luctus, nisi felis rhoncus nisl, sodales imperdiet neque quam id mauris. </div> <div class="content33"> <h2>Row 2 Column 1</h2> Felis turpis tristique odio, nec accumsan velit ipsum eu tellus. Duis vel felis. Maecenas in arcu nec nisi cursus consectetuer. Ut ac felis. Mauris aliquet lectus quis nisl. Aliquam quis urna quis diam facilisis imperdiet. Curabitur sit amet eros. Curabitur purus. In arcu magna, bibendum varius, elementum non, cursus eget, nulla. Etiam vulputate velit. Sed interdum leo in ligula. Sed non justo id odio bibendum tincidunt. Sed dictum, ipsum eget blandit luctus, nisi felis rhoncus nisl, sodales imperdiet neque quam id mauris. </div> <div class="content33"> <h2>Row 2 Column 2</h2> This column is not as high as the previous one. </div> <div class="content33"> <h2>Row 2 Column 3</h2> </div> <div class="content100"> Nunc vel arcu. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam luctus tellus luctus magna. Aenean tellus sapien, venenatis id, hendrerit sit amet, lacinia sed, ante. Nullam metus. Sed cursus lobortis orci. Etiam suscipit, tellus ut rutrum mollis, urna libero ultrices lectus, non hendrerit quam elit id leo. Quisque sollicitudin, mi id imperdiet sollicitudin, orci enim rutrum nibh, non adipiscing diam augue commodo nunc. Maecenas erat massa, sagittis eu, sagittis at, commodo nec, dolor. Aliquam erat volutpat. Donec nisl erat, vulputate id, dictum non, vulputate egestas, sapien. Fusce non justo eu felis imperdiet placerat. Suspendisse mattis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut ac tellus eget risus varius vehicula. In ante. </div> </div> </div> </body> </html> 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 Hi, I have an irritating issue with netscape 6.2 on the PC. I have a div that is floated left and this div contains two child divs, also flaoted left. My understanding is that the parent div should be stretched by its children and this is what happens in msie 5.5+, mozilla firefox, netscape 7 and all the decent Mac browsers. Not however NS 6.2. Does anbody know why or a way of making it behave properly? Here is my code: 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" lang="en"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <style type="text/css" media="screen"> div { border: 1px solid black; float: left; } #d1 { background: #cff; padding: 10px;} #d2 { background: #cf6; width: 200px ; height: 100px; } #d3 { background: #cf9; width: 200px ; height: 100px; } </style> </head> <body> <div id="d1"> <div id="d2">ghdfghdfghdfgh</div> <div id="d3">dfghdfhdfgh</div> </div> </body> </html> many thanks Here is the page: http://www.sdtars.com/development/o...tion/atwork.php (Note: Some pages don't work due to development) I have a class named sized and within the class there is always a img a p tag. I am trying to get the img tag to float to the left, and then have the p tag follow that up to it's right (still left aligned), with a left-margin of 10px. Every time I attempt to do that, it just forces the p tag down to the next line. Any ideas how I can get them to be inline? 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 So... 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. 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. sure i read an article on this somewhere but cant remember where, the problem is this Code: <div class="floated and cleared right"> stuff </div> <div class="fixed width" > <img class="floated left"> lots of text <div> related to my previous layout post. the problem is that the img (infact any floated element, cleared or not) falls below the right floated div! (red box in attatched gif) if i float and clear the first div left then the img is in the correct place within it but the div itseld drops below the right floated div help! Iv got my boxes sorted!!! but im quite newbie to CSS layout and stuff... so i want to put two boxes in side my container box side by side. i decided to use float... but they float outside my container box, which i suppose is what they are supposed to do. This is what im trying to achieve. Code: ---------------------------------------------------- | --------------------- --------------------- | | | | | | | | | | | | | | | Float Left | | Float right | | | | | | | | | | | | | | | --------------------- --------------------- | ---------------------------------------------------- I have been trying to find a sloution to making a float:right layer for right navigation to have a height of 100% that is nested within a container that is a position:absolute, but everything I have googled for comes up with no help (or things that don't work.) (see attached pic) Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> <html><head><title>The Shalom Foundation</title> <style type="text/css"> <!-- body { text-align:center; background-color:#666666; margin:0 0 50px 0; /* top right bottom left */ } p{ text-align:justify; font-family:Georgia, "Times New Roman", Times, serif; font-size:20px; line-height:24px; } #mainBox { position:absolute; right:12px; top:9px; padding:0px; width:733px; text-align:left; /* background-color:#999999; */ } #pageHeader{ height:202px; background:url(images/layout/header.jpg) no-repeat top left; padding:0; margin:0; text-indent:-15000px; overflow:hidden; } #nav{ position:absolute; right:546px; top:178px; margin:0; background:url(images/layout/menu.jpg) no-repeat top left; padding:0; margin:0; width:136px; height:302px; overflow:hidden; } #contentHdr{ position:absolute; top:178px; right:125px; /* background-color:#CCCCCC; */ padding:0; margin:0; text-align:right; width:400px; height:38px; overflow:hidden; } #contentTop{ position:absolute; top:220px; right:110px; background:url(images/layout/content_top.gif) top left; padding:0; margin:0; text-indent:-15000px; width:423px; height:28px; overflow:hidden; } #content{ float:right; margin:20px 17px 0 0; /* top right bottom left */ background:url(images/layout/content_bg.gif) top left; padding-left:15px; padding-right:15px; padding-top:0; padding-bottom:0; width:393px; overflow:hidden; } #rightNav{ float:right; background-color:#FFFFFF; padding:0; margin:0; width:93px; height:100%; clear:both; overflow:hidden; } #pageFooter{ float:right; background: url(images/layout/footer_matthew5_14.gif) top left; padding:0; margin:0; width:702px; height:92px; text-indent:-15000px; overflow:hidden; } --> </style> </head> <body> <div id="mainBox"> <div id="pageHeader">The Shalom Foundation</div> <div id="nav">Nav</div> <div id="contentHdr"><table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0"><tr><td valign="middle"><img src="images/layout/hdr_about_us.gif"></td></tr></table></div> <div id="rightNav"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td>rightNav please work</td></tr></table></div> <div id="contentTop"></div> <div id="content"><p>Magnus es, domine, et laudabilis valde: magna virtus tua, et sapientiae tuae non est numerus. et laudare te vult homo, aliqua portio creaturae tuae, et homo circumferens mortalitem suam, circumferens testimonium peccati sui et testimonium, quia superbis resistis: et tamen laudare te vult homo, aliqua portio creaturae tuae.tu excitas, ut laudare te delectet, quia fecisti nos ad te et inquietum est cor nostrum, donec requiescat in te. da mihi, domine, scire et intellegere, utrum sit prius invocare te an laudare te, et scire te prius sit an invocare te. sed quis te invocat nesciens te?</p></div> <div id="contentBottom"></div> <div id="pageFooter">pageFooter</div> </div> </body> </html> Is there a solution to this? Thanks in advance! Ok so either I'm tired and not thinking straight or I'm going crazy... Never had this problem before... The top wrapper has a gap below it in IE6 so it's not flush with the middle wrapper... Any ideas... See my source code below... Thanks for the help. PHP Code: <style type="text/css"> /* Structure */ /*-------------------------------------------------------------------- */ #Container { position:relative; margin:0 auto; width:920px; height:auto; min-height:100%; } #LeftSection { float:left; display:block; width:400px; height:200px; margin:0 0 0 2px; padding: 0 0 0 0; } #RightSection { float:left; display:block; width:400px; margin:0 0 0 0; padding: 0 0 0 0; height:200px; } #GreenTop { float:left; display:block; width:399px; height:30px; margin:0 0 0 0; padding: 0 0 0 0; background-color:#bdcdba; } #GreenTitle { float:left; display:block; font-family:Arial, Helvetica, sans-serif; font-size:11px; width:100px; margin:0 0 0 0; padding:0 0 0 11px; } #InnerControls { float:left; display:block; font-family:Arial, Helvetica, sans-serif; font-size:11px; width:295px; height:auto !important; min-height:100%; margin:0 0 0 0; padding:0 0 0 0; } #innerContainer { float:left; display:block; width:295px; height:auto; margin:0 0 0 7px; padding:0 0 0 0; } /* Wraps */ /*-------------------------------------------------------------------- */ #wrapTop { float:left; margin:0 0 0 0; padding:0 0 0 0; clear:both; display:block; width:908px; height:3px; background-image:url(images/topWrapper.gif); background-repeat:no-repeat; } #wrapMiddle { float:left; margin:0 0 0 0; padding:0 0 0 0; clear:both; display:block; width:908px; height:auto; background-image:url(images/middleWrapper.gif); background-repeat:repeat-y; } #wrapBottom { float:left; margin:0 0 0 0; padding:0 0 0 0; clear:both; display:block; width:908px; height:3px; background-image:url(images/bottomWrapper.gif); background-repeat:no-repeat; } #wrapInnerTop { float:left; display:block; width:295px; height:3px; margin:0 0 0 0; padding:0 0 0 0; background-image:url(images/innerTopWrapper.gif); background-repeat:no-repeat; } #wrapInnerMiddle { float:left; display:block; width:295px; height:auto; margin:0 0 0 0; padding:0 0 0 0; background-image:url(images/innerMiddleWrapper.gif); background-repeat:repeat-y; } #wrapInnerBottom { float:left; display:block; width:295px; height:3px; margin:0 0 0 0; padding:0 0 0 0; background-image:url(images/innerBottomWrapper.gif); background-repeat:no-repeat; } </style> <div id="Container"> <div id="wrapTop"></div> <!--// Start Auto-Middle Wrapper //--> <div id="wrapMiddle"> <div id="LeftSection"> <div id="GreenTop"> <div id="GreenTitle"><strong>Branch:</strong></div> </div> <div id="InnerControls"> <div id="wrapInnerTop"></div> <div id="wrapInnerMiddle"> <div id="innerContainer">TEST<br /> TEST<br /></div> </div> <div id="wrapInnerBottom"></div> </div> </div> <div id="RightSection"></div> </div> <!--// End Auto-Middle Wrapper //--> <div id="wrapBottom"></div> </div> Hello guys, I know this is asked several time, but this case is different and can't find a working solution. I'm creating a navbar using ul lists with items as images, and want to center it. I'm using the blueprint css framework, and the list items contains images instead of text. Here's the HTML code : Code: <body> <div class="container"> <div id="header" class="span-24"> <div id="header_wrapper"> <ul> <li><img src="images/nav_03.png" /></li> <li class="selected"><a href="#"><img src="images/nav_04.png" /></a></li> <li><a href="#"><img src="images/nav_05.png" /></a></li> <li><a href="#"><img src="images/nav_06.png" /></a></li> <li><a href="#"><img src="images/nav_07.png" /></a></li> <li><img src="images/nav_08.png" /></li> </ul> </div> </div><!--End Header--> </div> </body> Here's the CSS code : Code: #header{ padding-top:53px; border:#F00 solid 1px } #header_wrapper ul { text-align: center; } #header_wrapper ul li { display: inline; } I tried many code configurations but can't get it to work! a live preview is available here I'm new to css web design and am attempting my first full layout. What I would like to do is have a hanging picture in the upper-righthand corner of the page that overlaps the header and content sections. All is well, until I specify a width or height on the content section. Although it looks fine in Firefox, IE either: a) moves the content section down or b) squishes the content to the side (if <!--<?xml version="1.0" encoding="utf-8"?>--> is in the html) Here's some much-simplified code to illustrate the problem: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 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> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <link href="images/style_test.css" rel="stylesheet" type="text/css" /> <title>Sandbox</title> </head> <style type="text/css"> #header { background-color: #cccccc; border: 1px solid #564b47; } #content { background-color: #c6dedf; border: 1px solid #564b47; width: 100%; height: 400px; } #hanging { float: right; background-color: #ccff99; border: 1px solid #564b47; margin: 20px; padding: 0; width: 300px; height: 300px; clear: right; } #footer { background-color: #cccccc; border: 1px solid #564b47; clear: both; } </style> <body> <div id="hanging"><code>#hanging {<br> float: right;<br> background-color: #ccff99;<br> border: 1px solid #564b47;<br> margin: 20px;<br> padding: 0;<br> width: 300px;<br> height: 300px;<br> clear: right;<br> }</code><p>This SHOULD overlap header & content.</p></div> <div id="header"><code>#header {<br> background-color: #cccccc;<br> border: 1px solid #564b47;<br> }</code></div> <div id="content"><code>#content {<br> background-color: #c6dedf;<br> border: 1px solid #564b47;<br> width: 100%; /* hanging doesn't like this */<br> height: 400px; /* or this in IE*/<br> }</code></div> <div id="footer"><code>#footer {<br> background-color: #cccccc;<br> border: 1px solid #564b47;<br> clear: both; }</code></div> </body> </html> Anyone know a work-around or how to fix this? Thanks! I have a container containing two other divs. One is to be a left floating menu, and the other is to be a right floating content area. However, when I place these divs in a container that contains a background, the container won't expand as information is placed in the menu or the content area. My code looks like this. HTML: Code: <div class="blog-container"> <div class="blog-menu"> Some Random Menu </div> <div class="blog-content"> Some Random Content </div> </div> CSS: Code: .blog-container { position: relative; text-align: center; padding-top:15px; width: 925px; background-color: #eeeeee; } .blog-menu { float: left; width: 120px; border: 1px solid blue; } .blog-content { float: right; width: 150px; border: 1px solid red; } I really have no idea why it's doing this. Any help would be greatly appreciated. Hey all... I'm doing some testing in Firefox, and I've encountered a problem. Code: <div style="background-color: #FF9801; height: 33px; width: 99px; text-align: center; display: inline; padding-top: 8px;">Help</div> My intention here is to create a box that is 99px high, 33px wide, and with the text in the middle. In IE6, this appears to be fine. However, when testing it out in FF, I don't get the spacing that I want. Here's the kicker: When I add the float element, (float: left), it comes out the way I want it to. But it does seem to add a bit of whitespace above and to the left of it. I don't want the whitespace! Can anyone help with a compromise that will work in both browsers? My CSS usage has been pretty light until up to this issue. Thanks in advance! Hey there! First off, take a look he http://apollomix.com As you can see, I have that little chat box on the sidebar. However, for the life of me, I can't figure out how to make it 100% tall! I've tried giving the main content div a height of 100%, the body a height of 100%... everything. It just won't go! What gives? Based on what I read, the parent DIV should be 100% tall, and it should work. I guess not. Any help would be really, really appreciated! Thanks! How do I make a div go to 100% height cross browser? I have a layout like this: ----------HEADER------------- NAVHOLDER | NAV(div inside holder) | NAV(div inside holder) | | | | ----------FOOTER------------- cheers. Hi I've got 4 divs that are of the exact same size. I need them to all occupy the same real estate on a page. three of them will always be hidden and only one is visible at a time, this is controled by javascript. My question is what kind of positioning tricks do I have to do in order to make these 4 identical sized divs occupy the same space. I tried relative positioning like this div1{ position:relative; top:0; left:0; height:200px;} div2{ position:relative; top:-200; left:0;height:200px;} div3{ position:relative; top:-400; left:0;height:200px;} div4{ position:relative; top:-600; left:0;height:200px;} This only moved the contents of each div up to the desired location, however, it did not move the actual div itself, so I'm left with the reserved 600px high worth of empty space Please help Hi, I have 3 div boxes in a container, they sit side by side (i.e. 3 in a row) with different amounts of text in each div. The dilemma is that I need all the div's to be the same height as the tallest div. can someone tell me how to do this? thanks |