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

uniformly distribute the list items on the horizontal navigation bar

Does anyone know how to properly space out a ul in a navigation bar, with 5px padding on the right and left and the text evenly spaced in between? body { background: #ffffff; text-align: center; font-family: helvetica, arial, san ...

Discover the method for invoking a Javascript function within a Leaflet popup using HTML

Upon clicking on a marker on the leaflet map, I aim to trigger a popup box that contains five elements: Title Description Image Button (Next Image) Button (Previous Image) To achieve this, I attempted to include a custom popup for each feature ...

Splitting columns evenly in a table with a width of 100%

Welcome to my first query on this platform. Despite my efforts to search for a solution, I couldn't find an explanation as to why my code isn't functioning correctly in Internet Explorer (10+). I have created three divs displayed as cells, each ...

Enhancing productivity with a more streamlined process for creating a responsive website design through the optimization of

I recently had the task of placing two images in a band on a webpage and ensuring they were responsive to different screen sizes. Image 'a' represented a circular logo, while image 'b' was a rectangular logo. The red band served as the ...

Hide the menu when a user taps on an item on mobile or tablet devices

I'm facing a unique challenge and could use some guidance. The issue is with the mobile version of my website, accessible at . On tablets or mobile devices, the menu is condensed into a button. To navigate through the menu, I have to click the button ...

Update the text in a personalized dropdown menu when an option is chosen

After spending some time working on a customized dropdown with the use of CSS and Vanilla JavaScript (Plain JS), I encountered an issue while trying to select and update the dropdown text upon clicking an option: window.onload = () => { let [...opt ...

Clicking a button in jQuery will automatically scroll to the far left

I am facing a challenge with my webpage where inline block divs are being appended each time a link is clicked, causing the total width to eventually go off the page (which is intentional). I would like to implement an animated scroll feature that automati ...

Put the code inside a function. I'm new to this

My goal is to encapsulate this code: if($(window).width() > 980) { $(window).on("scroll", function() { if($(window).scrollTop() > 20) { //add black background $(".x-navbar").addClass("active"); $(".x-navbar .desktop ...

Tips for implementing validation in JavaScript

I'm brand new to learning Javascript. Recently, I created a template for a login page and it's working perfectly fine. However, I am struggling with setting up validation and navigation. My goal is to redirect the user to another page if their us ...

The hover effect in CSS brings life to list items when filled with content

I am attempting to create an animation for an <li> element that gives the illusion of a fill effect moving from left to right when hovered over. This is my current progress: ul { list-style-type: none; } .hoverTest { float: left; margin-right: 1 ...

Why does the pound symbol in z-index always show up in Angular?

Having an issue with my code where I set a z-index in the CSS like this: .mat-mini-fab { position: absolute; right: 5px; top: 4px; z-index: 999; box-shadow: none !important; } However, whenever I visit my site, the z-index is not being appl ...

Striking a balance between innovation and backward compatibility in the realm of Web Design/Development

Creating websites is my passion, and I enjoy optimizing them for various platforms, devices, and browsers. However, lately, I've been feeling frustrated. I'm tired of facing limitations in implementing my creative ideas due to outdated technolog ...

Changing the CSS property of a single table cell's innerHTML

I have a question that may seem silly, but I'm going to ask it anyway. Currently, I am iterating through a list of strings that follow the format "1H 20MIN" and adding them to table cells using the innerHTML property like so: for (i = 0; i < list ...

What is the best method for extracting [object Text] using XPath?

I'm currently working with Selenium and attempting to extract text from a node that contains the keyword "approved," but I'm unsure of how to retrieve and validate this specific text. Here is the node structure - <div class="Notification-bo ...

I am encountering a problem while performing JavaScript validations

In jQuery or using the element's ID, I can validate a textbox. For example: var field = document.getElementById('tbxSearchField').value if (field == "") {alert("please enter text");} The HTML code is as follows: <input class="input" id ...

Why does HTML validation matter after the webpage has finished loading?

After coming across an article recommending a workaround for a method that isn't considered strictly valid (using target="_blank") by using JavaScript to apply the rules after the page has loaded, I began contemplating if this approach is ethical. It ...

Is there a way to display all of them inline in Woocommerce?

Can anyone assist with making each of these inline? <div class="atc_nsv"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <ul> <li><img class="ad lazyloaded" data-src="//cdn.shopify.com/s/files/1/0608/5882/6972/fi ...

Hiding a div using the Bootstrap `.hidden-xs` class may not work as

I have been working on a website and I want to hide a specific section for users viewing it on small screens. I tried using Bootstrap's .hidden-xs class, but when I tested it using Chrome's mobile emulator set to "iPhone 5", the div did not hide ...

Employing the GET method to retrieve the values of two text inputs

I'm struggling to retrieve the values from two text input fields: <form action="search.php"> <input type="text" name="q1"> <input type="text" name="q2" > <input type="submit" name="submit" value="Search" /> </form> On t ...

The responsive menu refuses to appear

my code is located below Link to my CodePen project I'm specifically focusing on the mobile view of the website. Please resize your screen until you see the layout that I'm referring to. I suspect there might be an issue with my JavaScript cod ...