Is there a way to connect horizontal Divs so that when one increases in height, a linked Div also increases in height?

Looking to design a form with three interconnected horizontal divs, creating a structure similar to HTML table rows or spreadsheet cells.

Let's imagine a series of horizontal divs:

Column1     Column2     Column3

...as Column2 increases in height (due to dynamically added elements), Column1 should also grow vertically alongside it.

Furthermore, Column2 may contain multiple groupings of related elements. Each grouping should align vertically with one of the "rows" in Column3.

In other words, when Column2 expands with additional "rows", Column1 should shadow its growth; however, if new elements are added to the first segment of Column3 (associated with the initial "row" of Column2), then Column2 will adjust its height to match that particular collection of elements in Column3.

Perhaps a visual aid would help illustrate this concept:

Column1     Column2     Column3
======      ======      ======
Fri Aug 21  Shift 1     Something about Shift1
Sat Aug 22  Shift1      

...when a second shift is added on Friday:

Column1     Column2     Column3
======      ======      ======
Fri Aug 21  Shift 1     Something about Shift1
            Shift 2     
Sat Aug 22  Shift1      

...Column1 maintains its vertical alignment with Column2 after adding Shift2 for Friday.

Now, additional elements are inserted into Column3 for Friday's Shift1, causing Shift1 to expand downwards/vertically accordingly:

Column1     Column2     Column3
======      ======      ======
Fri Aug 21  Shift 1     Something about Shift1
                        Something more about Shift1
            Shift 2     
Sat Aug 22  Shift1      

How can we establish and uphold this interrelationship? What methods can be used within Bootstrap (or any other framework)?

Answer №1

If you're looking for a simple and reliable way to achieve a 3-column layout where each div always stays the same height as the others, consider using the HTML table element.

HTML

<table>
    <col>
    <col>
    <col>
    <tr>
        <td><div>DIV #1</div></td>
        <td><div>DIV #2</div></td>
        <td><div>DIV #3</div></td>
    </tr>
</table>

CSS

table {
    table-layout: fixed;
}

col {
    width: 100px;
}

td {
    border: 1px solid black;
    font-size: 1.5em;
    padding: 10px;
}

This approach ensures that regardless of the amount of content in any div, all other div elements will adjust their heights accordingly. http://jsfiddle.net/n7170pxg/1/

Answer №2

Make sure to take a look at these two articles on using display: table and display: table-cell. They could provide the solution you're searching for.

-

-

The second link appears to offer the most comprehensive answer.

HTML

<div class="container">
    <div class="column">Column 1.</div>
    <div class="column">Column 2 is a bit longer.</div>
    <div class="column">Column 3 is longer with lots of text in it.</div>
</div>

CSS

.container {
  display: table;
}
.column {
  display: table-cell;
  width: 100px;
}

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

The functionality of jQuery clone is failing when draggable items are used to generate a duplicated version

I'm new to implementing jQuery Draggable functionality and I'm trying to create a drag and drop feature where the drag element is cloned and dropped to a specific location. Here is the code I have so far: $(function () { $('#D ...

Is there a way to modify a document without altering its original location?

I attempted to load an entire page using ajax, with the doctype and html tags removed. However, when I tried setting it with the following code: document.documentElement.innerHTML=xmlhttp.responseText; Google Chrome returned an error message: An invalid ...

CSS3 Animation: Facing issue with forwards fill behavior in Safari when using position and display properties

After creating a CSS3 animation to fade out an element by adjusting its opacity from 1 to 0 and changing the position to absolute and display to none in the last frames, I encountered an issue. In Safari, only the opacity is maintained while the position a ...

Achieve the identical outcome of the code in jQuery using React.js

Hey there! I'm currently exploring how to achieve similar results using React JS. I realize my request might seem a bit trivial, but I'm in the process of understanding how JavaScript and React JS can be connected in practical projects. Feel fr ...

Unlocking the Power of JavaScript: Harnessing Its Potential for Numerous IDs in HTML

There's a script I came across on the internet at this link: let multi = 2; let str = "Little lamb"; let multiStr = ""; while(multi > 0){ multiStr += str multiStr += " "; multi--; } multiStr = multiStr.trimEnd ...

Use CSS to create boxes of a specific size within a table cell that spans the entire height

I'm having trouble using CSS to create two boxes (one red and one green) inside a table cell. I can't seem to make them fill the entire height of the cell. Here is what I have tried so far: td { background-color: lightblue; padding: 5px; ...

Looking to add a glowing effect to a div when hovered using jQuery

Seeking assistance to add a glow effect to a div when hovered using jQuery. Below is the code snippet: HTML <div class="tablerow"> <div class="image"> <img src="1.jpg"> </div> <div class="info"> ...

Ensure that the responsive SVG image remains centered even when resizing

I have been attempting to center crop the responsive SVG image while resizing. Even though I used preserveAspectRatio="xMidYMax slice", the image width does not stay consistent with my screen size. body{ margin:0;padding:0; } .wrapper { position: re ...

The webpage displays the element as <span class="icon">&#xe80d;</span> instead of rendering it properly

In my ReactJS project, I have created a component called Menu1item: class Menu1item extends React.Component{ render(){ return ( <div> {this.props.glyph}{this.props.value} </div> ) ...

How can I guarantee consistent UTF-8 encoding in Nokogiri parsing, ERB templates, and encoding HTML files using Ruby?

After successfully parsing parts of a website, I encountered an issue with UTF8: get '/' do url = '<website>' data = Nokogiri::HTML(open(url)) @rows = data.css("td[valign=top] table tr") erb :muster I am now attempting ...

Retrieving information through SELECT with a post parameter

I have created the following HTML code: <select name="compet" id="compet"></select> <select name="spage" id="spage"> <option value="home">Home</option> <option value="insert">Insert</option> <option valu ...

Achieving vertical alignment of text next to an image using a skeleton grid

Does anyone know how to align the images vertically with the text on the "Board of Advisors" tab on THIS PAGE? Here is the shortened HTML code: <div class="four columns alpha"><img class="ImageBorder" src="LINK" alt="" /></div> <div ...

The mobile responsive view in Chrome DevTools is displaying incorrect dimensions

Seeking some clarification on an issue I encountered: I recently created a simple webpage and attempted to make an element full width using width: 100vw. However, I observed that on screens smaller than around 300px, the element appeared smaller and not t ...

Error in hover feature not performing to expectations

Check out my jsfiddle link: http://jsfiddle.net/ganganp/x62wR/5/ $('#rotator0 div').hover( function () { ssrc = $(this).find('img').attr("src"); valt = $(this).find('img').attr("alt"); ...

Tips for deleting a button from a DataTable file upload feature

I currently have Datatable set up to upload images using the code snippet below: { label: "Images:", name: "files[].id", type: "uploadMany", display: function ( fileId, counter ) { re ...

The jQuery .get() function is only operational in debugger mode

I am attempting to retrieve data from , which provides a plain text response, and store it in a variable for future use. Below is my javascript code: var extractData = function() { var copiedData = "not successful"; $.get('http://numbersapi.c ...

Having trouble with string matching in JavaScript?

My attempts to verify my Ajax response with a string have consistently resulted in a fail case being printed. Below is the section of code relating to my ajax request: var username = document.getElementById("name").value; var password = document.getEle ...

Is it possible to apply two ngClass directives to a single div element in Angular 4?

When I click to start editing, a component is called for the editing process. In this component, I am unable to click on anything and the background turns black, which is okay. However, I would like for each ID that I select to edit to become active with a ...

CSS Dropping Down Menu Design

Hello everyone! I am taking my first step into web development and currently in the process of revamping my DJ website. Check out my updated site here: I am working on creating a dropdown div within the top-left menu that will display information about t ...

Creating a responsive DataTable filled from a $.ajax request is a straightforward process that can greatly

I am in the process of creating an application that retrieves a lot of data from a web-service query and populates a data table with it. The data shows up correctly and styled properly on desktop, but when I switch to viewing it on a mobile device, the dat ...