I'm adding a toolbar to an application with multiple levels of flex elements.
<div class="toolbar">
<div class="button">Button1</div>
<div class="button">Button2</div>
<div class="button">Button3</div>
...
</div>
It's gonna take up the whole width of the parent and use horizontal scrolling on overflow.
.toolbar {
display: flex;
flex-direction: row;
overflow: scroll;
width: 100%;
}
This works swimmingly in an empty document. However, because the application itself uses display: flex
, toolbar's width: 100%
becomes the width of the whole document, not the width of its immediate parent. width: 100%
affects the outside flex layout! But having a fixed width, e.g. width: 300px
works perfectly fine.
A demo: https://jsfiddle.net/6s23o7Lf/
Basically, I'm trying to get this:
Is there a way to say that a flex item should take up all of the parent's width (all of its space along the secondary axis) without affecting its layout? Like align-items: stretch
, but also cut off contents on overflow.
I tried making toolbar
not a flex element (using display: block
on it and display: inline-block
on the buttons, with white-space: nowrap
and all that jazz), but the width still comes from up the DOM tree.
For context, my end goal is similar to what you see at the bottom of an Excel document (left/right arrows are used for scrolling there):
[Edit] Note that this is quite different from this question, because it involves nested flex elements with don't have fixed sizes.