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:
The exact heights of the columns cannot be predetermined due to dynamic content
The RIGHT column must consistently display a background color that extends to the footer
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)