Fluid center with fixed left and right columns in a responsive 3-column CSS layout

I'm striving to design a layout with three columns, where the left and right columns are static while the center column is flexible.

This can be achieved using display table and table cell, or by altering the order of columns in HTML. However, both options complicate the responsive layout. Specifically, when the screen width is below 1024px, the third column should move underneath the second column while the first column remains unchanged. Furthermore, when the width is reduced to under 500px, all content should transition into a single vertical column.

Additionally, each column's height must match the tallest column as they will have different backgrounds.

Assume we have the following structure:

#left {
  width:200px;
  position:absolute;
  top:0;
  left:0;
  background-color:red;
  height:100%;
}

#middle {
  margin-left:200px;
}

#right {
  width:200px;
  position:absolute;
  top:0;
  right:0;
  background-color:blue;
  height:100%;
}
<div id="content">
  <div id="left">
    LEFT FIXED
  </div>
  <div id="middle">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tristique tellus vel lorem efficitur ornare. Maecenas sit amet commodo velit, at eleifend est. Cras luctus orci vitae erat maximus rutrum. 
  </div>
  <div id="right">
    RIGHT FIXED
  </div>    
</div>

Is there a way to achieve a fixed left, fluid center, fixed right setup without using display table or reordering columns?

The recommended solutions often involve utilizing display table or rearranging the source order, which I prefer to avoid.

Answer №1

To address the issue of text hiding behind in your middle id, I have added the CSS property "margin-right:200px;".

Additionally, I have implemented two Media queries to cater to your specific requests.

CSS:

#left {
        width: 200px;
        position: absolute;
        top: 0;
        left: 0;
        background-color: red;
        height: 100%;
    }

    #middle {
        margin-left: 200px;
        margin-right: 200px;
    }

    #right {
        width: 200px;
        position: absolute;
        top: 0;
        right: 0;
        background-color: blue;
        height: 100%;
    }

    @media screen and (max-width:1024px) {
        #right {
            width: 100%;
            margin: 0;
            top: 300px;
            left: 0;
            right: 0;
            height: 100px;
            position: absolute;
        }
        #left,
        #middle {
            height: 300px;
            top: 0;
            position: absolute;
        }
    }

    @media screen and (max-width:500px) {
        #left,
        #right,
        #middle {
            width: 100%;
            margin: 0;
            left: 0;
            right: 0;
            top: 0;
            height: 100px;
            position: relative;
        }
    }

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

Place div element on top

In my table cell, I have a link that reveals a hidden div when clicked. At the moment, I am using position: absolute and z-index:10 for this setup. It functions properly, but I want to adjust it slightly towards the top and left. However, when I include t ...

Sleek CSS Slider with Image Transformation on HoverThe requested task has been

I am currently working with a client on the website . One of the features on the site is a slider at the top that allows for image swapping using pure CSS. However, the client recently requested that the images change when hovering over radio buttons or au ...

The margin of the parent container is influencing the margin of the child element

Purple Working on displaying a rectangle shape in a browser using divs in my React project. Everything works fine, but when I add margin to the parent base and then draw the boxes, there's some space between the mouse cursor and the actual box. The ...

Unable to properly vertically center multiple divs within a parent div and align their elements vertically within them

I'm diving into the world of HTML/CSS and grappling with various concepts. My goal is to vertically align 2 divs within a larger div, as well as center the contents within those divs. HTML: <html> <head> <link rel="stylesheet" typ ...

Transform the look of your bootstrap 5 inputs by making them dark-themed

I have a feature in my app that allows users to switch between light and dark modes. Currently, I am using Bootstrap 5 form-control inputs and want to customize their background color based on the mode selected. Which CSS classes do I need to target in or ...

What is the method for activating or deactivating pointer events for a particular section of an element?

Is it feasible to deactivate pointer events for only a portion of an element rather than the entire element? For instance, as shown in the image below.. https://i.sstatic.net/rnS7M.png Perhaps one could utilize another element to cover the specific area ...

Printing from Chrome is becoming a time-consuming process for this particular webpage

I've been working on creating a print/PDF-friendly template for articles on a WordPress site by customizing the Tufte CSS template. However, I'm facing an issue where the print preview render (and subsequent printing/saving as PDF) is extremely ...

validating forms with an abundance of checkboxes

Currently, I am in the process of creating a checkbox form that consists of more than 200 questions (yes, I know, quite ambitious!). My main requirement is to prevent the user from advancing to the results page unless they have checked at least one checkbo ...

Rearrange the sequence of numbers using JQuery when an HTML element is deleted

I'm currently working on a simple functionality where I have 5 rows, each with its own number. So initially, the rows are numbered from 5 to 1. If I remove a value like 3, the sequence should adjust to 4, 2, 1, indicating that I now have only 4 rows ...

How can we use JavaScript to retrieve an element with custom styling?

I've encountered a strange issue with my script where it seems to stack up borders and display a 2px border instead of the intended 1px border when switching elements on click. Here is the link code I am using: <li ><a href="plumbing.php"&g ...

Ensure that the content in the right column is in alignment with the

The two div elements are colored differently, with the right column (pink) not aligning properly with the left column (green). For reference, here is my fiddle: JSfiddle * { margin: 0px; padding: 0px; border: 0px; } #wrapper { width: 960px; m ...

Place an element in the middle of the svg

I have a D3.js svg element measuring (1000,1000) with a circle positioned randomly, such as (100,200). My goal is to adjust the svg so that the circle is centered at (500,500). I want to create a function that can do this for any randomly positioned circl ...

JS-generated elements do not automatically wrap to the next line

For my first project, I've been working on a to-do list and encountered an issue. When I create a new div with user input, I expect it to start on a new line but it remains stuck on the same line. Can anyone point out where I might have gone wrong? I ...

Are checkboxes embedded within labels?

There are two common ways that people code checkboxes on the web, and I'm wondering which one is considered correct. <input id="a" type="checkbox"/><label for="a">checkbox</label> <label for="b"><input id="b" type="checkbo ...

`After the initial instance, the menu title will be altered.`

I have a responsive menu using Bootstrap. When the menu is collapsed, I want it to display the name of the page, and when it is open, I want it to show "Menu." Currently, I have named it "Watch the Trailer" (so let's assume that we are on that page). ...

What causes the fading effect on my navigation bar when the slideshow is in use?

I recently created a navigation bar at the top of my webpage, placed above a picture slideshow. However, I noticed that as the slideshow transitions between images, the background color of the navigation bar fades to transparent. How can I prevent this and ...

Optimizing Image Fit and Positioning for Different Web Browsers

I have designed a webpage using HTML, JavaScript, and CSS that features a photo carousel allowing users to navigate through images by clicking left and right arrows. The carousel's container is set at 500px tall and takes up 100% width of its parent d ...

"Mastering the art of printing wrapped text with Bootstrap to avoid pesky horizontal scrollbars

My issue is quite straightforward. I am trying to display all content on a web browser without the need for a horizontal scrollbar. <div class="container"> <div class="row h-100" style="overflow-y:scroll; padding-left: ...

Struggling to eliminate the scrollbar on a Material UI Dialog

I have a modal window that includes a keyboard, but I'm encountering some issues. Despite adding overflow:'hidden' as inline CSS, the scrollbar refuses to disappear. Furthermore, even when utilizing container-full padding-0 in Bootstrap, th ...

HTML border width is set to 100%, but there seems to be an issue with the responsive menu border and icon display

One issue I'm encountering with my website involves the border at the bottom of my navigation bar. Despite trying to adjust the box-sizing property to border-box, I still can't get it to display correctly. My goal is to have the border span 100% ...