Since you're using a percentage height on the flex container...
ol { min-height: 100%; }
... you need to also define a height for the parent and root elements.
HTML (no changes)
<ol>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</ol>
CSS
html, body { height: 90%; } /* NEW; needed for child percentage heights to work;
set at 90% just for demo purposes */
ol {
min-height: 100%;
display: flex;
flex-direction: column;
}
ol li {
flex: 1;
}
DEMO: http://jsfiddle.net/kzL4305k/1/
I think the trouble has to do with having to set height: 100%
to every
single parent element all the way to html. Can that be right?
Yes, that is correct. If you use percentage heights you need to specify the height for every single parent all the way up to the root element (html
). I've explained the reason for this here:
My list is deeply nested and setting all those heights breaks the
layout. I would prefer to work only with fluid heights.
You don't need to set the height for parent elements if you don't use percentages. Try using min-height
in pixels on flex containers, then letting flex-grow: 1
deal with the height issue for flex items.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…