I am working on a website where the menu bar and footer need to be 50px in height as shown in the image. In between the nav
and footer
, there is a content div
that should occupy the remaining space. To achieve this, I plan to use Jquery
to calculate the document height, Nav
height, and Footer
height, and then subtract them from each other to determine the content height:
content_height = document_height - nav_height - footer_height;
The issue I am facing is that when trying to retrieve the heights of footer
and nav
, the height attribute returns 0.
This is the Jquery code snippet I have implemented:
var height = $(document).height();
var menu_height = $('#nav').height() + $('#footer').height();
$('#content').css('height', height - menu_height);
You can view a demo here. Interestingly, the demo works fine but my actual code does not.
Can anyone provide guidance on how to solve this issue and correctly obtain the height of the desired elements?