CSS3 Flexbox Full-Height App and Overflow

CSS3 Flexbox full-height app and overflow

I can't say for sure if that's a browser bug or if it is in fact how the flex model is supposed to work. If that is how it should work I'd agree that's not exactly intuitive!

I found a work around by wrapping the lists in an absolutely positioned div with the overflow set to auto. This allows the flex boxes to maintain their original states and only change when the entire layout is recalculated vs. the content changing.

Here's the updated markup:

<section id="folders">
<div class="dynamicList">
<h2>Folders</h2>
<ul>
<li>Folder 1</li>
<li>Folder 2</li>
</ul>
<a href="#" id="add">Add Folder</a>
</div>
</section>

And the updated CSS:

#left #tasks,
#left #folders {
position: relative;
}

.dynamicList {
bottom: 0;
left: 0;
overflow: auto;
position: absolute;
right: 0;
top: 0;
}

I forked your fiddle here to demo:
http://jsfiddle.net/MUWhy/4/

UPDATE:

If you want the headings to remain fixed and only have the contents of the folder and tasks lists scroll, then I would consider putting the headings and the add buttons in their own fixed-height boxes within the #left div. It's a bit more mark up but still pretty simple. I haven't tried it on JSFiddle but I think that would be the best route to go.

How can I make Flexbox container take up full height of parent and be scrollable?

I would simplify your code and use CSS grid instead of flexbox

body {
overflow: hidden;
margin:0;
}

p {
padding: 30px 0;
background: lightGray;
}

.app {
display: grid; /* grid container */
height: 100vh; /* height on the upper container */
}

.app * {
display: inherit; /* cascading grid */
min-height: 0; /* related question : https://stackoverflow.com/a/43312314/8620333 */
}

.container-5 {
overflow: auto; /* scroll here */
}
<div class="app">
<div class="container-1">
<div class="container-2">
<div class="container-3">
<div class="container-4">
<div class="container-5">
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
</div>
</div>
</div>
</div>
</div>
</div>

How can I combine flexbox and vertical scroll in a full-height app?

Thanks to https://stackoverflow.com/users/1652962/cimmanon that gave me the answer.

The solution is setting a height to the vertical scrollable element. For example:

#container article {
flex: 1 1 auto;
overflow-y: auto;
height: 0px;
}

The element will have height because flexbox recalculates it unless you want a min-height so you can use height: 100px; that it is exactly the same as: min-height: 100px;

#container article {
flex: 1 1 auto;
overflow-y: auto;
height: 100px; /* == min-height: 100px*/
}

So the best solution if you want a min-height in the vertical scroll:

#container article {
flex: 1 1 auto;
overflow-y: auto;
min-height: 100px;
}

If you just want full vertical scroll in case there is no enough space to see the article:

#container article {
flex: 1 1 auto;
overflow-y: auto;
min-height: 0px;
}

The final code: http://jsfiddle.net/ch7n6/867/

How can I make Flexbox children 100% height of their parent?

Use align-items: stretch

Similar to David Storey's answer, my workaround is:

.flex-2 {
display: flex;
align-items: stretch;
}

Note that height: 100% should be removed from the child component (see comments).

Alternatively to align-items, you can use align-self just on the .flex-2-child item you want stretched.

Make a div fill the height of the remaining screen space

2015 update: the flexbox approach

There are two other answers briefly mentioning flexbox; however, that was more than two years ago, and they don't provide any examples. The specification for flexbox has definitely settled now.

Note: Though CSS Flexible Boxes Layout specification is at the Candidate Recommendation stage, not all browsers have implemented it. WebKit implementation must be prefixed with -webkit-; Internet Explorer implements an old version of the spec, prefixed with -ms-; Opera 12.10 implements the latest version of the spec, unprefixed. See the compatibility table on each property for an up-to-date compatibility status.

(taken from https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes)

All major browsers and IE11+ support Flexbox. For IE 10 or older, you can use the FlexieJS shim.

To check current support you can also see here:
http://caniuse.com/#feat=flexbox

Working example

With flexbox you can easily switch between any of your rows or columns either having fixed dimensions, content-sized dimensions or remaining-space dimensions. In my example I have set the header to snap to its content (as per the OPs question), I've added a footer to show how to add a fixed-height region and then set the content area to fill up the remaining space.

html,body {  height: 100%;  margin: 0;}
.box { display: flex; flex-flow: column; height: 100%;}
.box .row { border: 1px dotted grey;}
.box .row.header { flex: 0 1 auto; /* The above is shorthand for: flex-grow: 0, flex-shrink: 1, flex-basis: auto */}
.box .row.content { flex: 1 1 auto;}
.box .row.footer { flex: 0 1 40px;}
<!-- Obviously, you could use HTML5 tags like `header`, `footer` and `section` -->
<div class="box"> <div class="row header"> <p><b>header</b> <br /> <br />(sized to content)</p> </div> <div class="row content"> <p> <b>content</b> (fills remaining space) </p> </div> <div class="row footer"> <p><b>footer</b> (fixed height)</p> </div></div>

Can't set full height for flexbox child , any help would be appretiated HTML CSS SASS Web Design

I believe I understand what you're saying,

(If this is completely wrong let me know an I'll update it!)

you need to add a height to the body, perhaps a min-height would help

body {
min-height: 100vh;
}

this sets the height to be ATLEAST the the height of the viewport.

Take a look,
https://codepen.io/looskie-the-flexboxer/pen/abqjOge

How to prevent a flex item height to overflow due to it's content

You need to add min-height: 0 to your .main-content CSS rule. That prevents that element from stretching to contain its children and pushing the footer offscreen (which is the bad behavior that you're trying to avoid).

This happens because flex items (children of a flex container) establish a default minimum main-size, based on their contents, and will refuse to be smaller than that minimum. In your case (with the outer flex container being vertically-oriented), "main-size" is height, and the flex item in question (.main-content) is establishing a content-based min-height.

(If you want the list items to be scrollable, then you may want to also add overflow-y:auto to .main-content)

Flexbox under overflow not taking full width

The problem is that the container with the blue background is taking the width of the parent and not the content, to solve this you can change its property "display" to "inline-flex".

Then if you change the "flex" property of the .cell class to a "width" property the width you set will count for the parent and it will reach the blue container making it fill all the content.

      .problem {
display: inline-flex;
height: 100%;
background-color: blue;
}

.cell {
align-self: stretch;
width: 100px;
}


Related Topics



Leave a reply



Submit