2

I am bit lost ... I want to make 2 columns where one the left column is scroll-able depending on the size of the right column Here is my example in jsfiddle : http://jsfiddle.net/6f3bwrh7/

In my case I want the red column (that has the scroll) to get the same height as the green column I tried something like this :

  overflow:auto;

But I think I am totally wrong

Gergely Toth
  • 6,638
  • 2
  • 38
  • 40
LuR
  • 251
  • 1
  • 4
  • 16
  • Possible duplicate of [How do I keep two side-by-side divs the same height?](https://stackoverflow.com/questions/2997767/how-do-i-keep-two-side-by-side-divs-the-same-height) – Dinesh Ghule Jun 08 '18 at 09:30
  • Also see https://stackoverflow.com/questions/40563976/two-columns-side-by-side-scrollable – Dabrule Mar 15 '21 at 12:38

5 Answers5

4

If you'd like two columns, only one scrollable you could use position: fixed on one of the columns. Like this:

body {
  margin: 0;
  padding: 0;
}

.left {
  width: 50%;
}

.left {
  position: fixed;
}

.right {
  padding-left: 50%;
}

.left img {
  height: auto;
  max-width: 100%;
  outline: 0;
}
<div class="left">
  <p>
    Hello
  </p>
</div>
<div class="right">
  <p>Long contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong content</p>
  <p>Long contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong content</p>
  <p>Long contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong content</p>
  <p>Long contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong content</p>
  <p>Long contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong content</p>
  <p>Long contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong content</p>
  <p>Long contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong content</p>
  <p>Long contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong content</p>
  <p>Long contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong contenLong content</p>
</div>
billy.farroll
  • 1,903
  • 2
  • 15
  • 23
0

Try to change this :

overflow: auto;

to this

overflow-y: scroll;

Fazie
  • 67
  • 6
0

its possible to make the divs the same height, BUT, according to which one has the higher height.

you could add flex to the parent container and the 2 divs will be of the same height. but in your case, it'll be the height of the left column, because it has the greater height out of the 2.

#wrapper {
  display: flex; /* equal height of the children */
}

Otherwise, I would recommend using javascript to get the 'scrollheight' of the right div, and apply it to the left div.

wsgg
  • 934
  • 1
  • 20
  • 43
  • yeah I want the left column height get equal to the right column but I want to use only css – LuR Jun 08 '18 at 13:53
0

To make both columns the same height you can either use display:grid; or display:flex; on your #wrapper.

But as I understand it you want to set the height of the bigger element to the one of the smaller element. For that you have to use javascript or use a fixed height in your css.

Domenik Reitzner
  • 1,583
  • 1
  • 12
  • 21
0

check output:

#left-block{
  float:left;
  width:30%;
  background-color:red;
  overflow:auto;
}

#right-block{
  float:right;
  width:70%;
  background-color:green;
}

.row {
  display: flex; /* equal height of the children */
}

.col {
  flex: 1; /* additionally, equal width */
  padding: 1em;
}
<div id='wrapper' class='row'>
  <div id='left-block' class='col'>
    <div class='elmt'>
    elmt 1
    </div>
    <div class='elmt'>
    elmt 2
    </div>
    <div class='elmt'>
    elmt 3
    </div>
     <div class='elmt'>
    elmt 4
    </div>
    <div class='elmt'>
    elmt 5
    </div>
    <div class='elmt'>
    elmt 6
    </div>
        <div class='elmt'>
    elmt 7
    </div>
    <div class='elmt'>
    elmt 8
    </div>
    <div class='elmt'>
    elmt 9
    </div>
  </div>
  <div id='right-block' class='row'>
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptas minus commodi repellat voluptatum odit quos excepturi fugiat quia distinctio harum pariatur inventore possimus minima sequi, enim eius, cupiditate, perferendis accusantium.
  </div>
  <div style='clear:both'>
  
  </div>
</div>
Dinesh Ghule
  • 3,423
  • 4
  • 19
  • 39
  • I want the left column to be scrollable So the height of the left column should end to element 3 or 4 then scroll – LuR Jun 08 '18 at 13:55