Two rectangular divisions placed next to each other, with one perfectly centered and the height of the second division adjusting to match the height of the

I attempted to implement the Matthew James Taylor method, utilizing three columns. However, my main issue arises when I desire the middle column to dictate the height. In other words, if the center div is 500px in height, I want the right div's height to also be 500px, even with an overflow:scroll property.

Here is the code on jsfiddle with a more detailed explanation

HTML:

<div class="colmask threecol">
<div class="colmid">
    <div class="colleft">
        <div class="col1">
            <!-- Column 1 start -->
            <p>Column 1</p>
            <p>This is the main content of the middle column.</p>
        </div>
            <!-- Column 1 end -->

        <div class="col2">
            <p>Column 2</p>
            <p>This represents the second column. Ideally, there wouldn't be a second column and the center div would be perfectly centered without it.</p>
        </div>
        <div class="col3">
            <!-- Column 3 start -->
                <p>Column 3</p>
                <p>This depicts the right column. I'm aiming for its height to adjust according to the middle column's height. Instead of overflowing as it currently does, I wish for its height to match the middle column and have scrollable overflow.</p>
            <!-- Column 3 end -->
        </div>
    </div>
</div>

CSS:

    body {
    margin:0;
    padding:0;
    width:100%;
}
/* column container */
.colmask {
    clear:both;
    float:left;
    width:100%;
    /* entire width of the page */
    overflow:hidden;
    /* Trim any extending divs */
}
/* common column settings */
.colright, .colmid, .colleft {
    float:left;
    width:100%;
    /* width of the page */
    position:relative;
}
.col1, .col2, .col3 {
    float:left;
    position:relative;
    overflow:hidden;
}
/* Three-column layout settings */
.threecol {
    background:#eee;
    /* color scheme for the right column */
}
.threecol .colmid {
    right:25%;
    /* width of the right column */
    background:#fff;
    /* color scheme for the center column */
}
.threecol .colleft {
    right:50%;
    /* width of the middle column */
    background:#aaa;
    /* color scheme for the left column */
}
.threecol .col1 {
    width:46%;
    /* width of center column content (column width minus side paddings) */
    left:102%;
    /* 100% plus left padding of center column */
}
.threecol .col2 {
    width:21%;
    /* Width of left column content (column width minus side paddings) */
    left:31%;
    /* width of (right column) plus (center column side paddings) plus (left column left padding) */
}
.threecol .col3 {
    width:21%;
    /* Width of right column content (column width minus side paddings) */
    left:85%;
    /* Please note the calculation here:
                (100% - left column width) plus (center column side paddings) plus (left column side paddings) plus (right column left padding) */
}

I've tried to keep the code concise, but it was quite a task.

Appreciate your help!

Answer â„–1

To properly structure your layout, it is necessary to nest the second div within the first and position it absolutely

JSfiddle Example

HTML

<div class="container">
    <div class="sidebar"></div>
</div>

CSS

.container {
    width:60%;
    margin:0 auto;
    background-color: lightgray;
    position: relative;
    height:300px;
}

.sidebar {
    position: absolute;
    width: 120px;
    top:20px;
    right:10px;
    height:100%;
    background-color: lightblue;
}

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

Personalized Tumblr-style button

Hey there, I've been working on creating a custom Tumblr-like button and tried adding an iframe above it to make it clickable. However, something seems to be off as it's not functioning properly. I'm still trying to wrap my head around how i ...

The "(click)" event doesn't fire upon clicking a material icon

After creating an <a> tag with a (click) event function call, I noticed that the click event works everywhere except for the arrows mat-icons within the code snippet below: <span *ngIf="section.pages.length>0"> <mat-icon *ngIf="secti ...

I am experiencing issues with the ng-dropdown-multiselect library and it is not functioning

Check out this awesome library for creating dropdown menus using angularjs and twitter-bootstrap-3 at: . I am trying to implement the examples provided. In my html, I have: <div ng-dropdown-multiselect="" options="stringData" selected-model="stringMod ...

Choose the element that is trapped within the div

I've hit a roadblock with this issue that I just can't seem to figure out. I was working on a practice project creating a Netflix-like webpage, and the select element in the footer containing languages is stuck and won't budge. Here's m ...

Error: The ORM class object cannot be converted to a string. <img src>

Hey there, I'm still quite new to PHP and idorm so bear with me. I've spent a lot of time searching for a solution to this particular issue without luck. The error message "Object of class ORM could not be converted to string" keeps popping up i ...

Toggle the hamburger menu using JavaScript

How can I close my hamburger menu when clicking a link for one page navigation? The menu is functioning properly, but I need a way to close it. Unfortunately, I have limited knowledge of JS. I only have the HTML and CSS for this: HTML in index.html file ...

Creating a dynamic scene with three.js within an HTML div element

I've been searching for solutions but can't seem to figure it out for this particular scenario. https://codepen.io/rkimo/pen/vdwxJj Essentially, I just want to include this blob in a div so that I can add content before and after it and be able ...

Getting 100% height on floated neighboring divs: Tips and tricks

​<div id='container'> <div class='left'></div> <div class='right'></div> <div class='clear'></div> </div>​​​​​​​​​​​​​​​​â ...

The HTML button triggers a function to execute on a different webpage when clicked

I'm facing a straightforward issue that I can't seem to figure out due to my limited experience with Angular and web development. The problem revolves around two components, namely home and dashboard. In the home.component.html file, there's ...

Tips for positioning elements within an ng-repeat list using absolute positioning?

Here is the HTML code: <div class = "container"> <form ng-submit = "createSticky()"> <input ng-model="formData.data" type="textarea" name="sticky_content" placeholder="add sticky text" required="true"/> <input ng-model= ...

Positioning elements in a header using CSS techniques

I am currently working on designing a navigation menu header that includes a logo, along with some buttons aligned to the left side of the logo. However, I am facing an issue where these buttons appear at the bottom of the logo instead of aligning to the t ...

Comparison of valueChanges between ReactiveForms in the dom and component级主动形

Is there a method to determine if the change in valueChanges for a FormControl was initiated by the dom or the component itself? I have a scenario where I need to execute stuff() when the user modifies the value, but I want to avoid executing it if the v ...

Allowing scroll events to flow through from a child <div> to <canvas> in Excalidraw

In my current project, I am utilizing Excalidraw to draw a layer of <div>s on top of the <canvas>. While everything is functioning well, I have encountered an issue with scrolling through the infinite canvas. When the mouse hovers over one of t ...

PHP offers a different solution instead of using an HTML hidden input tag

Is there a way to pass a value from one HTML form to another without using hidden input fields? I need this value for a prepared SQL statement. I'm concerned about security risks associated with using hidden input fields. Does anyone have an alternat ...

TradingView widget chart embedded within a web page is failing to display when hosted on X

I am having trouble displaying a TradingView widget. When I embed the widget in an HTML file and open it in a regular browser, the chart shows up fine. However, when I embed the widget in a PHP or HTML file and try to open it using xampp, the browser doesn ...

Refreshing the dropdown selection to a specific option using AngularJS and either JavaScript or jQuery

Currently, I am facing an issue with resetting the select tag to its first option. I have implemented Materialize CSS for styling purposes. Despite my efforts, the code snippet below is not achieving the desired outcome. Here is the JavaScript within an ...

"Taking a break" and indulging in Sass

When transferring Sass classes from another project, I wanted to create a wrapper to contain these styles locally. Here is how my wrapper is currently set up: .my-wrapper { @include "framework-main" } Initially, everything seemed fine. However, I soo ...

Transparent static navbar displayed above header image

Scenario I managed to develop a transparent navbar that is superimposed on top of a header image with an SVG curve attached to it. To create the transparent navbar, I modified some classes associated with it by removing bg-light. By adding the class fix ...

Using jQuery to dynamically change the CSS color based on the background-color of a checkbox label

When a checkbox is selected, the function below runs to change the text color to white or black based on the darkness of the background color. However, the third checkbox should trigger this change to white but currently does not. function isDark(color) { ...

Is it possible to utilize CSS rules for a non-existent div within CSS?

Can this be achieved using CSS? If .div1 is not present, enforce the following rule: .div2{ property: value; } For example, <div class="div1"> ... </div> <div class="div2"> <!-- it exists, so no action needed --> </div& ...