The HTML code starts with a fluid middle column in a 3-column layout, while the other two columns have fixed widths

I am interested in creating a traditional 3-column layout similar to this:

|  |      |  |
|L |  M   |R |
|  |      |  |

I have been tasked with using the following html structure: as depicted, the Main div is the initial node of #container

<body>
  <div id="container">
    <div id="M">Main</div>
    <div id="L">Left</div>
    <div id="R">Right</div>
  </div>
</body>

Is there a way to achieve this layout with and without the use of css3 new features?

UPDATE: #L and #R have a set width of 200px. #container shares the same width as the window (excluding body margin) and #M's left border connects with the right border of #L, while #M's right border connects with the left border of #R.

Answer №1

Here is my strategy for achieving this specific layout.

#M {
  width: 60%;
  height: 500px;
  margin: 0 auto;
  background: brown;
  position: relative;
  top: 0;
}

#L {
  width: 20%;
  height: 500px;
  position: absolute;
  top: 0;
  left: 0;
  background: #c1c1c1;
}

#R {
  width: 20%;
  height: 500px;
  position: absolute;
  top: 0;
  right: 0;
  background: #c1c1c1;
}

This method ensures that the layout is fully responsive. However, if a fixed width for the outer divs is preferred, that can also be implemented.

JSFIDDLE

Answer №2

Could we achieve something similar to this example?

#A {
  display:inline-block;
  background:blue;
  width:33%;
}


#B {
  float:right;
  display:inline-block;
  background:green;
  width:33%;
}


#C {
  float:left;
  display:inline-block;
  background:orange;
  width:33%;
}

Answer №3

Note: It is actually feasible to achieve this using flexboxes. However, compromising browser compatibility for the sake of markup order might not be ideal.

Unfortunately, this solution does not accommodate the presence of the #M element at the top. Unless we resort to some clever positioning tricks, I don't see how this can be achieved.

If we were to relocate the #M element to the bottom, the following code would be applicable:

#M {
    background-color: #eeffff;
    height: 200px;
    margin: 0 200px;
}
#L {
    background-color: #ffeeff;
    float: left;
    height: 200px;
    width: 180px;
}
#R {
    background-color: #ffffee;
    float: right;
    height: 200px;
    width: 180px;
}

In such a scenario, unless the parent container has a fixed width, the middle section would be flexible while the left and right sections remain static. Alternatively, you could specify the margin and width of the #L and #R elements as percentages.

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

Conceal the div element when located beneath an ordered list with a designated

I need help hiding the display of comment information if it is a child comment. Below is my attempt to hide the div with the id "info" if the "ol" element has a class of "children". If you have another method for hiding the div when the comment is a chil ...

Revamp the Bootstrap Form Upload feature

I am looking to redesign the Bootstrap Form Upload field. The main reason behind this is that in Bootstrap, the file upload field is treated as one single component, making it impossible to separate the file upload button from the file upload text. The fi ...

Ensure uniform height for images in the absence of specific dimensions

Is there a solution to ensure that images of different sizes have the same height on a card? The issue is that the content is dynamic and coming from a CMS, so I don't know in advance what the image size will be or how much text will be in the card. & ...

Press the "Reveal More" button to expand the content to its full size

I am currently working on coding a "read more" section using a button. I have looked at some existing solutions, but none of them are to my liking. My plan is to create a div that includes all the relevant content. My goal is to have a div at the bottom w ...

Let's talk about the CSS properties for centering content and automatically

I've been struggling with getting my navbar to center and adjust its width based on the content inside. Can anyone help me with this? <nav> <ul id="menu" class="black"> <li><a href="index.html">Home</a></l ...

What is the best method for deleting an uploaded image from a box?

My code is quite lengthy, so I'll just showcase the JavaScript portion here. Here is a snippet of my JavaScript code: <script type="text/javascript"> let current = 0; for(let i = 0; i < 5; i++) { $('#thumbnail-view- ...

What is the best way to expand a scrollbar's width with CSS?

Can the width of a scrollbar on a <div> element within the <body> be increased? I mean the scrollbar specifically on the inner <div> element, not the default browser scrollbar since this page is in full screen mode and does not display t ...

Issue with header background images not showing up in Safari browser

On my website, the top header background and the background of the "Kreation Team" Div are not appearing on Safari for iPads and iPhones, but they are visible on iMacs and MacBooks. The background images do not show up on smaller devices. If you compare C ...

When the user clicks, display one div and conceal the others

https://codepen.io/leiacarts/pen/PoqRxNZ I need assistance with two specific tasks related to my website layout. Firstly, I am struggling to ensure that images displayed in the red sections remain constrained and automatically resize within the content di ...

The issue of unselection not functioning properly for multiple items when using both selectable and draggable features

i need the unselection of list items to be as smooth as selectable() but without draggable() My desired outcome is similar to the following gif showcasing combined selectable and draggable functionality: https://i.stack.imgur.com/3GjTD.gif here's t ...

Expanding HTML Editor's Functionality in Eclipse with Custom Tags

Creating an application involves incorporating custom tags within HTML code, which are processed on the server side before being presented to the end user as valid HTML. An example of using custom tags is shown below: <html> <body> ... < ...

Is your MJML column layout not stacking properly on mobile devices?

I've been struggling with a basic 2-column design created using the online editor at mjml.io. I can't seem to get it to stack on mobile devices. The email looks identical on desktop (Outlook 365 for PC) and mobile (Outlook for iOS on iPhone 13) ...

Issue with Refreshing Header Row Filter Control in Bootstrap Table

Currently in the process of developing an application that utilizes Bootstrap Table and its extension, Filter Control. One feature I've incorporated is individual search fields for each column to enhance user experience. The challenge I'm facing ...

Concealing the view-source feature in core PHP or HTML

Is there a way to conceal view-source in basic php or html? I've come across some information on this topic, but I'm having trouble grasping how to implement it: Web Developer Class: How to Hide your Source Code ...

Customize the background color of highlighted text using HTML and jQuery

Recently, I modified an existing code to divide plain text into four classes by selecting a portion of the text and coloring it. Afterwards, I extracted the text of each class and stored it in my database. While this code works well, I am looking for a way ...

The child div vanishes abruptly instead of smoothly transitioning like its parent

I have created a demo that showcases a simulation of the issue here. Codepen: https://codepen.io/anon/pen/pXvyMd I am attempting to achieve a fading effect on the caption text 'this is a test' when hovering over the box at the top right of the ...

When incorporating conditional statements into your code, make sure to utilize the tags <script> along with

I have some script tags as shown below: <script src="cordova-2.5.0.js"></script> <script src="js/jquery-1.7.2.min.js"></script> <script src="js/jquery.mobile-1.1.1.min.js"></script> <script src="js/jquery.xdomainajax ...

Using CSS and JavaScript to create a gradient-style opacity effect for smoothly fading out content

Is there a way to achieve a gradient fade effect on the opacity of an iframe and its content? To provide an illustration, think of the bottom of the notification centre in Mountain Lion or iOS. The concept involves having the content within an iframe grad ...

Footer in Bootstrap 3 malfunctions if <h2> tag is missing

I've encountered a strange issue that I can't seem to figure out. Simply removing the <h2> tags in my code causes the footer to move to the top instead of the bottom. Oddly enough, the footer works perfectly when there is a title, but as so ...

Showing error messages in Angular when a form is submitted and found to be invalid

My form currently displays an error message under each field if left empty or invalid. However, I want to customize the behavior of the submit button when the form is invalid. <form #projectForm="ngForm" (ngSubmit)="onSubmit()"> ...