html - Make flex item have 100% height and overflow: scroll -


this question has answer here:

i want flex item take 100% of remaining height , display overflow: scroll bar.

it looks problem comes #userlist takes 100% of window height , not taking remaining space .

body {    display: flex;     flex-direction: column;     min-height: 100%;     margin:0px;  }  .wrapper {    display: block;     flex: 1 1 auto;     display: flex;    flex-direction: row; /  }    #chatcontainer {  	background: orange;  	width: calc(100% - 350px);  	display: flex;  	flex-direction: column;  }  #tabs{  	background-color: red;  	flex: 1 1 0px;  	display: flex;	  }  #userscontainer {    flex: 1 1 0;     display:flex;    flex-direction:column;  }  #userlistwrapper {  	background-color:pink;  	flex: 1 1 auto;  	display:flex;  }  #userlist {      -webkit-flex: 1 1 auto;      overflow: auto;      min-height: 0px;      height:100%;    }  .input {  	background-color: #49fffc;  }
  <div class="wrapper">      <div id="chatcontainer">        <div id="webcamcontainer">webcam</div>        <div id="tabs">tabs here</div>        <div id="footer"  style="background-color:#a0c8ff;height:50px">footer</div>      </div>      <div id="userscontainer" style="background-color:blue">                <div class="input">searchinput1</div>        <div class="input">searchinput2</div>                <div id="userlist">                user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>                user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>                user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>                user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>user1<br>user2<br>            </div>          </div>    </div> 

https://jsfiddle.net/jpo31gq9/

the main problem having violation of rules governing percentage heights in css.

basically, when using percentage heights, must specify height of parent element. otherwise, element percentage height has no frame of reference, , height computes auto (the height of content).

from spec:

css height property

percentage
specifies percentage height. percentage calculated respect height of generated box's containing block. if height of containing block not specified explicitly , element not absolutely positioned, value computes "auto".

auto
height depends on values of other properties.

source: https://www.w3.org/tr/css21/visudet.html#propdef-height

so if plan use percentage heights, need specify height on every parent element root element (html) or fixed height declaration (such height: 250px).

in css, have body { min-height: 100%; }. however, there no height specified on parent (html).

the following parent elements in code missing height declaration:

  • html
  • body (min-height doesn't count)
  • .wrapper
  • #chatcontainer

with following adjustments layout works.

html { height: 100%; }              /* new */  body {     display: flex;     flex-direction: column;     /* min-height: 100%; */     margin: 0px;     height: 100%;                  /* new */ }  .wrapper {     display: block;     flex: 1 1 auto;     display: flex;     flex-direction: row;     height: 100%;                  /* new */ }  #chatcontainer {     background: orange;     width: calc(100% - 350px);     display: flex;     flex-direction: column;     height: 100%;                  /* new */ } 

revised fiddle


it's worth mentioning variations among current browsers.

percentage heights: chrome/safari vs firefox/ie

although traditional implementation of percentage heights uses value of height property, browsers have broadened scope.

as evidenced in following posts, firefox , ie using flex heights resolve percentage height of child elements.

bottom line: chrome , safari resolve percentage heights based on value of parent's height property. firefox , ie11/edge use parent's computed flex height.

for now, simplest cross-browser solution problem be, in view, using height property across board percentage heights.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -