(after this question and its useful answer)
I am trying to create a container with a header and footer, as well as an area of ββmain content that can increase / decrease as needed. No sizes are known in advance. All of this should be allowed to grow vertically until the container reaches the set limit using max-height .
Ideally, the height of the header and footer never changes; An article grows only as much as it should display its contents, but is limited by the size of its container.
Can this be done only with CSS?
Screenshot

Demo
- Work with a fixed container size: Fiddle
- same as above interactive: fiddle
- broken version using
max-height instead of height : Fiddle
HTML
<div> <header>header 1<br>header 2<br>header 3</header> <article>content 1<br>content 2<br>content 3 ...</article> <footer>footer 1<br>footer 2<br>footer 3</footer> </div>
CSS
div { display: flex; flex-flow: column; max-height: 300px; } article { flex: 2; overflow: auto; background: gold; }
I tried various values ββin the flex: property flex: including 0%, 100%, or main size as the base of flex, but could not get the result I'm looking for.
html css layout flexbox
Zilk Aug 03 '14 at 2:39 a.m. 2014-08-03 14:39
source share