The CSS sacred trifecta - troubleshooting a layout with 2 fixed columns and 1 fluid column

After putting in some hard work to create a 'holy grail'-style layout for my website, I'm faced with two issues that need fixing.

The main objective is to have a 'sticky' footer that expands along with the height of the browser window, along with a header and 3 columns. The setup includes fixed columns on both the left and right sides, while the middle column should adapt fluidly.

The problems arise from the behavior of the center 'fluid' column which isn't meeting my expectations. My intention is for the fixed columns to always remain fully visible, with the center column filling the remaining horizontal space. However, the center column occupies more room than anticipated, forcing users to scroll to view the right-hand column (as seen in the provided image below). Furthermore, the 'text-align: center' property doesn't seem to be aligning the text within the visible area of the center column as desired. Any assistance would be greatly appreciated!

Image Reference: https://i.sstatic.net/XKU0g.png

HTML Code:

<html>
    <head>
        <link type="text/css" rel="stylesheet" href="test.css" />
    </head>
    <body>
        <div id="header">
            <p>Header</p>
        </div>
        <div id="container">
            <div id="center">
                <p>Content</p>
            </div>
            <div id="left">
                <p>Content</p>
            </div>
            <div id="right">
                <p>Content</p>
            </div>
        </div>
        <div id="footer">
            <p>Footer</p>
        </div>

    </body>
</html>

CSS Styles:

* {
    margin: 0;
}

#container {
    width:100%;
}

#header {
    text-align: center;
    background: #5D7B93;
    height: 95px;
    padding: 5px;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 15;
}
#center{
    text-align: center;
    margin-top: 105px;
    background: red;
    position: relative;
    float: left;
    width: 100%;
    height: 100%;
}
#left {

    height: 100%;   
    width: 150px;
    text-align:center;
    background:#EAEAEA;
    margin-top: 105px;
    margin-left: -100%;
    overflow: scroll;
    position: relative;
    float: left;
}

#right {
    position: relative;
    height: 100%;
    width: 150px;
    margin-right: -100%;
    margin-top: 105px;
    background: blue;
    text-align: center;
    float: left;
}
#footer {
    text-align:center;
    background: #5D7B93;
    height:25px;
    padding:5px;
    position: fixed;
    bottom: 0;
    width: 100%;
}

Answer №1

Avoid using the float property. Instead, utilize position: absolute for the sidebars and apply a fixed margin to the center div.

Check out this JSFiddle example

CSS Styling:

#container{
    position: relative;
}

#left, #right {
    width: 200px;
    height: 100%;
    position: absolute;
    top: 0;
}

#left {
    left: 0;
}

#right {
    right: 0;
}

#center {
    margin: 0 200px;
}

Answer №2

After implementing this code in my layout, I found that everything is working smoothly

body,
html {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

#container{
  display: inline-flex;
  width: 100%;
  height: 100%;
  background: lightblue;
}

#left {
  width: 240px!important;
  min-width: 240px!important;
  background: red;
  height: 100%;
}

#right {
  width: 400px!important;
  min-width: 400px!important;
  background: red;
  height: 100%;
}

#center {
  background: blue;
  width: 100%;
  min-width: 600px;
  height: 100%;
}

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

Changing the background color of the dropdown button in Vue Bootstrap: A step-by-step guide

I've been struggling to modify the background color of a dropdown button, but no method seems to work. I've attempted changing it by using ID, removing its class and applying a new one, and even using !important to override the styles, but the ba ...

Is there a way to insert a space in a single iteration of an SQL query in PHP without impacting the others?

Is there a way to add a space between two words for certain iterations of an SQL query without affecting all uses? I attempted using CSS margins, but it didn't have the desired effect. Here is a snippet of the code I am currently working on: <div ...

Explore the feature of toggling visibility of components in Vue.js 3

I am facing an issue with showing/hiding my sidebar using a button in the navbar component. I have a navbar and a side bar as two separate components. Unfortunately, none of the methods I tried such as v-show, v-if, or using a localStorage value seem to wo ...

Implementing a Basic Div Overlay Effect

There is a Div with the id of "placeholder" located in a table cell, containing three nested divs with ids of "content1," "content2," and "content3." I would like these nested divs to match the size of their parent, "placeholder," and overlap each other. ...

PHP is having trouble identifying the file extension for file uploads

After sending an array through AJAX and echoing it in PHP, I have the following data: [file] => Array ( [name] => XXXX.jpg [type] => image/jpeg [tmp_name] => D:\xampp\tmp\phpC5F2.tmp [error] => 0 [size] = ...

Styling a modal popup using session storage in CSS

I recently created a modal popup using CSS by following a helpful tutorial that can be found at this link: Now, I am curious about how to store the value entered in a textbox as session data. I came across some code in another tutorial that demonstrated h ...

Adding new divisions to an already existing division with angled borders

I am currently attempting to create a header similar to the one displayed in the attached image. Despite trying various solutions found on this platform, I have not been able to achieve the desired result. I have managed to work out the text and logo eleme ...

Steps to create a clickable button wrapper label in React

Contained within the components below: <CheckboxGroupLabel htmlFor={option.label}> <FormCheckbox onClick={() => onChange} key={option.label} defaultChecked={defaultChecked} {...rest} /> {option.value} ...

Focus on the iPad3 model specifically, excluding the iPad4

I am looking to apply specific CSS that works on iPad 3, but not on iPad 4, or vice versa. Currently, I am able to target both versions by using the following code: @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and ( m ...

duplicate styling for individual table cells

I am in need of a span element inside a td tag that I am generating within a table. In order to ensure the span fills the td, I have set it as an inline-block with a width and height of 100%. However, when pressing the delete key in the last cell, it star ...

What is the best way to display a multi-level sub-menu in front of its parent menu?

Code: nav#desktop-nav ul li > ul { position: relative; margin-top: 0; text-align: left; opacity: 0; visibility: hidden; position: absolute; top: 100%; transform: scaleY(0); transform-origin: 0 0 0; transition: al ...

Retrieve the information in a div element from an external website by utilizing AJAX

Exploring the world of AJAX is new to me, and I am eager to fetch content from a div on an external site and display it on my own website. Below is the current code snippet I have: <html> <head> <script src="https://ajax.googleapis.com ...

What is the process for updating button text upon clicking in Angular?

To toggle the text based on whether this.isDisabled is set to false or true, you can implement a function that changes it when the button is clicked. I attempted to use this.btn.value, but encountered an error. import { Component } from '@angular/core ...

What is the best way to shade a webpage and showcase a floating, engaging box at the same time?

I have noticed a common trend of websites using this attention-grabbing effect. Are there various methods to achieve this? Is there a popular JavaScript library designed specifically for this purpose that is widely utilized? Additionally, how can I impleme ...

Tips for accessing the names of subdirectories and files on a website

If we have the URL, is it possible to access the names of the files within the parent directory? Similar to how we can do in DOS by using the command "DIR" to view the list of files inside a folder. For example, if we have a URL like , I am curious to kno ...

Leverage AJAX variables directly within the HTML page

In my application, I have incorporated an Input type="date" field to capture date values from users. However, I need to send the value of the date as "sdate" in the URL used in the action method, as illustrated below. My goal is to post the value of the In ...

Combine less files in webpack to generate a single minified CSS output file

Can webpack be used to combine multiple less files into one minified CSS file? I'm having trouble setting different output paths for my files. How can I make my CSS file output to './assets/stylesheets/bundle/' instead of './assets/ja ...

How do you identify a Selenium element using a CSS selector?

Having trouble locating the element for "Sign out" button in Selenium. I've tried using the following CSS identifier: css= div[class='sub-nav chat-bubble']>ul>div:nth-child(3)>li:nth-child(4)>a Could someone please help me modi ...

Add a div element only if there is a background image present

I am facing a situation where I need to display an image as the background of a div only if it is available. If the image is not present, I do not want the div to be visible at all. I am working with django templates and here is my current approach: {% if ...

Display PHP output within a styled CSS box

<html> <head> </head> <style type="text/css"> .yellow-box { position:absolute; top:100px; left:500px; width:300px; height:300px; background:yellow } </style> <div class = "yellow-box" > </div ...