3

I'm trying to "stack" divs on top of each other as new div boxes (.dialog-box) are added to the parent container (.dialog-container).

To stack the elements, I'm using the following on the parent:

display: flex;
flex-direction: column;
justify-content: flex-end;

I'd like to scroll that container for .dialog-boxs that are overflowing, yet with flex-box the overflow-y: scroll; is not scrolling.

Two boxes: (fill up container from bottom to top as expected):

enter image description here

Six boxes (expands outside the height of the container and should scroll):

enter image description here

SCSS:

.dialog-container {
    border: 4px solid rgba(255, 255, 255, .4);
    border-radius: 5px;
    width: 300px;
    height: 340px;
    position: relative;
    top: -50px;
    margin: 0 auto;
    overflow-y: scroll;
    z-index: 5;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;

    .dialog-box {
        width: 90%;
        background: $dialogBoxWhite;
        margin-bottom: 20px;
        border-radius: 8px;
        border: 5px solid $dialogBoxGreenBorder;
        color: $dialogBoxGreenFont;
        text-align: center;
        margin-left: 5px;
        padding: 5px;
        display: inline-block;
        p {}
    }
}

HTML:

<div class="dialog-container">
   <div class="dialog-box"></div>
   <div class="dialog-box"></div>
   <div class="dialog-box"></div>
   <div class="dialog-box"></div>
   <div class="dialog-box"></div>
   <div class="dialog-box"></div>
</div>
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
user3871
  • 12,432
  • 33
  • 128
  • 268

2 Answers2

1

You simply remove the justify-content: flex-end;

Two boxes: (fill up container from bottom to top as expected): for this you add below code to your scss file :

display: flex;
flex-direction: column-reverse;
justify-content: flex-start;

.dialog-container {
    border: 4px solid rgba(0, 0, 0, .4);
    border-radius: 5px;
    width: 300px;
    height: 350px;
    position: relative;
    margin: 0 auto;
    overflow-y: scroll;
    z-index: 5;
    display: flex;
    flex-direction: column-reverse;
    justify-content: flex-start;
}
    .dialog-box {
        width: 90%;
        background:white;
        margin-bottom: 20px;
        border-radius: 8px;
        border: 5px solid green;
        color: green;
        text-align: center;
        margin-left: 5px;
        padding: 3px;
        display: inline-block;
        }
<div class="dialog-container">
   <div class="dialog-box">Box 1</div>
   <div class="dialog-box">Box 2</div>
   <div class="dialog-box">Box 3</div>
   <div class="dialog-box">Box 4</div>
   <div class="dialog-box">Box 5</div>
   <div class="dialog-box">Box 6</div>
    <div class="dialog-box">Box 7</div>
</div>

also show example in scroll-y working with flex-column

Arpita Patel
  • 300
  • 1
  • 14
-6

Try to change display: flex; to display: flex-box;

This will give you a scroll bar that actually scrolls. Additionally, your examples divs are all lacking closing tags.

https://jsfiddle.net/Lpw0726j/23/

<div class="dialog-container">
   <div class="dialog-box">9</div>
   <div class="dialog-box">8</div>
   <div class="dialog-box">7</div>
   <div class="dialog-box">6</div>
   <div class="dialog-box">5</div>
   <div class="dialog-box">4</div>
   <div class="dialog-box">3</div>
   <div class="dialog-box">2</div>
   <div class="dialog-box">1</div>
</div>


.dialog-container {
    border: 4px solid rgba(255, 255, 255, .4);
    border-radius: 5px;
    width: 300px;
    height: 340px;
    position: relative;
    top: 50px;
    margin: 0 auto;
    z-index: 5;
    display: flex-box;
    flex-direction: column;
    justify-content: flex-end;
    overflow-y: auto;
    background-color: teal;


    .dialog-box {
        width: 90%;
        background: black;
        margin-bottom: 20px;
        border-radius: 8px;
        border: 5px solid red;
        color: green;
        text-align: center;
        margin-left: 5px;
        padding: 5px;
        display: inline-block;
        p {}
    }
}
ikos23
  • 4,879
  • 10
  • 41
  • 60