I am making a vertical menu page using display: flex; . I want the width of the menu to be around several buttons, without having to use a fixed width.
However, I also want a status message to appear in the menu window, which may have a rather long text. I would like this status div to have the width of the menu, without forcing the menu container to increase its width. Instead, the status-div should increase its height and wrap the text.
Explaining this with words is quite complicated, so I suggest you check out this script: http://jsfiddle.net/bXL3q/
Note the difference when setting .statusmessage to display: none; .
Any ideas, or is this what I'm trying to make impossible? Could it be?
What I tried:
width: 100% fails, obviously it just assumes the width of the parent elementwidth: -webkit-min-content kind of works, but this makes the element too narrow.flex-basis and flex-grow affect the height of the element and do not affect the widthposition: absolute will solve the problems with width, but now I have no way to determine the height of the status-div .. (in order to force the scroll bar in windows with small height - instead, it will simply flow over the button elements)
body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; display: flex; flex-flow: row nowrap; align-items: stretch; } .page { flex-grow: 1; background-color: yellow; } .menu { background-color: red; height: 100%; display: flex; flex-flow: column nowrap; } .somechildren { white-space: nowrap; background-color: green; border: 1px solid black; } .menu>* { flex-shrink: 0; } .separate { flex-grow: 1; } .statusmessage { background-color: magenta; align-self: flex-end; }
<div class=menu> <div class=somechildren>I'd like the menu's</div> <div class=somechildren>width to fit nicely</div> <div class=somechildren>around these children</div> <div class=separate></div> <div class=statusmessage> While forcing this status message to wrap and grow its height, without affecting the width of the container. </div> </div> <div class=page> The page </div>
css flexbox
Thoronwen
source share