<p>In a web application, I have a page that contains a DIV that has an auto-width depending on the width of the browser window.</p>

<p>I need an auto-height for the object.  The DIV starts about 300px from the top screen, and its height should make it stretch to the bottom of the browser screen.  I have a max height for the container DIV, so there would have to be minimum-height for the div.  I believe I can just restrict that in CSS, and use Javascript to handle the resizing of the DIV.</p>

<p>My javascript isn't nearly as good as it should be.  Is there an easy script I could write that would do this for me?</p>

<p>Edit: 
The DIV houses a control that does it's own overflow handling (implements its own scroll bar).</p>

[{'answer_id': 33096, 'author': 'Chris Marasti-Georg', 'author_id': 96, 'author_profile': 'https://Stackoverflow.com/users/96', 'pm_score': 3, 'selected': False, 'text': '<p>What should happen in the case of overflow?  If you want it to just get to the bottom of the window, use absolute positioning:</p>\n\n<pre class="lang-css prettyprint-override"><code>div {\n  position: absolute;\n  top: 300px;\n  bottom: 0px;\n  left: 30px;\n  right: 30px;\n}\n</code></pre>\n\n<p>This will put the DIV 30px in from each side, 300px from the top of the screen, and flush with the bottom.  Add an <code>overflow:auto;</code> to handle cases where the content is larger than the div.\n<hr/>\nEdit: @Whoever marked this down, an explanation would be nice... Is something wrong with the answer?</p>\n'}, {'answer_id': 33124, 'author': '17 of 26', 'author_id': 2284, 'author_profile': 'https://Stackoverflow.com/users/2284', 'pm_score': 0, 'selected': False, 'text': '<p>If I understand what you\'re asking, this should do the trick:</p>\n\n<pre><code>// the more standards compliant browsers (mozilla/netscape/opera/IE7) use \n// window.innerWidth and window.innerHeight\n\nvar windowHeight;\n\nif (typeof window.innerWidth != \'undefined\')\n{\n    windowHeight = window.innerHeight;\n}\n// IE6 in standards compliant mode (i.e. with a valid doctype as the first \n// line in the document)\nelse if (typeof document.documentElement != \'undefined\'\n        &amp;&amp; typeof document.documentElement.clientWidth != \'undefined\' \n        &amp;&amp; document.documentElement.clientWidth != 0)\n{\n    windowHeight = document.documentElement.clientHeight;\n}\n// older versions of IE\nelse\n{\n    windowHeight = document.getElementsByTagName(\'body\')[0].clientHeight;\n}\n\ndocument.getElementById("yourDiv").height = windowHeight - 300 + "px";\n</code></pre>\n'}, {'answer_id': 33129, 'author': 'Toran Billups', 'author_id': 2701, 'author_profile': 'https://Stackoverflow.com/users/2701', 'pm_score': 3, 'selected': False, 'text': "<p><code>document.getElementById('myDiv').style.height = 500;</code></p>\n\n<p>This is the very basic JS code required to adjust the height of your object dynamically.  I just did this very thing where I had some auto height property, but when I add some content via <code>XMLHttpRequest</code> I needed to resize my parent div and this offsetheight property did the trick in IE6/7 and FF3</p>\n"}, {'answer_id': 33147, 'author': 'Jason Bunting', 'author_id': 1790, 'author_profile': 'https://Stackoverflow.com/users/1790', 'pm_score': 6, 'selected': True, 'text': '<p>Try this simple, specific function:</p>\n\n<pre><code>function resizeElementHeight(element) {\n  var height = 0;\n  var body = window.document.body;\n  if (window.innerHeight) {\n      height = window.innerHeight;\n  } else if (body.parentElement.clientHeight) {\n      height = body.parentElement.clientHeight;\n  } else if (body &amp;&amp; body.clientHeight) {\n      height = body.clientHeight;\n  }\n  element.style.height = ((height - element.offsetTop) + "px");\n}\n</code></pre>\n\n<p>It does not depend on the current distance from the top of the body being specified (in case your 300px changes).</p>\n\n<hr>\n\n<p>EDIT: By the way, you would want to call this on that div every time the user changed the browser\'s size, so you would need to wire up the event handler for that, of course.</p>\n'}, {'answer_id': 1718904, 'author': 'Shanti', 'author_id': 209155, 'author_profile': 'https://Stackoverflow.com/users/209155', 'pm_score': 0, 'selected': False, 'text': '<p>With minor corrections:</p>\n\n<pre><code>function rearrange()\n{\nvar windowHeight;\n\nif (typeof window.innerWidth != \'undefined\')\n{\n    windowHeight = window.innerHeight;\n}\n// IE6 in standards compliant mode (i.e. with a valid doctype as the first\n// line in the document)\nelse if (typeof document.documentElement != \'undefined\'\n        &amp;&amp; typeof document.documentElement.clientWidth != \'undefined\'\n        &amp;&amp; document.documentElement.clientWidth != 0)\n{\n    windowHeight = document.documentElement.clientHeight;\n}\n// older versions of IE\nelse\n{\n    windowHeight = document.getElementsByTagName(\'body\')[0].clientHeight;\n}\n\ndocument.getElementById("foobar").style.height = (windowHeight - document.getElementById("foobar").offsetTop  - 6)+ "px";\n}\n</code></pre>\n'}, {'answer_id': 26062700, 'author': 'RawBits', 'author_id': 2023816, 'author_profile': 'https://Stackoverflow.com/users/2023816', 'pm_score': 0, 'selected': False, 'text': "<p>Simplest I could come up...</p>\n\n<pre><code>function resizeResizeableHeight() {\n    $('.resizableHeight').each( function() {\n        $(this).outerHeight( $(this).parent().height() - ( $(this).offset().top - ( $(this).parent().offset().top + parseInt( $(this).parent().css('padding-top') ) ) ) )\n    });\n}\n</code></pre>\n\n<p>Now all you have to do is add the resizableHeight class to everything you want to autosize (to it's parent).</p>\n"}, {'answer_id': 40434747, 'author': 'mwag', 'author_id': 3160967, 'author_profile': 'https://Stackoverflow.com/users/3160967', 'pm_score': 0, 'selected': False, 'text': '<p>inspired by @jason-bunting, same thing for either height or width:</p>\n\n<pre><code>function resizeElementDimension(element, doHeight) {\n  dim = (doHeight ? \'Height\' : \'Width\')\n  ref = (doHeight ? \'Top\' : \'Left\')\n\n  var x = 0;\n  var body = window.document.body;\n  if(window[\'inner\' + dim])\n    x = window[\'inner\' + dim]\n  else if (body.parentElement[\'client\' + dim])\n    x = body.parentElement[\'client\' + dim]\n  else if (body &amp;&amp; body[\'client\' + dim])\n    x = body[\'client\' + dim]\n\n  element.style[dim.toLowerCase()] = ((x - element[\'offset\' + ref]) + "px");\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/33080', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1226/']