"Implemented a user-friendly header and footer that stick to the top and

My goal is to create a fixed header and footer, allowing the main content to scroll underneath while keeping the right navigation in place.

To achieve this effect, I've been experimenting with different solutions. One of my attempts can be viewed here: http://jsfiddle.net/sjUBQ/. However, in order to show a scrollbar, I had to set a fixed height for the main content section using CSS.

I also tried incorporating jQuery code into the mix:

$(document).ready(function() {
  var desiredHeight = $("body").height() - $("head").height() - $("footer").height();
  $(".yui3-u-3-5").css("min-height", desiredHeight );
});​

Unfortunately, this solution did not work as expected. Can anyone guide me on how to achieve a sticky header and footer setup while ensuring that the inner div displays a scrollbar when the content exceeds the browser window height?

Answer №1

Does this match the concept you have in mind? Check it out here

You can experiment by adjusting the height of the lower right pane to see if it functions as desired. I believe using position: fixed; for your header and footer is crucial (assuming I understand your objective correctly). It would also be beneficial to set top and bottom margins on the main div equal to the heights of the header and footer respectively.

UPDATE: I added "BEGIN" and "END" in the Lorem Ipsum text to ensure visibility of all content.

UPDATE #2: Revised jsFiddle link: Latest version available here

UPDATE #3: To summarize, the following jQuery code should meet your needs:

var headerHeight = $('#head').height(),
    footerOffset = $('#footer').offset().top,
    desiredHeight = footerOffset - headerHeight;

$('.yui3-u-3-5').css('height', desiredHeight);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering an Uncaught TypeError while trying to read properties of undefined (specifically 'remove') during a Change event is causing an issue for me

Looking to update the icons by changing the class from .fa-plus to .fa-minus for this specific menu section <div class="accordion-menu"> <h2 class="accordion-header" id="subseccOne"> ...

Utilize the Bootstrap column push-pull feature on the mobile version of

https://i.stack.imgur.com/yTBIt.png When viewing the desktop version, div A is displayed at the top of the page. However, I would like to move it to the bottom when viewing on a mobile device (col-xs). I have attempted to solve this issue myself without s ...

Updating an if statement in Rails views via AJAX: the ultimate guide

In my app, I have votable posts that users can vote on through AJAX. While this functionality works well, I also want to update the status of a post (indicating whether it is an agreed milestone) when a user votes through AJAX. Below is the code snippet fo ...

Decoding JSON information using JQuery/JavaScript

I came across a similar discussion on this topic here, however, the format of my returned data is slightly different. The Json string returned from the server looks like this: <!DOCTYPE HTML> <html> <head> <style> </style> ...

Implement a feature in JavaScript that highlights the current menu item

I'm currently developing a website at and have implemented a JavaScript feature to highlight the current menu item with an arrow. The issue I'm facing is that when users scroll through the page using the scrollbar instead of clicking on the men ...

jQuery efficiently handles large amounts of text data transfer (gradual loading)

The issue at hand: My website relies on jQuery AJAX (post) for navigation, meaning the page doesn't refresh every time a user moves to a different section. This setup requires me to fetch data using AJAX and present it dynamically. While this works w ...

When the fullscreen modal is opened, the initial image displayed is not the same as the one that was clicked on

Seeking assistance: I've been struggling with a problem for quite some time now and could really use some help from you guys. My issue involves an 'AngularJS' webapp that retrieves posts from an 'FB page' via 'OpenGraph' ...

Showing no background color until the user lifts their finger

I am currently in the process of developing a website. The navigation on the website starts off as transparent (background: transparent) when opened, but as soon as you start scrolling, it should transition to a colorful state with shades like grey, midnig ...

Using AJAX to send both data input values and file attachments simultaneously to a PHP server

I am currently having an issue with sending form values to my PHP page using AJAX. My form includes text inputs and a file input for image uploads. Below are the AJAX codes I have been working on: function sendval() { var form = $('#user_update_for ...

How can the resize function be modified to include an additional 100 pixels on top of the current size?

Something interesting I discovered is that I can do the following: height() + 100); When I attempted to execute: $('.modal1').colorbox.resize({height()+100}); I was puzzled as to why it didn't work. All I wanted to achieve is to add an ad ...

How to send parameters to the jQuery delete button click event handler

Here is the jQuery code I am working with: $('#btnDelete').click( function() {//Do the delete here via jquery post}); In my table, each row has a delete button like this: <a id="btnDelete">Delete</a> I need to pass parameters to t ...

Implementing a translucent overlay onto a specific HTML section using sidebar.js/jQuery

Searching for a way to enhance the functionality of my website using Sidebar.js, I came across an interesting feature on hypebeast.com. When you click on the three-bar icon, the main container section's opacity changes. How can I achieve this effect? ...

What is the best method for inserting dynamic HTML content (DIV) with JavaScript?

Can someone assist me in dynamically adding HTML content when data is returned from the server-side? I am currently using ajax/jQuery to handle server-side processing requirements. The success code section of my ajax function allows me to write HTML elemen ...

Error: Unexpected token : encountered in jQuery ajax call

When creating a web page that requests remote data (json), using jQuery.ajax works well within the same domain. However, if the request is made from a different domain (e.g. localhost), browsers block it and display: No 'Access-Control-Allow-Or ...

Leverage jQuery to activate/deactivate a button according to variables

Currently, I am utilizing jQuery to carry out username and email validations prior to a user signing up... This code assigns a boolean value based on the response received from PHP. $(document).ready(function() { if (usr_checked == true) ...

AngularJS enables tab highlighting by responding to button selections

In my application, there are 3 tabs set up as follows: <li ng-class="{ active: isActive('#one')}"><a data-toggle="tab" class="tab-txt-color" href="#one" ng-click="selectTab('fruits') ...

Setting the height of a div tag in CSS/HTML5 to match the current height of the browser window

Is there a way to make the height of my div tag always equal to the height of the browser's window, so it adjusts automatically when the browser is resized? I have tried using .class { height: 100%; } But this doesn't work. I've learne ...

Having trouble getting the background of the <span> element to function properly

So, here is the code I have been working on: echo "<span style='float:right; text-align:right; background-image:url('" . $icon_url . "') no-repeat top right; height:86px; width:86px; display:block;'>" . $curr_temp . "<br /> ...

Getting Anchor Javascript to Submit in Internet Explorer. Functioning in Firefox, Chrome, and Safari

Greetings Stackoverflow enthusiasts, I have been working on a raffle form where users can input their name and select their location from a dropdown list. After filling out the form, they can click submit and their information will be stored in a database ...

I am experiencing an issue where the Flex table is not displaying more than 50 rows

I am experiencing an issue where I can't scroll back up with the scrollbar. The table is dynamically filled with data from a database, and when it gets too long, I am unable to scroll back up. Any suggestions on how to solve this problem? If you need ...