Using Simple jQuery to Set the Height of a DIV to the Page Height
With CSS2 there is no easy way to set the height of an element to match the length of a page. Most people try to use:
height: 100%;
This only sets the element to be the height of the browser window. As soon as you scroll down, your element does not keep going. In all my searching I have not found a single way to do this in CSS alone that works in all current browsers.
To solve this issue I have been using very simple jQuery to retrieve the height of the page and set the height of the element:
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#name_of_element").height($(document).height());
});
</script>This very simple code has made it simple to ensure an element, such as a DIV, gets assigned the height of the full page.
7 Comments
Leave a comment
Follow John Chapman
SharePoint StackExchange
- http://t.co/iQpe9vD0 - #sharepoint - [SharePoint 2010 / SQL Server 2008] Query the SharePoint Object Model from a .NET SQL Server CLR Functi
- http://t.co/2dyRsdgu - #sharepoint - [SharePoint 2010] Debugging a Custom SharePoint Timer Job
- Help! FAST Search for SharePoint 2010 SQL Server Deadlocks http://t.co/3MDByzBP
Recent Posts
- [SharePoint 2010 / SQL Server 2008] Query the SharePoint Object Model from a .NET SQL Server CLR Function
- [SharePoint 2010] Debugging a Custom SharePoint Timer Job
- [SharePoint 2010] Set Access Request Email for All SharePoint Sites
- [ASP.NET / LINQ] Access GridView DataItem Properties of Anonymous Types
- [.NET / LINQ] Dynamic SQL-Like LINQ OrderBy Sorting Extension

Thanks buddy for this code.
Saving lots of time
God bless
I tried all the other solutions with mixed results as well. I finally gave up and decided to use JavaScript. jQuery worked out for me again, thanks for posting this…
Great, thanks, I was getting a headache trying to do this with css
How do I reduce the style class that is applied to the element by a specified amount?
I need to reduce the height generated by 265 pixels, where would I add it to this code?
$(“#name_of_element”).height($(document).height());
$(“#name_of_element”).height($(document).height() – 256);
Nice Job.
Thank you, Thank you, Thank you! Just spent an hour trying to fix css! This technique fixed it in 10 seconds.