Can anyone explain this behavior? I've created two stacked flexbox children to be a simple outline for a full-screen web app. However, adding content inside of my top element seems to expand it, eventually pushing the bottom one off of the screen.
var buttonEl = document.getElementById('addButton');
buttonEl.addEventListener('click', function() {
var newEl,
ulEl;
// Create a list item element
newEl = document.createElement('li');
newEl.innerHTML = "Test List Item";
// Add the list item element to the list
ulEl = document.getElementById('list');
ulEl.appendChild(newEl);
}, false);
* {
padding: 0px;
margin: 0px;
overflow: hidden;
}
html {
width: 100%;
height: 100%;
}
body {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
background: lightblue;
}
#top {
flex-grow: 1;
overflow-y: auto;
}
#bottom {
flex-basis: 1em;
}
li {
width: 100%;
height: 2em;
line-height: 2em;
background: white;
}
<div id="top">
<button id="addButton">add list item</button>
<ul id="list">
</ul>
</div>
<div id="bottom">
Bottom
</div>
You can do this by setting the child to be position: absolute. Usually, this should work: overflow: hidden doesn't clip absolutely positioned descendants unless the same container doesn't have position:relative (see cssmojo.com/clearfix-reloaded-overflowhidden-demystified).
visible - Default. The overflow is not clipped. The content renders outside the element's box. hidden - The overflow is clipped, and the rest of the content will be invisible.
To change this, set the min-width or min-height property.” This means that a flex item with a long word won't shrink below its minimum content size. To fix this, we can either use an overflow value other than visible , or we can set min-width: 0 on the flex item.
Here's one way to do it: http://jsfiddle.net/1ejgybmv/.
* {
padding: 0px;
margin: 0px;
}
html, body {
height: 100%;
}
body {
display: flex;
flex-direction: column;
background: lightblue;
}
#top {
flex: 1 1 auto;
overflow-y: auto;
}
#bottom {
flex: 0 0 1em;
}
li {
height: 2em;
line-height: 2em;
background: white;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With