Reputation: 239
I have a nav bar that I have positioned 'fixed' at the top of my page. The problem that I have is that I want to displace the entire page down by the (dynamic) size of my nav depending on the size of the screen used. Basically, I want to move the whole page down the height of this nav. To do this, I'm going to be using a padding to the nav that will affect it's height. I am using a box-sizing:border-box attribute on this nav but whenever I try and load the page, it doesn't account for the extra height added with the padding when I use jQuery's .height() function.
The div with the 'displacement' class does not have anything to it except a 100% width initially. This is the ugly result along with all of the current code
Can anyone tell me why this is happening or if I've overlooked something?
Upvotes: 0
Views: 1953
Reputation: 930
var height = $('header').outerHeight();
$('.displacement').css('height',height);
Try something like this
Upvotes: 1
Reputation: 1299
Try using .outerHeight() to get the height of the navbar.
From jQuery API docs:
"The top and bottom padding and border are always included in the .outerHeight() calculation; if the includeMargin argument is set to true, the margin (top and bottom) is also included."
http://api.jquery.com/outerheight/
Upvotes: 3