CSS - 100% Of Remaining Height Of Parent
This is something I've never been able to figure out a good solution for. I've found a few posts about the same issue, but in more specific terms. Quite often they also speak about how to fill the entire viewport in some way.
Anyway. Let's say we have a container: <div id="container"></div> Inside this container we have sort of a caption element. An element that is dynamic in height. Font size, padding, margins and the like will affect how high it gets in the end. <div id="container"><h2>My Dynamic Height caption</h2></div> Now. If i add another "sub container" in there. How do i make it take up the remaining space (height) of the parent container, no matter the size of the parent container and no matter the size of the sibling's dynamic height content (the h2 in this example) <div id="container"> <h2>Caption</h2> <div id="subContainer"> I want this div to be as high as what's left of "container" </div> </div> I know I can do this with javascript, calculating exact dimensions of subContainer based on the current environment. I even have a CSS solution, making "container" position relative and positioning subContainer absolute with left,right,bottom = 0 and top = somewhat close to how high the h2 is. Any other ideas? Similar TutorialsI am trying to make sure that the body div takes up all the available space in div container (the parent div), however: Code: height: 100%; makes it take up 100% of the whole page, not just the container. Here is my source code: Code: <!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> <title>Home -- OpportunIT</title> <link href="main.css" rel="stylesheet" type="text/css" /> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <link rel="alternate" type="application/rss+xml" title="OpportunIT News Feed" href="http://www.sphinxgaming.com/OpportunIT/" /> <link rel="shortcut icon" href="favicon.ico" /> </head> <body id="test"> <div id="container" class="rounded-corners"> <div id="header">OpportunIT</div> <div id="nav-menu"><ul> <li><a href="?page=home">Home</a></li> <li><a href="?page=software">Software</a></li> <li><a href="?page=about">About us</a></li> <li><a href="?page=contact">Contact us</a></li> </ul></div> <br/><br/> <div id="body"> Welcome to OpportuneIT!<br/> <br/> <b>What's New:</b><br/> <a href="?page=sinc">SiNC Framework Announced</a><br/> SiNC is a framework used to manage computers and networks in a secure,<br/> reliable, easy to learn and use way. SiNC can make almost any network<br/> management tasks simpler, such as transferring a file over a secure<br/> connection, running commands on or even remotely controlling computers,<br/> checking the status of various servers, computers and online services<br/> automatically, simplifying networked programming tasks and managing network<br/> security.<br/> <br/> <a href="?page=home">Renamed and Redesigned!</a><br/> We have been renamed to OpportuneIT, and are working on a brand new<br/> website... Stay tuned for more info on this.<br/> </div> </div> </body> </html> Code: html, body { height: 95%; } #container { height: 100%; width: 95%; margin-left: auto ; background: #FFFFFF; margin-right: auto ; } #nav-menu ul { list-style: none; padding: 0; margin: 0; } #nav-menu { margin-left: auto ; margin-right: auto ; width:40em } #nav-menu li { float: left; margin: 0 0.15em; } #nav-menu li a { height: 2em; line-height: 2em; float: left; width: 9em; display: block; border: 0.1em solid #dcdce9; color: #0d2474; text-decoration: none; text-align: center; } #body { height:auto; width: auto; margin-left: auto ; background: #FFFFFF; margin-right: auto ; padding: 5px; } #header { margin:0px; padding:0px; background: #000000; width:auto; height:54px; font-family:Verdana; font-size:30px; text-align:center; color:#FFFFFF; border-bottom: #AAAAAA solid 5px; } #footer { margin:0px; padding:0px; background: #000000; width:auto; height:24px; text-align:center; color:#FFFFFF; } .rounded-corners { -moz-border-radius: 20px; -webkit-border-radius: 20px; -khtml-border-radius: 20px; border-radius: 19px; border-style:solid; border-width:20px; } Thanks in advance. Hello, I would like to know how to do this: I have a fixed-size div and several inner divs in it, positioned vertically (on top of each other). I want the last div's size to be equal to the size of the fixed-size div minus all the other divs (currently, one other div). Example: I have a form, which has a certain height. The form has a header and a section (div) with 3 inner checkbox divs (columns), and I want the checkbox divs to scroll if they overflow the main div and in effect the parent div. Is there any way to do this? Thanks! EDIT: Here is a live example. (in this example, there's an extra div within the child div holding the checkboxes) Currently, instead of the desired solution each checkbox div is 70% of the height of the main parent. helenas flower abode.com / pictures.php?width=800&height=1118&picturediv_height=366&pngalt=.png&js=1&action=search EDIT2: I changed the structure of the site and the page link as well, and you can't see the temp. fix in Firefox and possibly in IE7 (tested in IE6). EDIT3: Anyone? found what I was looking for. Hello there, I have a question about floating and automatic heights. First, i don't want to use tables becouse of layout etc... I want to have a "row" with 3 seperate "columns". Each "Cell" should have the same height as the heighest "Cell". Now this is where the problem is. The height isn't correct . I Tryed height: auto and 100%. But nothing is working. How can i fix this? Thx in advance. CSS: Code: .divRow { float: left; position: relative; height: auto; margin: 2px 0; } .columnTo, .columnMessage, .columnDate { height: 100%; float: left; padding: 0; padding-right: 2px; background-color: #f0f0f0; vertical-align: middle; } .columnTo { width:75px; overflow: hidden; background-color: #ff0000; } .columnMessage { margin-left: 2px; width:270px; overflow: hidden; background-color: #00ff00; } .columnDate { margin-left: 2px; width:40px; overflow: hidden; background-color: #0000ff; } HTML Code: <div class="divRow"><div class="columnTo" style="background:#ffad39">Column#1:</div><div class="columnMessage" style="background:#ffad39">Column#2:</div><div class="columnDate" style="background:#ffad39">Column#3:</div><div class="clearBoth"></div></div> <div class="divRow"><div class="columnTo clearBoth">Foobar #1</div><div class="columnMessage">This is a peace of text etc.. etc.. etc.. etc.. And Some more text, and some more..............</div><div class="columnDate">blah</div><div style="clear:both"></div></div> <div class="divRow"><div class="columnTo clearBoth">Foobar #1</div><div class="columnMessage">This is a peace of text etc.. etc.. etc.. etc.. And Some more text, and some more..............</div><div class="columnDate">blah</div><div style="clear:both"></div></div> Hi, there. I've created a simple 2-column list using a <span> to justify items I want in the right column to the right edge of the containing <div>... everything is working fine in Firefox, but have just noticed that Internet Explorer is punching all the spans down one line. I thought spans were purely inline, so this is a little confusing! Here's the CSS I'm using: Code: #300px-LIST { width:300px; margin:0px auto; text-align:left; padding:0; } .right { float: right; } ...and the HTML: Code: <div id="300px-LIST"> LINE 1 LEFT<span class="right">LINE 1 RIGHT</span><br /> LINE 2 LEFT<span class="right">LINE 2 RIGHT</span><br /> LINE 3 LEFT<span class="right">LINE 3 RIGHT</span><br /> </div> Any pointers gratefully received! Ok so I have a logowrap layer which is at 100%. I have the actual logo set with 'float:right;' with a width of 900px. Now i have a layer just before that with float:left;, but i want to set the width with the remaining space, so all resolutions will render it the same way, whether it be a 1280*760 - or whatever. CSS: Code: #logowrap { width:100%; background-color:#000000; } #logonavtext { float:left; color:#0099FF; padding:2px; } #logonavtext ul { list-style:none; } #logonavtext li { display:inline; margin-right:30px; } #logowrapimg { float:right; width:900px } HTML: Code: <div id="logowrap"> <div id="logonavtext"> <ul> <li>[ I ]</li> <li>[ II ]</li> <li>[ III ]</li> <li>[ IV ]</li> <li>[ V ]</li> <li>[ VI ]</li> <li>[ VII ]</li> <li>[ VIII ]</li> <li>[ IX ]</li> </ul> </div> <div id="logowrapimg"> <?php include('scripts/logorandom.php'); ?> </div> <div class="clear"> </div> </div> Any help would be great. Of course If you have a better way, I would more then welcome it. I'm (noobishly) developing a site and want a menubar of fixed size at the top, with the remaining area of the window filled with a div containing the scrolling content. It's height should be effectively 100% - size of menubar. When I tried 100% height it natually was the full screen height, but then the whole page is full screen height plus the height of the menu bar. Does anyone know how to size a div to meet my needs? Here is the basic structure i'm working with: Quote: <div id="header'> header goes here </div> <br clear="all"> <div id="leftbar">dynamically generated content from php here</div> <div id="map"> map here </div> the styles: Quote: #header{ height:42px; width:100%; background-image: url(../images/header/header_spacer.jpg); background-repeat:repeat-x; text-align:right; } div.leftbar{ float:left; width: 400px; height:100%; overflow: scroll; z-index:1; } div.map{ float:left; } The Problem: In all browsers the height of the leftbar is : 100% of the entire page as opposed to 100% of the entire page minus the size of the header element. This causes a scroll bar to appear on the page. Any ideas on how to solve this problem? If I don't define a height of 100% the leftbar div doesn't scroll at all. A good example of what i'm trying to accomplish here is : maps.google.com . Notice how on that site, the left menu bar scrolls, but is always 100% of the remaining page length (after the search stuff on top). thanks in advance. Hi all, I am trying to automate everything on my test website and I have one more angle to cover. In effect, I want to adjust the line-height property (which I can do) based on the number of files within a specific folder (PHP and already done). The more files in the folder, the lower the line-height value must be. This is to ensure if I copy additional files into the folder, then the navigation menu (which is PHP reading files in this particular folder) will alter the CSS line-height property accordingly to ensure it can never exceed a certain height. Sounds wierd? go to www.re3.org.uk (next to the RE3 image, I have a list of hyperlinks which are obtained from files within the folder) My problem, when adjusting the CSS property (which is set as cm in *.css file) in javascript, it doesn't correspond correctly, the line-height property in javascript doesn't appear to be work in cm but some other measurement. Does anyone know how to change what unit of measurement Javascript works in? Or does anyone know what unit of measurement javascript uses when adjusting line-height / line-width values? I want to create a mini-algorithm that works out the appropriate line-height based on the image height (got that already) and the number of files in the folder (got that too) so the menu automatically adjusts to fit. Whew! Hello Just recently I had an idea for a page I wanted to make, the design is basically a 3-column layout with no traditional header or footer, the height of all three columns should run the length of the window/page height the left and rightmost column would have a fixed width or a width in em, the center column width should fill the space in between. If the content is short all columns should extend to the height of the page window, but if the content in any of the columns is longer than the window height they should all extend to reach the bottom of the page and accommodate the content length In my first attempt things didn't go so well, results varied wildly across browsers so I decided to start from scratch bit by bit Bellow is the point at which I reach consistent but undesired behaviour, I have validated and tested the code in Firefox 3/Pale Moon, Internet Explorer 8, Chromium 9, and Opera 11 I would like the end result to work in the above browsers as well as IE7 if possible I should point out now that im not interested in using faux-columns, the layout should not require images, I also wish to have absolute-positioned elements in the columns some time later 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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Three Columns</title> <style type="text/css"> *, html, body { margin: 0; padding: 0; font-size: 100%; } html, body { width: 100%; height: 100%; } #maincontainer { position: relative; height: 100%; background: #eee; } #left { position: absolute; top: 0px; left: 0px; width: 200px; background: #fbb; height: 100%; } #mid { position: relative; margin: 0 200px 0 200px; background: #efe; height: 100%; } #right { position: absolute; top: 0px; right: 0px; width: 200px; background: #bbf; height: 100%; } </style> </head> <body> <div id="maincontainer"> <div id="left"> left start<br /> left<br /> left<br /> left<br /> left<br /> left<br /> left<br /> left<br /> left<br /> left<br /> left<br /> left<br /> left<br /> left<br /> left end<br /> </div> <div id="mid"> mid start<br /> mid<br /> mid<br /> mid<br /> mid<br /> mid<br /> mid end<br /> </div> <div id="right"> right start<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right<br /> right end<br /> </div> </div> </body> </html> In the above example it works as long as the content within the columns is shorter than the window height, but if you re-size the window so that the text in the right or left column goes beyond the page, and then scroll to the bottom, the columns do not extend to the bottom of the page so there is a large gap where the content overflows beyond the column What I would like to do from this point is make the columns extend to the bottom of the page when this happens, but I'm not sure how best to proceed I also have a version of the above code which uses floated left and right columns instead of absolute positioned ones, would it be better to work from that? or does it not really matter Thanks in advance I've never done much CSS work, but I know this has to be an easy fix. Each DIV appears to be 10px higher when viewed in IE. I want them to be 8px high and they end up being 18px high. In Firefox, Netscape, and Opera it works fine. Anyone mind correcting this imbarrassing little 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" > <head> <title>IE 10px Padding Problem</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> body { margin:0px; } #container { position:relative; margin:auto; width:730px; } #header { height:110px; } .textualtop { border:1px solid #000000; height:8px; } .textualbottom { border:1px solid #000000; height:8px; } </style> </head> <body> <div id="container"> <div id="header"></div> <div class="textualtop"></div> <div class="textualbottom"></div> <div class="textualtop"></div> <div class="textualbottom"></div> <p>Notice how in IE6 each DIV is 10px higher then in FF. Why is it doing this?</p> </div> </body> </html> It seem that everytime I added the image tag, the div'x area get bigger in IE but not in Mozilla/Firefox browser. So, I thought by added the "margin-bottom:-360px;" to the div would fix it but it had an opposite effect. Meaning it worked in IE but Mozilla show a vertical scrollbar. So, does anyone know how can I make the <img> overlap one another without being stacked on one after another in height for IE if I take out the "margin-bottom: -360px;"? Thanks... Code: div.divBox1 { width: 286px; height: 359px; float: left; } div.divClearFloat { clear: both; height: 0px; /* For IE Stupidity (it added some spaces after clearing the float) */ font-size: 1pt; /* For IE Stupidity (minimum height only work with current font-size somewhere) */ } div.divDottedLineAdvertisementSeperator1 { width: 575px; height: 3px; background-color: #ff0000; font-size: 1pt; /* For IE Stupidity (minimum height only work with current font-size somewhere) */ } Code: <div class="divBox1"> <div style="margin-bottom:-360px;"> <img src="images/doctor.jpg" style="position:relative;top:0px;left:0px;z-index:2;"> <img src="images/we_help.jpg" style="position:relative;top:-360px;left:0px;z-index:1;"> </div> </div> <div class="divClearFloat"></div> <div class="divDottedLineAdvertisementSeperator1"></div> Hello everybody! I have been having a big problem with my webpage for a long time now and hope I can find an answer to my problem with your help. I want a div that contains the content of my pages (which varies in length depending on the individual page) to stretch the length of my page, but it only stretches the length of the window. Here's the HTML and CSS: HTML (I only included the very basic structure): <html> <body> <div class="container"> <div id="content"> <div id="..."></div> <div id="..."></div> <div id="..."></div> <div id="..."></div> </div> </div> </body> </html>` CSS: html, body { height: 100%; font-family: Arial; font-size: 10px; color: #000000; background: #FFF url(../../images/body.png) no-repeat center 40px; margin: 0; position: relative;} .container { height: 100%; width: 960px; margin-right: auto; margin-left: auto; position: relative;} #content { width: 939px; min-height: 100%; position: relative; top: 210px; left: 6px; box-shadow: 0px 0px 8px #666; -moz-box-shadow: 0px 0px 8px #666; -webkit-box-shadow: 0px 0px 8px #666; background-color: #FFF;} I tried to set the content div to overflow: auto, but that includes a scroll bar for the content div that I do not want. It does, however, create the desired effect of the shadow and background of the #content div all the way to the end of the page. Am I missing anything? I thought min-height would work, but it doesn't! It only stretches the content div to page height and everything else is overflow, but without the content div's background color and shadow. Does anybody maybe see where the problem lies? Thank you so much in advance for your help. If you look at the bottom of the page at www.res-technologies_DOT_com/index.php?jos_change_template=restech2 in both IE and FF, you will see that it looks fine in IE, but in FF the page length is extended by exactly the height of the header image at the top of the page. Trying to figure out what's causing this is driving me nuts! Can anyone help? thx dh My web page has a display bug in IE 5+ on Windows. Specifically, I have a DIV within which I wish to place two images. The two images are the same height and width, and I want to layer them (the top one is a PNG with transparency, but I have already solved that problem, this is a positioning problem) exactly on top of each other. I have done this by positioning them relatively within the DIV. The first image is top:0;left:0 and the second is top:-150;left:0 (the images are 150 px tall). They layer fine, but the DIV is twice the height (as if the second image were still following the first, making he DIV 300 px tall). I have tried many things and am stumped. Here is the site: URL Here is the relevant CSS: Code: #bannerPhoto { border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #000000; height: 150px; width: 750px; } #bannerPic { position: relative; z-index: 1; left: 0px; top: 0px; } #bannerText { position: relative; z-index: 2; left: 0px; top: -150px; } And the HTML: Code: <div id="bannerPhoto"> <div id="bannerPic"><img src="../images/bannerPhotos/image.jpg" height="150" width="750" /></div> <div id="bannerText"><img src="../images/text-cover.png" height="150" width="750" /></div> </div> Anyone? Thanks, Denver. I am having a problem trying to get one column match the height of another. Within a large DIV box, I created two columns separated by about 20 px. I floated one to the left, then pushed one over to the right. Both boxes will expand depending on the amount of content, but I would like them to match the same height. The boxes will be used throughout the entire website, so it would not make sense to create a background image to try and trick it into being the same height.. or actually specifying the height. Is there any way to tell the left box to be the same height as the right box?? I tried to link to my site but it won't let a new member link to a website. i came across a solution for this a while ago and can't repeat the result i have 3 columns, div format with a left left right float. 1 2 3 #2 contains content that varies with the page, #1 and #3 contain background elements. i need 1 and 3 to extend the full height of 2, even tho the actual content is much less. thanks for the help! Hi Guys, Consider the following box: PHP Code: <div style=border: 1mm black Solid; width: 148mm; height: 98mm;'> </div> 148mm + 1mm + 1mm = width of 150mm 98mm + 1mm + 1mm = width of 100mm Now why does neither firefox or ie manage to get it? Firefox is about 2mm out and ie is about 3mm out? Any ideas or is it some quirk? Charlie Please look at this page - http://hometown.tmhdesign.com/ask.asp?faq=9 See how the <p> exceeds the containing box at the bottom? I put a border-bottom on the containing div to show you where the issue occurs. It does not happen in IE7 I just noticed it does it also on this page http://hometown.tmhdesign.com/staff.asp Is there a way to get the style sheet to let the inner tag to override the parent's tag? Seem that only one webpage need that while many other doesn't. I'll post the code below, take a look at the text-align:left ...... Code: <div style="margin:0px;padding:25px 30px;text-align:left;"> <img style="text-align:center;" src="..."> </div> |