341

enter image description here

Here's the code I'm using to achieve the above layout:

.header {
  height: 50px;
}

.body {
  position: absolute;
  top: 50px;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
}

.sidebar {
  width: 140px;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.content {
  flex: 1;
  display: flex;
}

.column {
  padding: 20px;
  border-right: 1px solid #999;
}
<div class="header">Main header</div>
<div class="body">
  <div class="sidebar">Sidebar</div>

  <div class="main">
    <div class="page-header">Page Header. Content columns are below.</div>
    <div class="content">
      <div class="column">Column 1</div>
      <div class="column">Column 1</div>
      <div class="column">Column 1</div>
    </div>
  </div>
</div>

I omitted the code used for styling. You can see all of it in the pen.


The above works, but when the content area's content overflows, it makes the whole page scroll. I only want the content area itself to scroll, so I added overflow: auto to the content div.

The problem with this now is that the columns themselves don't extend beyond their parents height, so the borders are cut off there too.

Here's the pen showing the scrolling issue.

How can I set the content area to scroll independently, while still having its children extend beyond the content box's height?

Vadim Ovchinnikov
  • 13,327
  • 5
  • 62
  • 90
Joseph Silber
  • 214,931
  • 59
  • 362
  • 292

11 Answers11

399

I've spoken to Tab Atkins (author of the flexbox spec) about this, and this is what we came up with:

.content {
    flex: 1;
    display: flex;
    overflow: auto;
}

.box {
    display: flex;
    min-height: min-content; /* needs vendor prefixes */
}
<div class="content">
  <div class="box">
    <div class="column">Column 1</div>
    <div class="column">Column 2</div>
    <div class="column">Column 3</div>
  </div>
</div>

Here are the pens:

  1. Short columns being stretched.
  2. Longer columns overflowing and scrolling.

The reason this works is because align-items: stretch doesn't shrink its items if they have an intrinsic height, which is accomplished here by min-content.

Eric
  • 95,302
  • 53
  • 242
  • 374
Joseph Silber
  • 214,931
  • 59
  • 362
  • 292
  • I think you've almost got it. Just add "min-height: 100%" on .box -- that makes .box (and its stretchy columns) occupy the full available height, even if the columns' contents are made shorter. – dholbert Feb 05 '14 at 23:27
  • @dholbert - percentage heights only work when the parent has a fixed height. – Joseph Silber Feb 05 '14 at 23:33
  • 3
    They work when the parent's height doesn't depend on its children, generally, which is the case here. min-height: 100% does indeed fix your stretch-even-when-columns-are-short issue in Firefox (though not in Chrome). Not sure offhand if that's a Chrome bug or a Firefox bug. – dholbert Feb 05 '14 at 23:36
  • 4
    Note that Firefox currently only supports "min-content" for width values, not height values -- so this won't work in Firefox, if that matters to you. (See e.g. https://bugzilla.mozilla.org/show_bug.cgi?id=852367 ) – dholbert Feb 05 '14 at 23:53
  • (Even in Chrome (v32 dev), I'm not seeing 'min-height: -webkit-min-content;' have any effect, in the 'ehLFl' pen in your updated answer. I tried the columns with the heights you've given, and also with shorter heights, and that 'min-height' decl doesn't seem to affect the rendering on my machine. Are you sure it's buying you anything?) – dholbert Feb 05 '14 at 23:59
  • 2
    @dholbert - The problem with these pens is that they were public, so anybody could change them. I took ownership of them, so here you go: http://codepen.io/JosephSilber/pen/pmyHh – Joseph Silber Feb 06 '14 at 00:07
  • For what it's worth, I emailed the CSSWG to clarify the difference in behavior between Chrome & Firefox with "min-height: 100%", mentioned in the first three comments here. My post: http://lists.w3.org/Archives/Public/www-style/2014Feb/0180.html – dholbert Feb 06 '14 at 01:57
  • @dholbert - I asked Tab. Turns out Firefox is correct: "this is due to a disagreement over whether "stretched" things are definite or not when the container is definite in the cross axis. Firefox is correct - this was updated in the spec a while ago, and WK/Blink haven't updated yet: dev.w3.org/csswg/css-flexbox/#algo-stretch". – Joseph Silber Feb 06 '14 at 03:04
  • Thanks for nice example. It works smoothly but in my case I need `flex-flow: row wrap;` on the container + `flex: 1 100%;` on element to overflow (see [here](http://codepen.io/anon/pen/iKAdt)). That's pity, I will need to re-design HTML. – dma_k Oct 20 '14 at 16:53
  • This is not working properly in Chrome, the page header text [disappears more and more](http://i.imgur.com/asL5T9j.png) the more the content overflows. – phant0m Jun 25 '15 at 16:17
  • @phant0m - you can set the min-height on the page header to solve the disappearing header text problem, but as far as I can tell, this solution only works for Chrome. It doesn't work on Firefox, probably due to the bug mentioned by dholbert, and min-content isn't supported by IE according to caniuse, not even IE11. Guess I need to keep looking. – Dallan Quass Jul 24 '15 at 02:57
  • 5
    Yes, this is broken in IE11 – Steve May 05 '16 at 12:04
  • 2 years later: "Short columns being stretched" seems not to work anymore. – user2543253 Jul 11 '18 at 16:08
  • @user2543253 the columns are identified by the border between them, _not_ the red part. The red part is the content _inside_ the columns (looking back now, I see how that's confusing). – Joseph Silber Jul 12 '18 at 12:48
  • Thanks for the explanation. I had child divs of the flex child elements. That caused an issue. Fixed my problem with help from this article: https://css-tricks.com/flexbox-truncated-text/ I just wanted to leave the link, if it might help somebody – Imtiaz Jun 04 '20 at 13:39
  • This doesn't work in Chrome today (OSX Chrome Version 83.0.4103.97), the borders don't continue after the page fold, with or without the prefix. In safari it works – Jake Coxon Jun 11 '20 at 17:13
  • 1
    But probably a good idea to also point to https://stackoverflow.com/a/35609992/740553, below, because that's a solid solution for all those cases where this isn't (although if someone knows _why_ it works, as "here are the parts of the CSS/Flex specs that cause this to be true" explanation, all of SO and the wider web dev world would still greatly benefit from one =) – Mike 'Pomax' Kamermans Feb 17 '21 at 18:31
  • And the pen doesn't work if the body height isn't set or absolute is removed. – fionbio Oct 21 '22 at 19:23
222

I just solved this problem very elegantly after a lot of trial and error.

Check out my blog post: http://geon.github.io/programming/2016/02/24/flexbox-full-page-web-app-layout

Basically, to make a flexbox cell scrollable, you have to make all its parents overflow: hidden;, or it will just ignore your overflow settings and make the parent larger instead.

geon
  • 8,128
  • 3
  • 34
  • 41
  • 30
    This worked in my case as well, but wow, I'd really like to see an explanation of *why* it works. Most of the time, I find the CSS specs to be totally inscrutable for this kind of thing. – markrian Nov 08 '16 at 18:09
  • Any specific question that wasn't answered in the blog post? – geon Nov 09 '16 at 13:18
  • 5
    From your blog post: _"I have no idea why that works, and the specs says nothing either"_. So, I'm looking for an explanation of why it works. I've skimmed the specs, but as you said, nothing jumps out there. – markrian Nov 10 '16 at 13:45
  • 4
    After thinking about it some more, I think it makes sense. The default behaviour is for each div to expand to contain all of it's children, so there won't be any overflow to hide at the leaf nodes. You need to force overflow:hidden all the way from the top of the DOM, so no parent has the chance to accommodate it's children until you are down to the node you want to overflow and scroll. – geon Nov 11 '16 at 09:31
  • 4
    I'm not sure that really explains it. Setting overflow to hidden on an element doesn't stop it from expanding to contain all of its children, AFAIK. According to MDN: "The overflow property specifies whether to clip content, render scrollbars or just display content when it overflows its block level container." Additionally, setting overflow to anything other than visible creates a new block formatting context - but that can't be relevant, because flex containers already create their own block formatting context: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context. – markrian Nov 11 '16 at 11:53
  • 2
    I should add that I agree your explanation makes *intuitive* sense, but I don't think it's an accurate *technical* explanation, which is what I want. Only by truly understanding the reason will I be able to remember the the solution in future! – markrian Nov 11 '16 at 11:56
  • In my case (Chrome), I only needed to set the overflow on the parent that was the sibling of the footer. All other divs in the hierarchy were left with the default overflow and sized appropriately, with only the scrolled div showing up with scrollbars. I suspect that , because the height of the first child div (the one immediately inside the hidden-overflow dive) is set to 100%, it is setting itself to the _visible_ height. From there, all child divs are setting their height relative to that div's height. – seairth Mar 18 '21 at 18:17
  • 5
    I found the technical reason [here](https://medium.com/@stephenbunch/how-to-make-a-scrollable-container-with-dynamic-height-using-flexbox-5914a26ae336) and then [officially here (CSS spec)](https://drafts.csswg.org/css-flexbox-1/#min-size-auto). Basically, changing the overflow changes the min height automatic value. Try replacing the `overflow hidden` with `overflow auto` or `min height 0`. All should still work and the later should be preferred (or at least I understand that after reading the spec). – Noxware Feb 09 '22 at 03:22
  • 1
    I've read a gazillion posts about how to do this and this is the _only_ answer that solved my problem - bravo! – mikesol Aug 01 '22 at 19:11
  • thank you so much for this and the detailed writeup of your journey (in your blog post) – Jay Nov 22 '22 at 20:37
110

Working with position:absolute; along with flex:

Position the flex item with position: relative. Then inside of it, add another <div> element with:

position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;

This extends the element to the boundaries of its relative-positioned parent, but does not allow to extend it. Inside, overflow: auto; will then work as expected.

.all-0 {
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

p {
  text-align: justify;
}

.bottom-0 {
  bottom: 0;
}

.overflow-auto {
  overflow: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet" />


<div class="p-5 w-100">
  <div class="row bg-dark m-0">
    <div class="col-sm-9 p-0 d-flex flex-wrap">
      <!-- LEFT-SIDE - ROW-1 -->
      <div class="row m-0 p-0">
        <!-- CARD 1 -->
        <div class="col-md-8 p-0 d-flex">
          <div class="my-card-content bg-white p-2 m-2 d-flex flex-column">
            <img class="img img-fluid" src="https://via.placeholder.com/700x250">
            <h4>Heading 1</h4>
            <p>
              Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old...
          </div>
        </div>
        <!-- CARD 2 -->
        <div class="col-md-4 p-0 d-flex">
          <div class="my-card-content bg-white p-2 m-2 d-flex flex-column">
            <img class="img img-fluid" src="https://via.placeholder.com/400x250">
            <h4>Heading 1</h4>
            <p>
              Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old...
          </div>
        </div>
      </div>
      <div class="row m-0">
        <!-- CARD 3 -->
        <div class="col-md-4 p-0 d-flex">
          <div class="my-card-content bg-white p-2 m-2 d-flex flex-column">
            <img class="img img-fluid" src="https://via.placeholder.com/400x250">
            <h4>Heading 1</h4>
            <p>
              Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old...
          </div>
        </div>
        <!-- CARD 4 -->
        <div class="col-md-4 p-0 d-flex">
          <div class="my-card-content bg-white p-2 m-2 d-flex flex-column">
            <img class="img img-fluid" src="https://via.placeholder.com/400x250">
            <h4>Heading 1</h4>
            <p>
              Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old...
          </div>
        </div>
        <!-- CARD 5-->
        <div class="col-md-4 p-0 d-flex">
          <div class="my-card-content bg-white p-2 m-2 d-flex flex-column">
            <img class="img img-fluid" src="https://via.placeholder.com/400x250">
            <h4>Heading 1</h4>
            <p>
              Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old...
          </div>
        </div>
      </div>
    </div>
    <div class="col-sm-3 p-0">
      <div class="bg-white m-2 p-2 position-absolute all-0 d-flex flex-column">
        <h4>Social Sidebar...</h4>
        <hr />
        <div class="d-flex overflow-auto">
          <p>
            Topping candy tiramisu soufflé fruitcake ice cream chocolate bar. Bear claw ice cream chocolate bar donut sweet tart. Pudding cupcake danish apple pie apple pie. Halva fruitcake ice cream chocolate bar. Bear claw ice cream chocolate bar donut sweet tart.
            opping candy tiramisu soufflé fruitcake ice cream chocolate bar. Bear claw ice cream chocolate bar donut sweet tart. Pudding cupcake danish apple pie apple pie. Halva fruitcake ice cream chocolate bar. Bear claw ice cream chocolate bar donut
            sweet tart. opping candy tiramisu soufflé fruitcake ice cream chocolate bar. Bear claw ice cream chocolate bar donut sweet tart. Pudding cupcake danish apple pie apple pie. Halva fruitcake ice cream chocolate bar. Bear claw ice cream chocolate
            bar donut sweet tart. Pudding cupcake danish apple pie apple pie. Halvafruitcake ice cream chocolate bar. Bear claw ice cream chocolate bar donut sweet tart. Pudding cupcake danish apple pie apple pie. Halvafruitcake ice cream chocolate bar.
            Bear claw ice cream chocolate bar donut sweet tart. Pudding cupcake danish apple pie apple pie. Halvafruitcake ice cream chocolate bar. Bear claw ice cream chocolate bar donut sweet tart. Pudding cupcake danish apple pie apple pie. Halvafruitcake
            ice cream chocolate bar. Bear claw ice cream chocolate bar donut sweet tart. Pudding cupcake danish apple pie apple pie. Topping candy tiramisu soufflé fruitcake ice cream chocolate bar. Bear claw ice cream chocolate bar donut sweet tart.
            Pudding cupcake danish apple pie apple pie. Halva fruitcake ice cream chocolate bar. Bear claw ice cream chocolate bar donut sweet tart. opping candy tiramisu soufflé fruitcake ice cream chocolate bar. Bear claw ice cream chocolate bar donut
            sweet tart. Pudding cupcake danish apple pie apple pie. Halva fruitcake ice cream chocolate bar. Bear claw ice cream chocolate bar donut sweet tart. opping candy tiramisu soufflé fruitcake ice cream chocolate bar. Bear claw ice cream chocolate
            bar donut sweet tart. Pudding cupcake danish apple pie apple pie. Halva fruitcake ice cream chocolate bar. Bear claw ice cream chocolate bar donut sweet tart. Pudding cupcake danish apple pie apple pie. Halvafruitcake ice cream chocolate bar.
            Bear claw ice cream chocolate bar donut sweet tart. Pudding cupcake danish apple pie apple pie. Halvafruitcake ice cream chocolate bar. Bear claw ice cream chocolate bar donut sweet tart. Pudding cupcake danish apple pie apple pie. Halvafruitcake
            ice cream chocolate bar. Bear claw ice cream chocolate bar donut sweet tart. Pudding cupcake danish apple pie apple pie. Halvafruitcake ice cream chocolate bar. Bear claw ice cream chocolate bar donut sweet tart. Pudding cupcake danish apple
            pie apple pie. Halva
        </div>
      </div>
    </div>
  </div>

End result: image of end result showing a flex layout

CodePen Link

Aakash
  • 21,375
  • 7
  • 100
  • 81
  • 3
    This solution is especially useful if the component inside has padding set because it will lock it nicely in position wherever you want. It's much simpler. (Yes you could set `box-sizing: border-box` instead but that can be more complex for certain third party controls). – Simon_Weaver Feb 23 '19 at 05:32
15

The following CSS changes in bold (plus a bunch of content in the columns to test scrolling) will work. Well, it makes each content column individually scrollable, which may be more (better?) than originally requested. Anyway, see the result in this Pen.

.content { flex: 1; display: flex; height: 1px; }

.column { padding: 20px; border-right: 1px solid #999; overflow: auto; }

The trick here seems to be that a scrollable panel needs to have a height literally set somewhere (in this case, via its parent), not just determined by flexbox. So even height: 1px works. The flex-grow:1 will still size the panel to fit properly.

Chris Janicki
  • 521
  • 6
  • 6
  • Funny enough it works with `height: 0px`. This one is very useful when using nested layouts and such. Other solutions depend heavily on either `vh` `vw` or absolute positioning. – Artur Bodera Jun 21 '23 at 22:46
13

A little late but this could help: http://webdesign.tutsplus.com/tutorials/how-to-make-responsive-scrollable-panels-with-flexbox--cms-23269

Basically you need to put html,body to height: 100%; and wrap all your content into a <div class="wrap"> <!-- content --> </div>

CSS:

html, body {
  height: 100%;
}
 
.wrap {
  height: 100vh;
  display: flex;
}
TylerH
  • 20,799
  • 66
  • 75
  • 101
Doua Beri
  • 10,612
  • 18
  • 89
  • 138
  • 4
    You should be very careful when using "height: 100vh" as it measures differently in iOS Safari vs Android. One takes into account the height of the URL bar and the other does not. – Sean Anderson Jun 06 '20 at 02:14
  • this only works if the thing you want to scroll is the full height of the screen. If you add (for example) a header div you're back to square one – Liam Apr 13 '22 at 12:17
  • Thank you for this trick, works like a charm! – bgrand-ch Jun 09 '23 at 12:59
13

I didn't see this answer anywhere. But the trick I needed was to make sure the items had a flex-shrink: 0; else they'll get squeezed.

.container {
  display: flex;
  overflow: auto
}

.container > * {
  flex-shrink: 0;
  width: 10em;
  height: 10em;
  background: linear-gradient(to bottom right, #F0F, #0FF);
}
<div class="container">
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
</div>
Seph Reed
  • 8,797
  • 11
  • 60
  • 125
  • thank you so much. i have a layout that uses `min-height: 0` on all flex containers to allow children to be scrollable. that caused some things to shrink and overlap, but your `.container > *` thing fixed it – Dull Bananas Jul 22 '22 at 03:59
  • I think your example works because you've set your height: *height: 10em;* – Bogdan U Mar 14 '23 at 15:44
10

Add this:

align-items: flex-start;

to the rule for .content {}. That fixes it in your pen for me, at least (in both Firefox & Chrome).

By default, .content has align-items: stretch, which makes it size all of its auto-height children to match its own height, per http://dev.w3.org/csswg/css-flexbox/#algo-stretch. In contrast, the value flex-start lets the children compute their own heights, and align themselves at its starting edge (and overflow, and trigger a scrollbar).

amoebe
  • 4,857
  • 5
  • 37
  • 42
dholbert
  • 11,386
  • 3
  • 42
  • 31
5

One issue that I've come across is that to have a scrollbar a n element needs a height to be specified (and not as a %).

The trick is to nest another set of divs within each column, and set the column parent's display to flex with flex-direction: column.

<style>
    html, body {
        height: 100%;
        margin: 0;
        padding: 0;
    }

    body {
        overflow-y: hidden;
        overflow-x: hidden;
        color: white;
    }

    .base-container {
        display: flex;
        flex: 1;
        flex-direction: column;
        width: 100%;
        height: 100%;
        overflow-y: hidden;
        align-items: stretch;
    }

    .title {
        flex: 0 0 50px;
        color: black;
    }

    .container {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
    }

        .container .header {
            flex: 0 0 50px;
            background-color: red;
        }

        .container .body {
            flex: 1 1 auto;
            display: flex;
            flex-direction: row;
        }

            .container .body .left {
                display: flex;
                flex-direction: column;
                flex: 0 0 80px;
                background-color: blue;
            }
                .container .body .left .content,
                .container .body .main .content,
                .container .body .right .content {
                    flex: 1 1 auto;
                    overflow-y: auto;
                    height: 100px;
                }
                .container .body .main .content.noscrollbar {
                    overflow-y: hidden;
                }

            .container .body .main {
                display: flex;
                flex-direction: column;
                flex: 1 1 auto;
                background-color: green;
            }

            .container .body .right {
                display: flex;
                flex-direction: column;
                flex: 0 0 300px;
                background-color: yellow;
                color: black;
            }

    .test {
        margin: 5px 5px;
        border: 1px solid white;
        height: calc(100% - 10px);
    }
</style>

And here's the html:

<div class="base-container">
    <div class="title">
        Title
    </div>
    <div class="container">
        <div class="header">
            Header
        </div>
        <div class="body">
            <div class="left">
                <div class="content">
                    <ul>
                        <li>1</li>
                        <li>2</li>
                        <li>3</li>
                        <li>4</li>
                        <li>5</li>
                        <li>6</li>
                        <li>7</li>
                        <li>8</li>
                        <li>9</li>
                        <li>10</li>
                        <li>12</li>
                        <li>13</li>
                        <li>14</li>
                        <li>15</li>
                        <li>16</li>
                        <li>17</li>
                        <li>18</li>
                        <li>19</li>
                        <li>20</li>
                        <li>21</li>
                        <li>22</li>
                        <li>23</li>
                        <li>24</li>
                    </ul>
                </div>
            </div>
            <div class="main">
                <div class="content noscrollbar">
                    <div class="test">Test</div>
                </div>
            </div>
            <div class="right">
                <div class="content">
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>Right</div>
                    <div>End</div>
                </div>
            </div>
        </div>
    </div>
</div>

https://jsfiddle.net/LiamFlavelle/czpjdfr4/

Liam
  • 5,033
  • 2
  • 30
  • 39
5

The solution for this problem is just to add overflow: auto; to the .content for making the content wrapper scrollable.

Furthermore, there are circumstances occurring along with Flexbox wrapper and overflowed scrollable content like this codepen.

The solution is to add overflow: hidden (or auto); to the parent of the wrapper (set with overflow: auto;) around large contents.

Dognose
  • 69
  • 1
  • 4
2

I tried a lot of the answers above without much joy. I suspect that a lot of these answers are out of date or just didn't fit my requirements. The answer to my problem came from a related question:

The Automatic Minimum Size of Flex Items

You're encountering a flexbox default setting.

A flex item cannot be smaller than the size of its content along the main axis.

So the thing that was preventing my flex box item from scrolling was that the size of the element would automatically adjust to auto based on the content and then resize, not scroll. Here's a fully working modern example (using tailwind):

<!DOCTYPE html>
<html class="h-full">
    <head>
        <script src="https://cdn.tailwindcss.com"></script>
    </head>
    <body class="h-full">
        <div class="h-full flex flex-col items-stretch">
            <div class="bg-white border-b border-gray-400">
              <h1>
                Header
              </h1>
            </div>
            <div class="flex flex-row flex-auto min-h-0">
                <div class="flex flex-col bg-red-600 items-stretch min-h-0" style="flex: 0 0 25%;">
                    <div class="flex-initial min-h-0 overflow-x-hidden overflow-y-auto">
                        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque feugiat libero id elementum iaculis. Vestibulum at mauris mauris. Donec blandit nibh rhoncus mollis mattis. Aenean gravida ex sagittis semper aliquet. Suspendisse a dolor enim. Fusce sagittis lectus et eleifend imperdiet. Curabitur iaculis pellentesque rutrum. Fusce et gravida eros. Nam vestibulum pharetra lorem, sed semper leo fermentum nec.</p>
                        
                        <p>Curabitur varius feugiat maximus. Morbi dolor urna, consectetur ac nisl eget, varius pretium sem. Curabitur aliquam, lectus ut viverra consequat, dolor ligula gravida ex, nec dictum felis mi in enim. Curabitur luctus ligula diam, sed varius orci vehicula a. Ut vehicula imperdiet tempor. Morbi eget sollicitudin mi. Etiam condimentum sem arcu, non dignissim mi ultricies ut. Fusce faucibus sem nec laoreet facilisis. Nullam ut lorem vitae odio gravida rhoncus. Etiam ut orci vitae odio interdum consequat.</p>
                        
                        <p>Sed felis dui, fermentum ac libero ut, faucibus mattis urna. Morbi at est lobortis, lobortis diam nec, rhoncus augue. Sed at turpis malesuada nulla accumsan accumsan. Mauris pharetra, odio at elementum pharetra, lacus magna luctus sem, sit amet pretium lorem lectus sed libero. Curabitur ullamcorper turpis nunc, a eleifend urna venenatis ac. Vivamus consectetur, nunc quis facilisis vehicula, risus ligula finibus arcu, at vulputate ex dui lobortis dolor. Maecenas tincidunt, lacus et vehicula pulvinar, enim sem venenatis nisi, nec fringilla eros felis quis mauris. Duis luctus eu risus condimentum rutrum. Suspendisse interdum at velit eget mattis. Integer quis porta nisl. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc iaculis, lacus ut dignissim imperdiet, enim enim malesuada quam, id pretium justo neque id ipsum. Vestibulum nec nisl mattis, mattis est sed, venenatis lectus. Quisque sed magna nec purus viverra rhoncus dapibus sed sapien. Quisque id fermentum risus, non vestibulum justo. Donec ultrices enim quis eros porttitor, non posuere tortor viverra.</p>
                        
                        <p>Phasellus leo ipsum, tristique nec tristique sit amet, molestie eget urna. Aenean suscipit eget ante in vulputate. Morbi tincidunt velit quis lorem gravida, ac scelerisque massa aliquet. Aliquam sem lacus, bibendum ut elit at, mollis dapibus ligula. Suspendisse potenti. Fusce neque est, lobortis a augue a, pretium fermentum turpis. Etiam molestie et odio non rhoncus. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus condimentum cursus metus eu hendrerit. Vestibulum ultrices, leo eget consectetur tempus, nisi diam maximus orci, sit amet ultricies leo mauris vitae eros.</p>
                        
                        <p>Aenean eleifend pretium libero ut venenatis. Quisque maximus nulla eget arcu maximus, id rhoncus lectus lobortis. Nullam at ullamcorper nisi. Aliquam erat volutpat. Curabitur efficitur ante in fermentum euismod. Donec id arcu finibus, finibus mauris id, tempor nisl. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam lobortis feugiat ligula, id aliquet elit placerat ut. In ac mi elementum, varius urna a, condimentum urna. Sed luctus massa nulla, quis elementum sapien lacinia eu. Vestibulum risus leo, rutrum ac finibus in, iaculis at ligula. Nullam hendrerit mattis eleifend. Sed egestas lectus eu vulputate malesuada.</p>
                    </div>
                </div>
                    
                <div class="flex flex-col items-stretch min-h-0 flex-auto">
                    <div class="flex-initial min-h-0 overflow-x-hidden overflow-y-auto">
                        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque feugiat libero id elementum iaculis. Vestibulum at mauris mauris. Donec blandit nibh rhoncus mollis mattis. Aenean gravida ex sagittis semper aliquet. Suspendisse a dolor enim. Fusce sagittis lectus et eleifend imperdiet. Curabitur iaculis pellentesque rutrum. Fusce et gravida eros. Nam vestibulum pharetra lorem, sed semper leo fermentum nec.</p>
                        
                        <p>Curabitur varius feugiat maximus. Morbi dolor urna, consectetur ac nisl eget, varius pretium sem. Curabitur aliquam, lectus ut viverra consequat, dolor ligula gravida ex, nec dictum felis mi in enim. Curabitur luctus ligula diam, sed varius orci vehicula a. Ut vehicula imperdiet tempor. Morbi eget sollicitudin mi. Etiam condimentum sem arcu, non dignissim mi ultricies ut. Fusce faucibus sem nec laoreet facilisis. Nullam ut lorem vitae odio gravida rhoncus. Etiam ut orci vitae odio interdum consequat.</p>
                        
                        <p>Sed felis dui, fermentum ac libero ut, faucibus mattis urna. Morbi at est lobortis, lobortis diam nec, rhoncus augue. Sed at turpis malesuada nulla accumsan accumsan. Mauris pharetra, odio at elementum pharetra, lacus magna luctus sem, sit amet pretium lorem lectus sed libero. Curabitur ullamcorper turpis nunc, a eleifend urna venenatis ac. Vivamus consectetur, nunc quis facilisis vehicula, risus ligula finibus arcu, at vulputate ex dui lobortis dolor. Maecenas tincidunt, lacus et vehicula pulvinar, enim sem venenatis nisi, nec fringilla eros felis quis mauris. Duis luctus eu risus condimentum rutrum. Suspendisse interdum at velit eget mattis. Integer quis porta nisl. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc iaculis, lacus ut dignissim imperdiet, enim enim malesuada quam, id pretium justo neque id ipsum. Vestibulum nec nisl mattis, mattis est sed, venenatis lectus. Quisque sed magna nec purus viverra rhoncus dapibus sed sapien. Quisque id fermentum risus, non vestibulum justo. Donec ultrices enim quis eros porttitor, non posuere tortor viverra.</p>
                        
                        <p>Phasellus leo ipsum, tristique nec tristique sit amet, molestie eget urna. Aenean suscipit eget ante in vulputate. Morbi tincidunt velit quis lorem gravida, ac scelerisque massa aliquet. Aliquam sem lacus, bibendum ut elit at, mollis dapibus ligula. Suspendisse potenti. Fusce neque est, lobortis a augue a, pretium fermentum turpis. Etiam molestie et odio non rhoncus. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus condimentum cursus metus eu hendrerit. Vestibulum ultrices, leo eget consectetur tempus, nisi diam maximus orci, sit amet ultricies leo mauris vitae eros.</p>
                        
                        <p>Aenean eleifend pretium libero ut venenatis. Quisque maximus nulla eget arcu maximus, id rhoncus lectus lobortis. Nullam at ullamcorper nisi. Aliquam erat volutpat. Curabitur efficitur ante in fermentum euismod. Donec id arcu finibus, finibus mauris id, tempor nisl. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam lobortis feugiat ligula, id aliquet elit placerat ut. In ac mi elementum, varius urna a, condimentum urna. Sed luctus massa nulla, quis elementum sapien lacinia eu. Vestibulum risus leo, rutrum ac finibus in, iaculis at ligula. Nullam hendrerit mattis eleifend. Sed egestas lectus eu vulputate malesuada.</p>

                    </div>
                </div>
            </div>
          </div>
    </body>
</html>

Which renders like this in Chrome (100) enter image description here

Liam
  • 27,717
  • 28
  • 128
  • 190
1
.list-wrap {
  width: 355px;
  height: 100%;
  position: relative;

  .list {
    position: absolute;
    top: 0;
    bottom: 0;
    overflow-y: auto;
    width: 100%;
  }
}
zhishaofei3
  • 117
  • 1
  • 5