a unique approach for creating an elastic multicolumn design with full scroll height background color, free from any pre-scripted solutions

The challenge of dealing with a common CSS issue has led me on a search for a suitable solution. Despite finding numerous partial fixes, none have met my exact requirements.

Previously, I relied on a JavaScript workaround to address the problem. However, I encountered issues with browser caching when using iframes and preloading them before executing the CSS adjustment code. Even though I set the src attribute of the iframes after the CSS fix, the appearance was still distorted while the iframes loaded. While there may be a solution to this specific problem, I appreciate a CSS-only approach that can effectively meet my needs.

Therefore, I am seeking advice on how to create multiple columns of content, each with elastic (percentage) width and height, featuring background colors that extend all the way to the bottom of the scroll height. This should include reaching the bottom of the page in cases where there is minimal or no content, eliminating the need for JavaScript.

Answer №1

Tested in both Firefox and Chrome browsers. Check out the jsFiddle demo here: http://jsfiddle.net/4JBBT/4/

This solution I came up with may only be partial if you're looking to use a background image instead of a solid color. In that case, the image would need to remain fixed while the content scrolls over it.

I haven't seen this specific approach before, but someone else may have thought of it already. If you have any suggestions for improvement, please share them as I'm not an expert in CSS.

To implement this solution, create empty divs for each column with their respective background colors (or images) using the following structure:

    <div id="leftbg"></div>
    <div id="rightbg"></div>
    <div id="middlebg"></div>

The CSS styling for these background divs is as follows:

#leftbg
{
    background-color: green;
    height: 100%;
    width: 14%;
    position: fixed;
    top: 0;
    left: 0;
}
#rightbg{
    background-color: blue;
    height: 100%;
    width: 24%;
    position: fixed;
    top: 0;
    right:0;
}
#middlebg{
    background-color: red;
    height: 100%;
    width:62%;
    position: fixed;
    top: 0;
    right: 24%;
    left: 14%; 
}

Ensure that the positioning values relate correctly to one another, such as the width of `leftbg` matching the `left` value of `middlebg`.

Next, float content containers above the background divs, like so:

<div id="leftcontainer">
    <div id="leftcontent"><p>hello</p></div>
</div>

<div id="middlecontainer">
    <div id="middlecontent"><p>hello</p></div>
</div>

You can have more complex content within these containers, and they will scroll independently over the fixed background colors.

CSS styling for the content containers:

#leftcontainer{
    width: 14%;
    position: relative;
    float: left;
}
#middlecontainer{
    width: 62%;
    position: relative;
    float: left;
}

Ensure the widths match those of the background divs. The content and containers should have no background, allowing them to float over the backgrounds.

If the content divs are kept relatively positioned, each column can effectively behave like a separate page.

Answer №2

Utilizing the Flexbox technique (Flexible Box Layout Module). Check out an example at http://example.com/flexbox-example.

For more in-depth information on Flexbox, visit

You can also explore a great collection of resources on Flexbox by Chris Coyier here: http://css-tricks.com/snippets/css/a-guide-to-flexbox/

It's important to note that although browser support for Flexbox is generally good, it may not be complete and could require fallbacks. Some experts suggest caution when using Flexbox for complex page layouts due to potential complications with nested flexboxes.

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

Can you explain the distinction between [att|=val] and [att~=val] in css?

Could someone help me differentiate between the [att|=val] and [att~=val] attributes in CSS? I'm having trouble grasping the concept. Thank you! ...

The contact form is encroaching on the footer

The issue arises when the contact form overlaps with the footer. When testing the code on Codepen, the styles are correctly linked and working for everything except the contact form. I have attempted adjusting the padding, bottom position, etc., but nothin ...

Troubleshooting: Django update causing issues with CSS background image display

Recently, I made an upgrade to my Django 1.10 (Python 3.5) app to Django 1.11 (Python 3.6). Most of the functionalities are still intact, however, I am facing a peculiar issue where my CSS background images are no longer rendering (even though they work fi ...

Utilizing z-index and position in CSS for a clean separation between design and functionality!

I have been experimenting with the yui-grids css framework, utilizing three columns. I am placing all the decorative design elements in the left column and centering them using z-index and relative positioning. In the center column, I am focusing on more ...

Modify the default color selection tool

I am utilizing Angular6 with material-designs. My aim is to obtain color input from mat-form-field. I achieved this by using matinput type="color" within my input tag. Below is a snippet of my HTML file, <div> <mat-form-field class="fo ...

Guide to Styling List Items with Icons and Titles

Is it possible to align two elements to the left and two to the right within a list item (li)? The li is part of a page utilizing Bootstrap framework and FontAwesome project. You can see an example here: Below is the code for the li: <li class="list ...

Fade in and out of page or div elements with a simple click

I've been dedicating some time to my recruitment website lately. As a beginner in coding, I'm looking for a script that will automatically fade out the Employment review content when clicking on each employment vacancy div and then fade back in w ...

Activate the function within the same class only for the selected item

Hello there, I'm struggling to grasp how to make this particular functionality work. Basically, I have 8 divs, each containing an image used as a button with the same class (tm-img), and hidden divs with additional information. My goal is to initiall ...

The CSS slide effect is causing an overlap with the sticky top menu bar

When scrolling, the goal is to have the menubar stick as the second div with the other divs going under it. However, only the third div, the sliding banner, is overlapping with the sticky menubar while the others are functioning correctly. Is there anyone ...

I need to implement a div-based dropdown with a scrollbar in JavaScript and CSS to prevent it from extending beyond the screen. Additionally, the use of struts is essential in this implementation

Dealing with a dynamically populated div-based dropdown can be tricky, especially when it extends beyond the screen's limits and hides entries. This is an inherited application that lacks support, leaving me to handle it without the necessary expertis ...

Issue with border styling in Material-UI vertical ToggleButtonGroup

In my current front-end project, I have implemented the React Material UI ToggleButtonGroup. For a Multiple Selection example with vertical styling, you can refer to this code snippet: https://codesandbox.io/s/eyk66?file=/demo.js However, I encountered a ...

Which is better: CSS gradients or background images?

Years ago, I came across many CSS codes that used background-image: url(xxx.png) to mimic a gradient background filter, as only (please correct me if I'm mistaken) IE's proprietary filter could achieve a CSS gradient. In today's world - giv ...

How to align an image in the middle using Bootstrap and React

Having an issue with Bootstrap and aligning an image in the center. Currently, the image is appearing left-aligned: Here is the HTML: <div className="App vh-100"> <div className="d-flex h-70 border border-white container"> <div class ...

Resizeable drag and drop two-column design

Experimenting with creating a drag re-sizable layout using jQuery UI was quite an interesting challenge for me. If you want to check out the result, here is the link. However, my original goal was to achieve something different from what I ended up with. ...

Utilizing offsets/push in the correct manner

I have been developing a Bootstrap website and I wanted to get some feedback on my current code structure. The design is coming along nicely, but I am unsure if this aligns with best practices? <div class="container-fluid"> <div class="row"> ...

Having trouble getting this JavaScript query to function properly

The initial div in the code snippet below showcases the name of a university. When this name is clicked, it activates the function display_people(). This function is responsible for displaying or hiding the individuals associated with that university. The ...

Vuetify's offset feature seems to be malfunctioning as it does not

I'm facing an issue with the <v-flex> element in my code, specifically with the offset property not responding as expected. Despite following the recommended layout from the vuetify docs, I can't seem to get it right. Below you can see the ...

What steps are needed to achieve the hover effect on the portfolio page?

Looking to add a unique hover effect to my homepage design. Here's an example of what I'm envisioning: https://i.sstatic.net/Sx5Ge.jpg Can someone help troubleshoot my code? It's not quite working as intended. .stage_wrapper { margin ...

Adding and sorting div elements from an external HTML file

Greetings everyone, I have recently delved into the world of coding and am currently working on a project for my course to streamline access to information and data in my daily life. So far, I have created a single HTML file and two additional external HT ...

Tips for obtaining the XPath for an unordered list and a span element

My goal is to find the xpath that will select the seat "12A" from a webpage containing a list of seats. Here's the source code: <div class="seats" style="top: 48px;"> <ul class="row_12 leftOfAisle"> <li><a class="" data-r ...