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

Align two grid columns in the centre of the footer

I have a question regarding the alignment of two grid columns in my footer. I am using Bootstrap 4 and would like to center them directly in the middle. Currently, both columns are centered individually but there is a large space between them. I have tried ...

Update the iframe URL to direct the user to a new tab instead of opening a popup

I have created the following script, but I am facing a challenge as I realize that the URL I want to use opens in a new tab instead of just forwarding: <script> function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.sp ...

Implement a mouseenter event to all input elements that have specific names stored in an array, utilizing jQuery

I'm struggling to figure out how to apply my function to all input elements with a name that is included in my array. This is what I've attempted so far: var names = ["name1", "name2"]; $(document).ready(function(){ $('input[name=names[ ...

Exploring Next.js: A Guide to Implementing Browsing History in Your Application

Struggling to add entries to browser history when using Next.js's Link property for page navigation. Unable to push history entry, leading to incorrect page location in my application when going back. Any ideas on implementing this feature in Next.js? ...

What is causing the consistent error message "unable to read property 'logged' of undefined"?

Here is the code snippet from my app.js: var express = require('express'); var path = require('path'); var favicon = require('serve-favicon'); var logger = require('morgan'); var cookieParser = require('cookie- ...

Display a webpage containing error messages and user input that can be sent back to the AJAX request

My form collects user information such as name, surname, etc. Here is an example of one input field: <div class="form-group"> <label for="name">Name</label> <input type="text" class="form-control" id="name" name="name" value= ...

"The Ajax function for replacing a div upon change event is not functioning properly

I am having an issue with my select box using the onchange event, <select class="form-control" onchange="getval(this.value,'<?php echo $prd->pr_id;?>','ajax<?php echo $key?>','<?php echo $key ?>')"&g ...

What is the best way to output my PHP code into separate div elements?

I am attempting to place the prints generated by this PHP code into separate HTML divs so that I can customize them using CSS. However, everything is currently being printed into a single div named "body" with the class "hasGoogleVoiceExt". <?php class ...

Best practice in TypeScript for handling an Enum with a switch-case to assign a variable

Here's an issue I'm facing: I have a variable called Difficulty that is an Enum. Within a function, I need to set the configuration DifficultyConfig based on the value of Difficulty. The current solution I have in mind seems overly complicated: ...

How to troubleshoot Path Intellisense in VScode when using jsconfig.json for Next.js

In the structure of my project, it looks like this: jsconfig.json next.config.json components |_atoms |_Button.jsx |_Button.module.scss |_... |_... ... Within the jsconfig.json file, I have specified the following settings: { ...

Using NodeJS Script in conjunction with Express and setInterval

Feeling stuck and unable to find clear answers for the best solution. I have a Node.js app that serves APIs with MongoDB as the database. I created a setInterval within the request to update the data every 30 seconds. This was done to prevent the Node.js ...

Choose to either check or uncheck boxes using ReactJS

After successfully creating a function to select either single or multiple boxes, I encountered an issue with the "Select all" feature. Any suggestions on how to resolve this? (I'm utilizing the material-ui library for my checkboxes, which are essenti ...

|Webview|Best Practices for Integrating Upload Script

I am currently developing an Android app using WebView and I need to implement a code for uploading on Android. I came across the following code snippet and I want to convert it into JavaScript instead of Java (if possible). It needs to be linked to the up ...

Leverage the Axios package to make requests within a for loop

I'm new to JavaScript and currently working on a project using Vue.js, Axios, and the API available at . The goal of this project is to retrieve NBA player statistics for a homework assignment. I could use some assistance in addressing certain issues. ...

What is the best way to use jQuery to animate a particular height up to 100%?

To provide a sneak peek of the content in the div, I have minimized it so only the first line is visible. Now, I want to add an animation that will expand the div to 100% height when you click the title. However, using animate(height:"100%") does not res ...

Having trouble with getting v-cloak to function properly when dealing with asynchronous requests

I wanted to explore using the v-cloak directive to showcase a loading spinner while certain data properties in vue js are being loaded asynchronously for me to integrate into a table component. After successfully applying and styling my v-cloak styles on ...

When two elements overlap, adjust their CSS positions to ensure responsiveness

Is there a way to adjust the position of an element when it comes into contact with another? Check out this example http://jsfiddle.net/mZYR8/1/ In the example, if .title-wrap (yellow) touches .right-wrap (orange), I want the orange element to slide unde ...

Troubleshooting: Datepicker not appearing in Bootstrap

Here is the detailed markup for the datepicker component: <div class="form-group row"> <div class="col-xs-3 col-md-offset-9"> <label class="control-label">Pick Date</label> <div class="input-group date" id="dp3" data-d ...

Clearing hoverIntent using jQuery

In my scenario, I have three items identified as X, Y, and Z. The functionality of hovering is controlled by the hoverIntent. When I hover on item X, a tooltip is displayed using the following code: jQuery('.tooltiper').hoverIntent({ ove ...

Delete a designated section from a URL with the power of jQuery

I have a URL like http://myurleg.com/ar/Message.html and I need to change ar to en in it when clicked on. For example, if my current URL is: http://myurleg.com/ar/Message.html After clicking, it should become: http://myurleg.com/en/Message.html I attemp ...