html - How do I ensure the contents of my flex div stay within it's container? -


i have flexbox div 3 items in it. direction column.

the flexbox div doesn't have height, container has max-height.

the maxheight works container, middle item in flexbox div huge , goes way outside bounds of it's container.

here's codepen illustrating issue: http://codepen.io/jaman4dbz/pen/bwednn

you'll see body has computed height of 600px or such (depending on window height), while app div waaaaay larger.

the ultimate goal have large div stretch contents of flex div until reaches max-height, stop. want middle large div responsive.

* { box-sizing: border-box; }    body {       height: 100vh;      margin: 0;       font-family: helvetica, arial, sans-serif;  }    .twocol {      display: flex;  }    .app {      height: auto;      width: 100%;      /* height: 100vh; */      background: cadetblue;      display: flex;      flex-direction: column;      justify-content: space-between;      margin: auto;  }    /**   * note demo work fine in ie10. because in ie10, flex-shrink 0 instead of 1.  see: https://github.com/philipwalton/flexbugs#6-the-default-flex-value-has-changed   **/  .header {      width: 100%;      background: orchid;  }    /**   * 1. ie needs display: block on main element.   * 2. ie10 sets flex-shrink 0. according spec, has since changed. see: https://github.com/philipwalton/flexbugs#6-the-default-flex-value-has-changed   **/  .main {      display: block; /* 1 */      flex-grow: 1;      flex-shrink: 1; /* 2 */      background: blanchedalmond;      overflow: auto;      padding: 0 20px;  }    .footer {      width: 100%;      background: coral;  }    h1 { font-size: 36px; }  p { font-size: 16px; }
<body class="twocol">      <div class="app">          <header class="header">              <p>hello</p>          </header>          <main class="main">              <h1>cupcake ipsum dolor sit amet</h1>              <p>fruitcake macaroon candy canes marshmallow gummi bears biscuit love dessert. oat cake sugar plum marzipan gummi bears marshmallow love brownie jelly bonbon. sweet roll apple pie wafer fruitcake. gummi bears lemon drops sesame snaps. biscuit tiramisu sugar plum. carrot cake pastry cupcake tootsie roll chocolate jujubes. pudding muffin sweet. cheesecake candy canes wafer gingerbread sweet.</p>        <p>fruitcake macaroon candy canes marshmallow gummi bears biscuit love dessert. oat cake sugar plum marzipan gummi bears marshmallow love brownie jelly bonbon. sweet roll apple pie wafer fruitcake. gummi bears lemon drops sesame snaps. biscuit tiramisu sugar plum. carrot cake pastry cupcake tootsie roll chocolate jujubes. pudding muffin sweet. cheesecake candy canes wafer gingerbread sweet.</p>        <p>fruitcake macaroon candy canes marshmallow gummi bears biscuit love dessert. oat cake sugar plum marzipan gummi bears marshmallow love brownie jelly bonbon. sweet roll apple pie wafer fruitcake. gummi bears lemon drops sesame snaps. biscuit tiramisu sugar plum. carrot cake pastry cupcake tootsie roll chocolate jujubes. pudding muffin sweet. cheesecake candy canes wafer gingerbread sweet.</p>        <p>fruitcake macaroon candy canes marshmallow gummi bears biscuit love dessert. oat cake sugar plum marzipan gummi bears marshmallow love brownie jelly bonbon. sweet roll apple pie wafer fruitcake. gummi bears lemon drops sesame snaps. biscuit tiramisu sugar plum. carrot cake pastry cupcake tootsie roll chocolate jujubes. pudding muffin sweet. cheesecake candy canes wafer gingerbread sweet.</p>        <p>fruitcake macaroon candy canes marshmallow gummi bears biscuit love dessert. oat cake sugar plum marzipan gummi bears marshmallow love brownie jelly bonbon. sweet roll apple pie wafer fruitcake. gummi bears lemon drops sesame snaps. biscuit tiramisu sugar plum. carrot cake pastry cupcake tootsie roll chocolate jujubes. pudding muffin sweet. cheesecake candy canes wafer gingerbread sweet.</p>              <p>liquorice candy canes cake. gummies wafer tart topping pastry soufflé love pie. cake cookie croissant cupcake chocolate cake. liquorice jelly beans pudding sugar plum biscuit fruitcake. soufflé tootsie roll macaroon pudding. chocolate cake cake sesame snaps sugar plum biscuit love croissant icing. caramels jelly dessert candy bonbon bear claw chocolate bar cheesecake icing. toffee love cake gingerbread jelly-o tootsie roll. sesame snaps pie cupcake sweet. croissant danish brownie gummies lollipop chupa chups gummies danish.</p>              <p>chupa chups pudding topping caramels pie. tart jujubes ice cream muffin sugar plum. soufflé candy canes love lollipop pastry brownie danish apple pie. apple pie chupa chups biscuit chocolate bar love muffin love. caramels cupcake love sugar plum icing candy canes love macaroon. marzipan danish cheesecake marshmallow jelly. jelly-o sugar plum liquorice donut love pastry candy donut. love gummi bears chocolate.</p>              <p>gingerbread toffee pastry gingerbread love toffee. biscuit jelly wafer love cheesecake candy canes chocolate cake. love cake love cotton candy muffin oat cake love love. love bonbon macaroon toffee powder chupa chups cotton candy tootsie roll chocolate. croissant dessert chocolate bar. apple pie love croissant sugar plum cotton candy love. candy canes jelly love. jelly beans cupcake brownie pudding lemon drops</p>              <p>cheesecake macaroon toffee sesame snaps cotton candy cotton candy love. cake sugar plum sweet marshmallow love. soufflé liquorice ice cream candy canes love tootsie roll marzipan biscuit jelly. love love tiramisu donut. love bear claw pastry toffee. cheesecake apple pie bonbon bear claw jelly-o topping tootsie roll chocolate bar. cake bonbon toffee donut macaroon chocolate lemon drops gummies gummies. jelly beans chocolate bar cotton candy halvah fruitcake.</p>          </main>          <footer class="footer">              goodbye          </footer>      </div>      <div>col2</div>  </body>

set html, body, .app { height: 100%; } (and remove other height settings elements). it's necessary set html other two.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -