3

I need to create a form that has three horizontal divs which are interrelated, somewhat like the rows in an html table or the cells in a spreadsheet.

What I mean is with this series of horizontal divs:

Column1     Column2     Column3

...when Column2 grows in height (due to elements being dynamically added to it), Column1 must grow vertically in lockstep with it.

Similarly, but more complex"ily," Column2 may have multiple groupings of related elements. Each grouping needs to be tied vertically to one of the "rows" in Column3.

IOW, Column1 will grow in height as Column2 adds "rows", thus "shadowing" Column2 in that way; but then, when elements are added to the first section of Column3 (which are associated with the first "row" of Column2), Column2 will shadow the height of the first related collection of elements in Column3's first section.

Perhaps a visual representation would be clearer:

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 keeps vertical pace with Column2 when Shift2 was added for Friday.

Now, more elements are added to Column3 for Friday's Shift1, and Shift1 expands downward/vertically to accommodate it:

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

In what way can this interrelationship be established and maintained? How can this be done in Bootstrap (or otherwise, for that matter)?

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • Can include `html` , `css` at Question ? – guest271314 Aug 22 '15 at 04:03
  • 5
    There are two ways to do this and I hate to say it but the easiest is with tables. – Sabrina Aug 22 '15 at 04:05
  • 2
    The harder solution is to use `display: table` or `flexbox` but you're going to have a hell of a time lining up those rows. See this question's answer for that method: http://stackoverflow.com/questions/19695784/how-can-i-make-bootstrap-columns-all-the-same-height – Sabrina Aug 22 '15 at 04:06
  • 1
    I only know the basics of flexbox but I think even I can say that will be a nightmare. – Maria Ines Parnisari Aug 22 '15 at 04:07
  • 1
    "due to elements being dynamically added to it". Well, use tables and make empty cells (or empty div blocks if you need it, but i don't see the reason - since tabular data is in question, obviously) in back-end language you use. So, basically, print rows, with or without content in all cells/elements.... – sinisake Aug 22 '15 at 04:15
  • 1
    Hi Clay - I think my answer covers the first half of your question, but I'm not so sure about the second half. If it's not useful to you just lmk and I'll delete it. – Michael Benjamin Aug 22 '15 at 04:29
  • @Michael_B: lmk = Load My Kilos? – B. Clay Shannon-B. Crow Raven Aug 22 '15 at 12:51
  • Sorry, "let me know". – Michael Benjamin Aug 22 '15 at 12:52

2 Answers2

1

The simplest and probably most robust way to accomplish the 3-column layout where each div always maintains equal height with the other two is with 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;
}

In this demo, any amount of text you put in any div will take all other div heights with it. http://jsfiddle.net/n7170pxg/1/

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
-1

Check out those two articles for display: table and display: table-cell. They might be the answer to what you are looking for.

-http://colintoh.com/blog/display-table-anti-hero

-http://www.senktec.com/2014/01/using-css-display-table-cell-for-columns/

The last link seems to be the best solution.

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;
}
Kristina Bressler
  • 1,642
  • 1
  • 25
  • 60
  • 1
    Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. Link-only answers can become invalid if the linked page changes – Paulie_D Aug 22 '15 at 10:03