css - How to make flexbox children 100% height of their parent? -
i'm trying fill vertical space of flex item inside flexbox.
.container { height: 200px; width: 500px; display: -moz-box; display: -webkit-flexbox; display: -ms-flexbox; display: -webkit-flex; display: -moz-flex; display: flex; -webkit-flex-direction: row; -moz-flex-direction: row; -ms-flex-direction: row; flex-direction: row; } .flex-1 { width: 100px; background-color: blue; } .flex-2 { position: relative; -moz-box-flex: 1; -webkit-flex: 1; -moz-flex: 1; -ms-flex: 1; flex: 1; background-color: red; } .flex-2-child { height: 100%; width: 100%; background-color: green; }
<div class="container"> <div class="flex-1"></div> <div class="flex-2"> <div class="flex-2-child"></div> </div> </div>
and here's jsfiddle
flex-2-child
doesn't fill required height except in 2 cases where:
flex-2
has height of 100% (which weird because flex item has 100% default + buggy in chrome)flex-2-child
has position absolute inconvenient
this doesn't work in chrome or firefox currently.
i have answered similar question here.
i know have said position: absolute;
inconvenient works. see below further information on fixing resize issue.
also see jsfiddle demo, although have added webkit prefixes open in chrome.
you have 2 issues deal separately.
- getting child of flex-item fill height 100%
- set
position: relative;
on parent of child. - set
position: absolute;
on child. - you can set width/height required (100% in sample).
- set
- fixing resize scrolling "quirk" in chrome
- put
overflow-y: auto;
on scrollable div. - the scrollable div must have explicit height specified. sample has height 100% if none applied can specify
height: 0;
- put
see answer more information on scrolling issue.
Comments
Post a Comment