A webpage featuring a 2-column layout with a footer, along with a right column that is absolutely positioned and

I'm currently working on a basic two-column layout:

<div class = "parent">
   <div class = "left-column">
   </div>
   <div class = "right-column">
   </div>
</div>
<div class = "footer"></div>

The content in each column is dynamic, so it's impossible to predict the height of either column beforehand. However, there's a specific requirement that the RIGHT column must have a background color that always extends to the bottom of the page, regardless of its height compared to the left column.

To achieve this, I set the "parent" position:relative, and applied the following styles to the "right-column":

.right-column {
   position:absolute; 
   height: 100%; 
   right: 0px; 
   background-color: blue;
}

For the full code and implementation, you can view the JSFiddle link here: http://jsfiddle.net/gsmbzaz9/1/

However, there are several issues with this approach.

Firstly, setting height: 100% on the <body> or <html> means it will be based on the screen height, not the overall page height. As a result, positioning elements like the footer using bottom: 0 will apply to the screen bottom, rather than the entire page.

Secondly, if the right column is taller than the left one, the overflowing content spills out of the parent div, causing the blue background to get clipped.

The desired layout I'm aiming for is as follows:

+------+-------+
|      |       |
| LEFT | RIGHT |
|      |       |
+------+       |
       |       |
       |       |
+--------------+
|    FOOTER    |
+--------------+

In cases where the LEFT column is taller than the RIGHT, the blue background behind RIGHT should still extend properly, even if the content overflows into the footer area.

This layout setup seems to be quite common, but achieving it has proven tricky. While searching online for solutions regarding footer positioning, most techniques do not address the complications introduced by absolutely positioned columns outside the document flow.

Therefore, I'm seeking CSS techniques to accomplish this particular layout while considering the following requirements:

  1. The exact heights of the columns cannot be predetermined due to dynamic content

  2. The RIGHT column must consistently display a background color that extends to the footer

  3. The footer needs to remain anchored at the bottom of the page (not just the screen) and become visible only when scrolling down completely to the end of the content (or when there are no scrollbars due to small content)

Answer №1

Let's explore one approach to achieve this, focusing on the key properties utilized:

box-sizing:border-box -------- padding ----- display:table-cell ----position:relative for footer --

Initial Code Snippet with Minimal Content

* {
  margin: 0;
  padding: 0
}
html,
body {
  height: 100%
}
#cont {
  box-sizing: border-box;
  padding-bottom: 70px;
  display: table;
  width: 100%;
  height: 100%;
}
.footer {
  position: relative;
  top: -70px;
  height: 70px;
  z-index: 10;
  background: red;
}
.left-column > div {
  background: blue;
  padding: 20px;
  color: white;
}
.right-column {
  background: orange;
}
.left-column,
.right-column {
  box-sizing: border-box;
  min-height: 100%;
  display: table-cell;
  width: 50%;
}
<div id="cont">
  <div class="left-column">
    <div>
      <h1>Content</h1>
    </div>
  </div>
  <div class="right-column">
  </div>
</div>
<div class="footer"></div>

Modified Snippet with Abundant Content and Scrollbars Included

* {
  margin: 0;
  padding: 0
}
html,
body {
  height: 100%
}
#cont {
  box-sizing: border-box;
  padding-bottom: 70px;
  display: table;
  width: 100%;
  height: 100%;
}
.footer {
  position: relative;
  top: -70px;
  height: 70px;
  z-index: 10;
  background: red;
}
.left-column > div {
  background: blue;
  padding: 20px;
  color: white;
}
.right-column {
  background: orange;
}
.left-column,
.right-column {
  box-sizing: border-box;
  min-height: 100%;
  display: table-cell;
  width: 50%;
}
<div id="cont">
  <div class="left-column">
    <div>
      <h1>Content</h1>
      <h1>Content</h1>
      <h1>Content</h1>
      <h1>Content</h1>
      <h1>Content</h1>
      <h1>Content</h1>
      <h1>Content</h1>
      <h1>Content</h1>
      <h1>Content</h1>
      <h1>Content</h1>
      <h1>Content</h1>
      <h1>Content</h1>
      <h1>Content</h1>
    </div>
  </div>
  <div class="right-column">
  </div>
</div>
<div class="footer"></div>

Answer №2

Check out this fiddle here

I decided to incorporate a bit of JavaScript for the solution.

Now, according to your specifications, the 2 columns are perfectly aligned with the footer consistently positioned at the bottom of the divs (not the window), and the right column always extends to the full height up to the footer.

Hopefully, this provides some assistance

Here is a snippet of the code....

function adjustHeight() {
  leftHeight = $(".left-column").outerHeight();
  rightHeight = $(".right-column").outerHeight();
  if (leftHeight >= rightHeight) {
    $(".right-column").outerHeight(leftHeight);
  }
}

adjustHeight()

$(window).on('resize', function() {
  adjustHeight()
})

$(window).on('load', function() {
  adjustHeight()
})
h1 {
  padding: 20px;
}
.left-column {
  float: left;
  background: red
}
.right-column {
  float: right;
  background: blue;
}
.clearfix {
  clear: both;
}
.footer {
  background: aqua;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

<body>
  <div class="parent">
    <div class="left-column">
      <h1>Content</h1>

      <br/>
      <h1>Content</h1>

      <br/>
      <h1>Content</h1>

      <br/>
    </div>
    <div class="right-column">
      <h1>right</h1>
      <br/>
      <!-- remove these to see the height adjust -->
      <h1>right</h1>
      <br/>
      <h1>right</h1>
      <br/>
      <h1>right</h1>
      <br/>
      <h1>right</h1>
      <br/>
      <h1>right</h1>
      <br/>
      <h1>right</h1>
      <br/>
      <h1>right</h1>
      <br/>
      <h1>right</h1>
      <br/>
      <h1>right</h1>
      <br/>
      <h1>right</h1>
      <br/>
      <h1>right</h1>
      <br/>
      <h1>right</h1>
      <br/>
      <h1>right</h1>
      <br/>
      <!-- remove these to see the height adjust -->
    </div>
  </div>
  <div class="clearfix"></div>
  <div class="footer">
    <h1>FOOTER</h1>

  </div>

Answer №3

Utilizing jquery, this solution addresses various requirements. A link to the solution can be found here. The key specifications taken into consideration are as follows:

- Ensuring the right column extends to the bottom of the scrollable page, regardless of content length compared to the left column.

- Avoiding the use of absolute positioning.

- Placing the footer at the bottom of the page.

- Setting a minimum height for the right column so it reaches the bottom of the window.

CSS:

h1 {
    padding: 20px;
}
.left-column {
    width: 50%;
    display:inline-block;
    /* background-color: blue; */
}
.right-column {
    width: 50%;
    min-height: 100%;
    display:inline-block;
    float: right;
    background-color: lightblue;
}
.footer {
    text-align: center;
    width: 100%;
    display:inline-block;
    /* background-color: yellow; */
}

Jquery:

var leftHeight = $('.left-column').height();
var rightHeight = $('.right-column').height();
var windowHeight = $(window).innerHeight();
var footerHeight = $('.footer').height();

console.log(leftHeight, rightHeight, windowHeight);

if(leftHeight > windowHeight && leftHeight > rightHeight) {
    $('.right-column').height(leftHeight);
}
if(windowHeight > leftHeight && windowHeight > rightHeight) {
    $('.right-column').height(windowHeight - footerHeight);
}

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

What is the best way to showcase a photo selected using an HTML input within a div container?

My goal is to select a photo from a folder and display it on a webpage, but I have struggled to find a working solution. Can this be achieved using just basic HTML, CSS, and JS? I am new to web development, so please forgive me for any beginner questions. ...

"Interactive table feature allowing for scrolling, with anchored headers and columns, as well as the option to fix

I'm in need of a table that has certain requirements, as shown in the image. https://i.stack.imgur.com/Z6DMx.png The specific criteria include: The header row (initially blurred) should remain fixed when scrolling down the table The first column s ...

The smooth scroll feature is not functioning properly on the animated mouse-scroll down button

I've recently added an Animated Mouse Scroll Down button on my website. However, when I click the button, the smooth scroll feature is not working as expected. Important Note: I already have a separate button for navigating to the next section where ...

Splitting a list of accordions into two columns with CSS and React - a step-by-step guide!

I am looking for a way to showcase a list of Accordions in a two-column layout. Each Accordion consists of both a Summary and Details section, with the Details being visible only when the Summary is clicked. Unfortunately, I won't delve into the imple ...

"Troubleshooting a Animation Problem in the Latest Version of

I have discovered an issue with animations on the latest version of Firefox Quantum. Upon loading a page with certain animated elements set to display: none;, when a script changes it to .display = "block";, some parts of the animation may be missed or no ...

Exploring the ways to access inner contents of a Div element using ajax

Looking to update the SQL database with a list of variables sent from an HTML page. Some data is being sent correctly, while others are not. The list is placed in a div divided into two parts: "h1" and another "div". The header data is being sent correctly ...

Ensuring that the text-box is the same size as the image

I am encountering two challenges: When scaling the window down horizontally, I am facing an issue with aligning the images on the left (sideImage) vertically with the text box. I have attempted using margin-top auto and margin-bottom auto, but that doe ...

Is it possible to send an email with an attachment that was generated as a blob within the browser?

Is there a way to attach a file created in the browser as a blob to an email, similar to embedding its direct path in the url for a local file? The file is generated as part of some javascript code that I am running. Thank you in advance! ...

Is it possible to preview and print a markdown file as a PDF in VS Code using a custom CSS stylesheet?

Let me explain my scenario: I am looking to create a formatted markdown document (such as my CV) and apply a customized style using a CSS file. Afterwards, I aim to generate a PDF version of this document. In order to achieve this, I have integrated the ...

Tips for incorporating additional filter criteria into a jquery script

I am currently utilizing a jQuery script to filter data based on date periods. However, I now need to include an additional filtering criteria for the "POSITION" column. Since I lack expertise in jQuery, I would rather accomplish this using plain vanilla J ...

Preventing further onClick events from occurring ensures that any new onClick events will not be triggered as well. To achieve

In the process of developing a script, I've encountered a situation where the original developers may have implemented event prevention or some other mechanism to block any additional clicks on certain table td elements. Even though their click trigge ...

Creating an effect where an image gradually enlarges from its midpoint

A little while ago, I submitted a query about how to adjust the size of an image using the input type="range" feature. To my delight, user Prisoner provided me with a fantastic solution: <input id="ranger" type="range" min="1" max="100" value="100" /&g ...

Vue 3 has officially deprecated the use of ::v-deep as a combinator. Going forward, please utilize ::v-deep(<inner-selector>) instead

Recently, an error message has been popping up in Vue 3 regarding the use of ::v-deep. The warning states that using ::v-deep as a combinator is deprecated. Instead, it recommends using ::v-deep(<inner-selector>) Here is an example of the CSS ...

Tips for utilizing CSS flexbox to create a row of squares that can scale while maintaining their aspect ratios

Struggling with this issue has me on the verge of pulling my hair out. It seems like a simple task, yet I can't seem to achieve perfection. My goal is to create a row of squares that maintain their aspect ratio but scale down in size as their containe ...

What's the significance of this issue? Fatal error: Inability to utilize function return value in write context

An error occurred while processing the PHP code Severity: Compile Error Message: Unable to use function return value in write context line number:116 floor($BudgetPerPerson) = $TotalBudget / $NumberOfPeople; label class="heading">What ...

Trigger the running of a python script by clicking a button

On my HTML page, there is a single button that is supposed to trigger the execution of a python script upon being clicked. The goal is to receive the result of the script and display it on the same HTML page. The process involves validating the return val ...

Encountering an error of "undefined is not iterable, cannot read property Symbol(Symbol.iterator)"

While learning React through coding, I encountered an error (Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)). I am unsure where the problem lies. Any suggestions? When utilizing useEffect to activate setFiltere ...

Revamp the UI Framework's CSS to accommodate the latest Web Components

I've implemented Grommet as the UI Framework for my React page. However, I encountered a situation where certain web components, like a web chat control, are not covered by Grommet's CSS. What is the simplest way to style these additional web com ...

Issues arise with Bootstrap's navbar dropdown menus, rendering them inoper

Currently I am developing a bootstrap website using the "Butterfly" template. Everything is functioning properly except for the navbar when viewed on mobile devices. The dropdown menu fails to open on mobile devices, and I suspect it might be related to th ...

Tips for creating space between a label and radio button in Bootstrap 4

I attempted to use this solution as suggested, but unfortunately, it did not yield the desired results. I seek advice on how to achieve the intended outcome. <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="s ...