Center column with header and footer flanking each side

Trying to replicate the layout of the Facebook Android app on my page. The app features a 3 column design, with the central column exclusively displaying the header (no footer included, although I require one for my version).

This visual representation is illustrated in the image below.

The red and blue divs represent the left and right sidebars. The green and purple divs depict the central content area. The purple divs act as the header and footer, remaining fixed at the top and bottom of the page respectively.

An additional function needed is buttons placed on the header (top purple) that toggle the visibility of the sidebars. Initially, only the central content will be visible, with the ability to bring in the sidebars when necessary. Below is the code implemented so far, struggling to calibrate the width for the center div.

HTML:

<html>
<head>
<title>Sample</title>
<link rel="stylesheet" href="index.css" type="text/css" />
</head>
<body>
<div id="main">
    <div id="leftBar" class="main">Left Bar</div>
    <div id="content" class="inner">
        <div id="header">Head</div>
        <div id="body">Body</div>
        <div id="footer">Footer</div>
    </div>
    <div id="rightBar" class="main">Right Bar</div>
</div>
</body>
</html>

CSS:

body {
margin: 0px;
}

div.inner {
height: 500px;
width: 50%;
background: red;
}

<div.main{
background: lime;
height: 200px;
overflow: hidden;
position: relative;
}

#leftBar{
float: left;
}

#content{
position: relative;
height: 100%;
float: left;
}

#rightBar{
float: right;
}

#header{
position: fixed;
top: 0px;
background: blue;
}

#body{
margin-top: 40px;
position: relative;
}

#footer{
position: absolute;
bottom: 0px;
}   

Added JavaScript code within the provided fiddle link below: http://jsfiddle.net/mv6Bj/1/

The ideal width setting should ensure the center div spans the entire screen width. As the sidebars toggle into view, they ought to align themselves accordingly, shifting the center div left or right—a functionality derived from the Facebook app layout.

Current challenges faced include:

  1. The center div lacks full width and fails to adjust as elements appear/disappear
  2. The height of the center div does not consistently reach 100% coverage
  3. Upon clicking 'left', the leftBar vanishes and the content div shifts left while the header remains stationary

Answer №1

After careful consideration, I have made some updates to the fiddle.

See the Updated Demo

I've utilized the display:table property in this implementation. For more information, you can check out this resource or this one.

html, body {
    margin: 0px;
    min-height:100%;
    height:100%;
}

#main {
    min-height:100%;
    display:table;
    width:100%;
    height:100%;
}

#leftBar, #rightBar {
    background: lime;
    width:100px;
    display:table-cell;
}

#content {
    min-height: 100%;
    display:table-cell;
    background: red;
}

#header {
    background: blue;
    height:10%;
}
#body {
 min-height:80%;
    overflow:hidden;
}
#footer {
 background: magenta;
height:10%;
}

I hope these changes meet your requirements.

Answer №2

Feel free to take a look at this fiddle where I've made some adjustments to your CSS.

body {
   margin: 0px;
}
div.inner {
   height: 500px;
   width: 50%;
   background: red;
}
div.main {
   background: lime;
   bottom:0px;
   top:0px;
   overflow: hidden;
   position: absolute;
   width:20%;

}
 #leftBar {
 float: left;
}
 #content {
 position: absolute;
 height: 100%;
  top:0px;
  right:0px;
 width:60%;
 left:20%;
 float:left;

 }
 #rightBar {
float: right;
width:20%;
 background: lime;
top:0px;
bottom:0px;
left:80%;
    position:absolute;
}
#header {
float: left;
position: fixed;
top: 0px;
margin-left: 0px;
background: blue;
left:20%;
right:20%;
}
#body {
margin-top: 40px;
position: relative;
}
#footer {
position: absolute;
bottom: 0px;
position: fixed;

margin-left: 0px;
background: blue;
left:20%;
right:20%;
}

Check out the updated version here!

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

Is it necessary to reset (local storage, session storage) once the countdown timer reaches zero?

I have successfully implemented a countdown timer using session storage in my code. However, I am looking to enhance its functionality further by: Clearing the local session if the user leaves the site before the countdown timer finishes. Automatically c ...

Mastering Jquery Isotope integration with Wordpress for seamless filtering

I've been struggling to implement isotope filtering in my project. As a beginner in jQuery/javascript, I wanted to integrate isotope functionality into a client's website. Despite researching extensively on Stack Overflow and various websites, I ...

Creating a background with image overlays in React: A step-by-step guide

My challenge is to have an image that covers the entire background but it seems to stop abruptly where another object is placed, unable to extend further. I am utilizing Material UI and here is a snippet of my code: import { Image } from "../images&q ...

install jquery package via npm and save it as a dependency

Currently using Ubuntu 16.04 Proxy settings are configured in ~/.npmrc, here is the setup: registry="http://registry.npmjs.org/" proxy="http://username:password@proxyconfig:port" strict-ssl=false http-proxy="http://username:password@proxyconfig:port" ht ...

The process of implementing sticky headers that stay in place while scrolling in a React application

I have a challenge with organizing tables based on date, using headers like (today, yesterday, last week, ...) and I want to make them sticky depending on the current table in the viewport. I attempted to implement this functionality using the react-sticky ...

Set up global variables for components to access

Currently, I am working on a Laravel 8 project with vue-sweetalert2 integration. My goal is to set up the Toast behavior once and then be able to call it within various components. At the moment, my code looks like this: /js/components/Mypage.vue <scr ...

Set my click event handler back to its default setting

I'm struggling with resetting a click function after it completes. How can I make sure it's ready to run again? $('body').on('click', '#ConfirmBet', function () { function randomImg() { var imgs = $(&apo ...

"Combining multiple attributes to target elements while excluding specific classes

My dilemma lies in the following selector that identifies all necessary elements along with an extra element containing the "formValue" class which I aim to omit $("[data-OriginalValue][data-OriginalValue!=''][data-TaskItemID]") ...

Issues with JQuery `.click()` event

Check out this snippet of code I'm working with: $(".item").click(function () { alert("clicked!"); }); I also have (hypothetically; in reality it's more complex) the following HTML on my page: <a href="#" class="item"> ...

Are multiple .then(..) clauses in Javascript promises better than just using one .then(..) clause?

In this particular scenario, I have set up a basic 'toy' node.js server that responds with the following JSON object: { "message" : "hello there" } This response is triggered by making a GET request to "http://localhost:3060/" So, it's reall ...

Is there a way to serve server-side rendered content exclusively to search engine crawlers like Google Bot, without SSR for regular users in Next.js?

With a staggering number of users visiting the site every day, we are making strides to enhance our visibility on Google by implementing SSR (which may sound unbelievable) and achieving a richer preview when content is shared on messaging platforms. As th ...

Encase every picture within a div and add a numerical label in front of it

I'm working on a function that will wrap each image in a div and add a span label for each image. Here is the code I have written so far: $('#carousel img').each(function(index) { $(this).wrap('<div class="image"></div>& ...

Exploring Vue's feature of passing props and emitting events within nested components

Within my coding project, I am facing the challenge of properly implementing a parent component containing a form that includes a birthday component. This birthday component consists of two separate components within it. My task is to effectively pass prop ...

Having difficulty deleting a checkbox element using JavaScript

My goal is to have a feature where users can effortlessly add or remove checkbox div elements as needed. The code I have written successfully adds and resets checkboxes, but I am encountering an issue when trying to remove them. I am struggling to identif ...

What is the procedure for inserting comments into inline CSS?

You know, I've been wondering how to effectively comment out inline CSS styles within HTML tags. Is it best to use the /* */ comments from CSS? Or should we opt for <!-- --> in HTML? <span class="color_dark" style="top:20px;font-size: 17px;l ...

Utilize API or alternative methods for analyzing Instagram data

My master's thesis requires me to dissect multiple Instagram profiles, each containing over 1000 posts. I am in need of a comprehensive list including the following details: Type of Post (Image, Multi Image, Video) Description Likes Comments (total c ...

Is it possible to identify a click that is being held without any movement?

Check out the code snippet below: doc.on('mousedown', '.qandacontent', function() { timeout_id = setTimeout(menu_toggle.bind(this), 1000); }).bind('mouseup mouseleave', function() { clearTimeout(timeout_id); }); If y ...

Trouble with executing two asynchronous AJAX calls simultaneously in ASP.NET using jQuery

When developing a web application in asp.net, I encountered an issue with using jQuery Ajax for some pages. The problem arose when making two asynchronous Ajax calls - instead of receiving the results one by one, they both appeared simultaneously after the ...

What is the method for sending an AJAX request with a dynamically looping ID number parameter in the URL

I am looking to make multiple AJAX calls with a loop parameter named [id] in the URL, starting from request.php?id=1 and ending at id=9. I want to send each call after a 3-second delay. As a JavaScript beginner, I'm unsure of where to begin implementi ...

Testing a subordinate function within the main method that involves HTTP request authorization

Dealing with a tricky situation here, hoping for some guidance. So I'm working with a main method that serves as an api endpoint. This method calls another function to check if the user is authorized to access this endpoint or not. The sub-method, r ...