CSS - Three Divs Stacked Vertically Want Middle To Expand
Is there a way to get the #middle div to stretch vertically to fill up the remaining space of the page, say with min-height etc.?
Thanks, Mark 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=iso-8859-1" /> <title>Untitled Document</title> <style type="text/css"> html,body{ min-height:100%; height: 100%; } html{ border: 1px solid red; } body{ border: 1px solid blue; } #container{ border: 1px solid green; } #top{ border: 1px solid yellow; } #middle{ border: 1px solid black; min-height: 100%; height: auto; } #bottom{ border: 1px solid grey; } </style> </head> <body> <div id="container"> <div id="top"> </div> <div id="middle"> </div> <div id="bottom"> </div> </div> </body> </html> Similar TutorialsHi guys! Just wondering if this is an easy fix, otherwise I'll just switch the layout to a table. HTML: Code: <div id="box"> <div id="left"> <h1>MENU left</h1> <p>Content on the left.</p> </div> <div id="content"> <p> content... </p> </div> <div id="right"> <p>content...</p> </div> </div> CSS: Code: #box { width:750px; margin: 0px auto; padding:0px; border:1px; } #content { width:400px; padding:0px; float:left; overflow: auto; } #left { width:173px; padding:0px; float:left; background-color: #223344; border-color:white; } #right { width:173px; padding:0px; float:left; background-color: #223344; border-color:white; } I want all three columns to expand vertically to the size of the largest column. As of right now it's set up using CSS and I would prefer to keep it that way, but if switching the layout to tables would be much easier, I would be happy to do that too. Thanks for the help in advance! I couldn't really figure out what keywords to be searching for... I am more than happy to read a previous post if anyone could direct me. Here's my problem: Attempting to layout a page using divs and no tables. I have a stylized left-side border that I have to use, and I would like it to stretch. It a symmetrical drawing, so I cut it in half in Photoshop, and then saved a 1 pixel slice from the center as a third picture. (So I now have 3 images: one for the top, middle, and bottom) The Top and Bottom images should stay the same height, and the Middle image will be repeated to make the border stretch with the window. My div layout is as follows: <div id="divTopLeft" style="top:0em;left:0em;position:absolute;display:block;background-image:url('images/bg_TopLeft.gif');background-repeat:no-repeat;height:300px;width:151px;z-index:0;"> </div> <div id="divMiddleLeft" style="top:300px;bottom:300px;left:0em;position:absolute;background-image:url('images/bg_MiddleLeft.gif');background-repeat:repeat-y;width:151px;z-index:0;"> </div> <div id="divBottomLeft" style="bottom:0em;position:absolute;left:0em;vertical-align:bottom;display:block;background-image:url('images/bg_BottomLeft.gif');background-repeat:no-repeat;height:300px;width:151px;z-index:0;"> </div> This works great as long as the window is at least 600 pixels high. If the window becomes shorter than that, "divBottomLeft" overlaps "divTopLeft" (and maybe Middle as well, but I can't tell). I thought that specifying the same z-index would make them run into each other instead of overlapping, but no such luck. Can anyone help? Thank you! -jim Hi there. A very frustrating problem and so simple a situation . I have two divs, one stacked on top of the other. Nothing special with positioning or anything. Total barebones stuff. If I put an image (whether with image tag or as background-image) in the top div, the div will be padded on the bottom. This only happens in IE. As an example I have my page he URL The top div bgcolor is lime green, and you'll see it adds some extra space under the image. Compare in IE & FireFox and you'll see what I mean - green can be seen under the image in IE. The bottom of the image in the top div should be butted up against the top of the second div, whose bgcolor is red. No green should exist between the image and red. Thanks for any help, this should be rediculously simple for someone who knows CSS quirks well. page passed validation - xhtml 1.0 @ w3c.org What I'm wanting is for the links to be in the middle of the div vertically. Currently it's at the top. I've tried using vertical-align but that doesn't work. What am I missing here? asp.net firefox 3.6.11 CSS Code: #headercont { width:auto; height:100px; text-align:center; background-image:url('images/headbg.png'); } #connav { vertical-align:middle; } #connav ul { position:relative; list-style-type:none; list-style-image:none; } #connav li { display:inline; } #connav ul li a { text-decoration:none; margin: 4px; padding: 5px 20px 5px 20px; color:#ccff00; background-color:#61a003; } HTML (inside the body tags) Code: <div id="headercont"> <div id="connav"> <ul > <li><a href="#">Link</a></li> <li><a href="#">Link</a></li> <li><a href="#">Link</a></li> </ul> </div> </div> I'm trying to make a box (graphic) that will expand vertically as more content is added. I've made my border with flourishes and shadows, so a purely CSS box design isn't an option... Here's an exploded view of what I'm looking to do: ________________ |.........................| |.........................| |.........................| Top section that is static |.........................| |.........................| |.........................| Middle section with vertically |.........................| repeatable graphic |________________| Bottom section that closes it off Here's my code so far... Code: <div id="container" style="width:956px; margin:0px auto -1px auto;"> <div id="topedge" style="background-image:url(images/topedge.png); width:850px; height:15px;position:relative; left:53px;"></div> <div id="leftcolumn" style="background-image:url(images/leftedge.png); float: left; width: 79px; height: 641px;"></div> <div id="rightcolumn" style="background-image:url(images/rightedge.png); float: right; width: 79px; height: 641px;"></div> <div id="content" style="background:#000000; float: left; width: 797px; height:800px;">THIS IS THE CONTENT AREA</div> </div> </div> This code only makes the top half of the design, I can't seem to make the middle and bottom parts work. I'd appreciate any suggestions. Thanks. ok. Ive been trying to use CSS to style my page instead of tables. but I cant get stuff to line up right. basically I have a div spanning the whole width of a css box. inside that div I have 3 sections, one for left-aligned text, one for center aligned text and one for right aligned text. what I want is to display on the far left a left arrow image (for use as a button) and the word 'Previous'. then in the middle of the div, center aligned, I want to display the words 'select a different draw' and on the right hand side, right aligned I want the word 'Next' followed by my right arrow. EASY PEASY I thought. Well it has taken me an hour to realise that I have to set my parent element to position: relative for the left middle and right elements to use absolute without going to the very top of the page. so at least I now have them along in a line. What I have found is that the the text on the left and right is vertically aligned to the BOTTOM edge of the image and the text in the middle has been vertically aligned to the TOP of the image despite all 4 css classes being defined as vertical-align: middle; please tell me where I am going wrong, I'm loosing my marbles here! --html: Code: <div id="width-100"> <div id="third-left"> <img src="images/arrowleft.png" alt="foo"/> Previous </div> <div id="third-middle"> Select a different draw </div> <div id="third-right"> Next <img src="images/arrowright.png" alt="foo"/> </div> </div> --css: Code: #third-left { width: 30%; text-align: left; vertical-align: middle; } #third-middle { position: absolute; top: 0px; margin: 0 35% 0 35%; width: 30%; vertical-align: middle; text-align: center; } #third-right { position: absolute; top: 0px; right: 0px; width: 30%; text-align: right; vertical-align: middle; } #width-100 { width: 100%; position: relative; vertical-align: middle; background: white; } any thoughts? Thanks, Ben How could I Force a parent div to vertically expand to size of its child div? Thanks in advance, Richard Carson I should preface this by stating that I'm hopelessly bad at CSS! I have a bit of ajax-enabled html like this: Code: <div class="demo"> <div class="demo-description"> <p>Vault</p> </div> <ul id="sortable1" class="connectedSortable"> <li id="entry_1" class="ui-state-default ui-state-disabled"><img src = "img/1.jpg"></li> </ul> <div class="demo-description"> <p>Gallery One</p> </div> <ul id="sortable2" class="connectedSortable"> <li id="entry_4" class="ui-state-default"><img src = "img/4.jpg"></li> <li id="entry_2" class="ui-state-default"><img src = "img/2.jpg"></li> </ul> <div class="demo-description"> <p>Gallery Two</p> </div> <ul id="sortable3" class="connectedSortable"> <li id="entry_3" class="ui-state-default"><img src = "img/3.jpg"></li> <li id="entry_5" class="ui-state-default"><img src = "img/5.jpg"></li> </ul> </div><!-- End demo --> I want to format it such that while images [<li></li>] within galleries [<ul></ul>] appear side by side, the actual galleries appear one below the other. Just can't seem to figure it out. Edit: Nevermind. As soon as I posted, I discovered what I needed was "overflow: auto;" Isn't it always the way. Hi, what I'm trying to do is get two divs next to each other. That much I can do if I give them both a style of 'float:left;', but the problem with that is that they will overflow out of the div that they both sit in. Is there anyway to get two divs to sit next to each other, but to also expand the parent div if necessary? Thanks! Hi guys, I am trying to display two forms with several elements on a page. I would like to place the two forms on the webpage so that one is displayed on the left and the other on the right of the screen. Something like this URL http://craigbaldwin.com/blog/wp-content/uploads/2008/12/52.jpg I have written the following test and the forms are placed correctly inside the left and right divs. Code: <HTML> <Head> <style type="text/css"> div.wrapper { position: relative; clear: both; width: 100%; border : 1px solid #000000; } div.left { float: left; width: 50%; background: #ffffff; border : 1px solid #000006; } div.right { float: right; width: 50%; background: #ffffff; border : 1px solid #000001; } </style> </Head> <Body> <div class="wrapper">Wrapper <div class="left">Left Box Left Box Left Box Left Box Left Box Left Box Left Box Left Box Left Box Left Box Left Box Left Box Left Box Left Box Left Box </div> <div class="right">Right Box Right Box Right Box Right Box Right Box Right Box Right Box Right Box Right Box Right Box Right Box Right Box Right Box Right Box </div> </div> </Body> </HTML> A couple of problems with the above. 1. In Internet explorer the divs are aligned correctly but in firefox it gets all messy. 2. As long as the window is maximised then i the divs are aligned vertically correctly. If i resize the browser window then they are no longer aligned vertically. Is there a way to make them always next to each other from left to right even if the window is resized? (try resizing the window for the example i showed above) Thanks DIV blocks display incorrectly in IE8 and it's driving me insane.. I tried adjusting padding for each column amongst other things but no dice! Everything looks fine in FireFox and IE9. I'm not allowed to post links as a new user but the website is dmstriping dot com. You'll have to fix the below links yourself. Any help would be greatly appreciated! **Here are the css files:** dmstriping dot com/new site/css/style.css dmstriping dot com/new site/css/layout.css Web Site: dmstriping dot com/new site/index.html Hi, I'm new here. I wasn't sure if this was a javascript problem or a css (I'm thinking it's probably a css problem). I've been using css for about a year, all very straight forward until my friend asked me to make some changes to his site Bascially what he wanted me to do is 1. vertically center the entire site to the browser window, and 2. also vertically center the title and caption for his photogallery Below is a link to the site I'm working on Code: http://theo.mypreview.co.uk/gallery/test I added some javascript that I found searching on google which isn't working quite right. This is the javascript code Code: (function ($) { // VERTICALLY ALIGN FUNCTION $.fn.vAlign = function() { return this.each(function(i){ var ah = $(this).height(); var ph = $(this).parent().height(); var mh = (ph - ah) / 2; $(this).css('margin-top', mh); }); }; })(jQuery); If you follow the link posted to the site I'm working on you should see 3 thumbnails, 1st thumbnail is a video which is my main struggle to center vertically. The other 2 thumbnails are for images. If you click on one of the thumbnails for a picture you will see how the title and caption align vertically (not quite center)* For some reason the div containing the main image content ignores the height so the margins are too big. *Video is posted within the span class called "phototext" which is where the descriptions for the images appears. side note - this javascript seems stop IE6 and 7 from loading the page Thanks Larss Hi all, I know there are certain tricks to vertically center texts or images in a div area. And I have read somewhere there are plans to avoid current complexity compared with tables. For example, provided I use same CSS... Code: div,table{ width: 250px; height: 100px; border: 1px solid red; text-align: center; } ...we optain well vertically centered text in this table... Code: <table> <tr><td>this IS vertically centered</td></tr> </table> ...but not in this div based one... Code: <div>this IS NOT vertically centered</div> I ask, do you know an easy way to acomplish the same we get with tables? Thanks! I'm wworking on a CSS template and I'm trying to vertically align two divs.... one on top of the other with a five pixel margin between the two.... However, unless I use a bunch of HTML breaks (which will result in an uneven template), I can't figure out how to do it. I've tried to vertical-align them and etc. Any help is appreciated. Oh, I know my code could be a bit more clean, this is just a comp. I've also tested this on FF so far. I doubt IE will return favourable results either. My example: www.efacln.com/Untitled-1.html My CSS code: Code: #container { MARGIN: 5px; } #header_container { border-color: black; BORDER-STYLE: solid; BORDER-WIDTH: thin; BORDER-LEFT: none; BORDER-RIGHT: none; WIDTH: 100%; } #header_content { BORDER-COLOR: black; BORDER-STYLE: solid; BORDER-WIDTH: thin; BORDER-TOP: none; BORDER-BOTTOM: none; WIDTH: 600px; HEIGHT: 100px; MARGIN-LEFT: auto; MARGIN-RIGHT: auto; } #kirk_news { BORDER-COLOR: black; BORDER-STYLE: solid; BORDER-WIDTH: thin; WIDTH: 550px; HEIGHT: 100px; FLOAT: left; POSITION: absolute; MARGIN-TOP: 5px; MARGIN-RIGHT: 2.5px; } #navigationblock { BORDER-COLOR: black; BORDER-STYLE: solid; BORDER-WIDTH: THIN; WIDTH: 410px; POSITION: relative; FLOAT: RIGHt; MARGIN-TOP: 5px; MARGIN-LEFT: 2.5px; } #scott_news { BORDER-COLOR: black; BORDER-STYLE: solid; BORDER-WIDTH: thin; width: 410PX; MARGIN-TOP: 1 px; MARGIN-TOP: 5px; } </STYLE> I'm trying to vertically align two divs inside a table cell. I have the cell's vertical-align property set to text-top because I want the first div to be aligned at the top of the td but I can't, no matter what I try, get the second div to align to the bottom. Is there a better way to accomplish this without nesting tables or is this the right way and I'm just missing something? edit: posted this question at the end of the working day, was quit tired. basically i was having trouble vertically spacing images in a menu whilst simultaneously aligning text labels to the middle of those images... Is there a way to create a simultaneous effect of both linking and onmouseover for two different layers that are stacked in the same position? Meaning ... I have LAYER 1 which would have the "initial image" and the "hot text" that would trigger a rollover (onmouseover) effect for the "new image" to repopulate the same position but in the same or "new" div ... onmouseout, the "new image" would hide and the "initial image and "hot text" div content would reappear ... I've attempted something of what I wanted, but am still having issues. Any assistance you can provide would be greatly appreciated -- THANKS! Code: <html> <head> <title></title> <style type="text/css"> .hidden {position: absolute; visibility: hidden} #netcalltext { z-index: 1; position: absolute; top: 2px; left: 2px; } #d1 { z-index: 2; position: absolute; top: 2px; left: 2px; } </style> <script language="JavaScript"> <!-- function showIt(obj) { if (document.getElementById) {document.getElementById("d1").style.visibility = "visible";} else {if (document.layers) { document.layers[obj].visibility = "show";} else {document.all("d1").style.visibility = "visible";} } } function hideIt(obj) { if (document.getElementById) {document.getElementById("d1").style.visibility = "hidden";} else {if (document.layers) { document.layers[obj].visibility = "hide";} else {document.all("d1").style.visibility = "hidden";} } } //--> </script> </head> <body> <div id="d1" class="hidden"><img src="images/tools-on.jpg" alt="" width="194" height="280" border="0"></div> <div id="netcalltext"><a href="#" onMouseOver="showIt('d1')" onMouseOut="hideIt('d1')"><img src="images/tools-off.jpg" alt="" width="194" height="280" border="0"></a></div> </body> </html> Ok, so I've learned to stay away from tables when you don't need them, and I have an instance where this is the case. I have a container div that has a header, content and a footer. On my home page, I have to divs next to each other with the same height and a div below them towards the right. To simplify my problem, look at this example. Code: <html> <body> <div style="float:right"> Hello there! </div> <hr> </body> </html> If there's a "float:right" on that div, the hr tag below doesn't get pushed down. But if I use relative positioning and don't use the floats, I can't put the two top divs next to each other. The other option is to use absolute positioning, but again content below doesn't get pushed down correctly. It seems that using "clear:both" works, but it seems weird that this has to be done. For example if I have floating divs in a container, I can get them to stretch out the container like so: Code: <html> <body> <div style="border: 1px solid #000; "> <div style="float:right"> Hello there!<br /> Hello there!<br /> Hello there!<br /> Hello there!<br /> Hello there!<br /> Hello there!<br /> Hello there!<br /> </div> <div style="clear: both"></div> </div> <hr> </body> </html> Am I missing something fundamental here? Is there a better solution? Thanks in advance. Here's the site in Question: http://www.winchps.vic.edu.au It's a standard fixed width floated DIV columns with a wrapper. One thing it does have is a second DIV inside both columns to display the Gradient background over the top of the repeated background. It works perfect in Firefox & IE7 (with a tweak) but IE6 mkes the sidebar nested div drop below the original sidebar DIV click here for a screenshot for those lucky enough not to have IE6. Here's the CSS code for the basic layout: Code: body { font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif; font-size: 12px; text-align: center; margin: 0px 0px 60px 0px; padding:0px; border: 0; line-height: 2; } #header { width: 802px; } #wrapper { width: 802px; margin:0px; padding: 0px; text-align: left; margin: 0 auto; background: url(images/bodybg.jpg) center repeat-y; } #content { padding: 0px; margin: 0px; } #maingrad { background: url(images/winchcontentgrad.jpg) top left repeat-x; padding: 10px; } #main { width: 589px; float: right; background: url(images/winchcontentbg.jpg) repeat; border-left: solid 1px #000; border-right: solid 1px #000; } #mainstop { width: 589px; float: right; background: url(images/winchcontentbg.jpg) repeat; border-left: solid 1px #000; border-right: solid 1px #000; border-bottom: solid 1px #000; font-size: 10px; } #sidebargrad { background: url(images/winchsidebargrad.jpg) top left repeat-x; padding: 10px 5px 0px 10px; } #sidebar { width: 200px; float: left; background: url(images/winchsidebg.jpg) repeat; line-height: 2; font-size: 14px; border-left: solid 1px #000; border-right: solid 1px #000; } I obviously need to put a conditional comment in there, same for what I did for the minor IE7 tweak, but I'm struggling to suss out what's causing it, I haven't found the specific issue on any of the regular sites (PIE etc). Anyone got any ideas? Centering DIVs inside other DIVs in Firefox? Can it be done in a straight forward way? Setting the inner DIVs float to none seemed to work for IE but not FF. |