I use a third-party component that occupies all the available space, i.e. width=100% and height=100%. I don't have control over it.
I'm trying to fit it in the following layout, but its height=100% doesn't work (I expect the third-party component to occupy all the green space).
Why? How would you fix that?
.container {
display: flex;
flex-direction: column;
width: 200px;
height: 100px;
}
.header {
display: flex;
background-color: rgba(255, 0, 0, 0.5);
}
.content {
flex-grow: 1;
background-color: rgba(0, 255, 0, 0.5);
}
.third-party-component {
height: 100%;
width: 100%;
background-color: rgba(0, 0, 255, 0.5);
}
<div class="container">
<div class="header">Header</div>
<div class="content">
<div class="third-party-component">
Third party component
</div>
</div>
</div>
In general, for an element using percent on height to pick up its parent's height, the parent need a height other than auto or being positioned absolute, or the height will be computed as auto.
Based on those 2 options, and as you mentioned in a comment, your own header is dynamic in height, you are left with absolute positioning.
The problem with adding absolute to the content, it will be taken out of flow and stop behaving as a normal flowed flex item, the good news, one can add a wrapper set to absolute.
Stack snippet
.container {
display: flex;
flex-direction: column;
width: 200px;
height: 100px;
}
.header {
display: flex;
background-color: rgba(255, 0, 0, 0.5);
}
.content {
position: relative; /* added */
flex-grow: 1;
background-color: rgba(0, 255, 0, 0.5);
}
.wrapper {
position: absolute; /* added */
left: 0; /* added */
top: 0; /* added */
right: 0; /* added */
bottom: 0; /* added */
}
.third-party-component {
height: 100%;
width: 100%;
background-color: rgba(0, 0, 255, 0.5);
}
<div class="container">
<div class="header">Header</div>
<div class="content">
<div class="wrapper">
<div class="third-party-component">
Third party component
</div>
</div>
</div>
</div>
Another option could be to update the Flexbox properties, to give the content a height, using flex: 1 1 100% and give header flex-shrink: 0; so it doesn't shrink (as content got 100%).
This might not work on Safari though, as I know it have had issues when the height property is not set, though can't test that now as I don't have access to Safari.
.container {
display: flex;
flex-direction: column;
width: 200px;
height: 100px;
}
.header {
display: flex;
flex-shrink: 0;
background-color: rgba(255, 0, 0, 0.5);
}
.content {
flex: 1 1 100%;
background-color: rgba(0, 255, 0, 0.5);
}
.third-party-component {
height: 100%;
width: 100%;
background-color: rgba(0, 0, 255, 0.5);
}
<div class="container">
<div class="header">Header</div>
<div class="content">
<div class="third-party-component">
Third party component
</div>
</div>
</div>
Because .content haven't height (height = 0px) and .third-party-component have 100% of 0px. You can add propety height : calc (100% - <height of .header>) into .content
.container {
display: flex;
flex-direction: column;
width: 200px;
height: 100px;
}
.header {
display: flex;
background-color: rgba(255, 0, 0, 0.5);
}
.content {
height: calc(100% - 18px);
flex-grow: 1;
background-color: rgba(0, 255, 0, 0.5);
}
.third-party-component {
height: 100%;
width: 100%;
background-color: rgba(0, 0, 255, 0.5);
}
<div class="container">
<div class="header">Header</div>
<div class="content">
<div class="third-party-component">
Third party component
</div>
</div>
</div>
You can simply use another flex container in the .content element:
.container {
display: flex;
flex-direction: column;
width: 200px;
height: 100px;
}
.header {
display: flex;
background-color: rgba(255, 0, 0, 0.5);
}
.content {
flex-grow: 1;
display: flex;
flex-direction: column;
background-color: rgba(0, 255, 0, 0.5);
}
.third-party-component {
flex-grow: 1;
height: 100%;
width: 100%;
background-color: rgba(0, 0, 255, 0.5);
}
<div class="container">
<div class="header">Header</div>
<div class="content">
<div class="third-party-component">
Third party component
</div>
</div>
</div>
Related
I am working on a banner and want the banner to have background taking the width of the viewport but content of this banner should take the width of the content space. The content of the banner is in a div who should be at the same position on left than grandparent.
Any idea on how to do it ?
.grandparent{
background-color: rgb(0, 255, 0);
width: 90vw;
height: 30vh;
margin: 30px;
}
.parent{
background-color: rgb(0, 0, 255);
width: 100vw;
height: 15vh;
position: relative;
left: calc(-50vw + 50%);
display: flex;
align-items: center;
}
.child{
background-color: rgb(255, 0, 0);
width: 20vw;
display: flex;
justify-content: space-between;
}
<div class="grandparent">
<div class="parent">
<div class="child">
<button>1</button>
<button>2</button>
<button>3</button>
</div>
</div>
</div>
https://jsfiddle.net/khdz7ugq/
Schema of what I have in mind
I am building a modal, and want it to be centred in my page and grow organically but only until it reaches a certain width and height.
I center this modal (.modal) with flexbox, and it works fine.
Inside this modal I have another flexbox (.modal-content), with a body (.modal-content__body) and a footer (.modal-content__footer) element. I want the body to grow until the whole .modal reaches my max-height, at which point I want the modal-content__body to start scrolling vertically.
The HTML hierarchy is:
.modal-container // Full screen
.modal // Centred box with max-width and max-height
.modal-content // The content of the modal
.modal-content__body // Potentially growing content
.modal-content__footer
I can't get the .modal-content not to overflow. It simply ignores the parent's (.modal) height and grows to provide space for the content.
If I remove the additional div of the .modal-content and simply merge the .modal with the .modal-content it works as expected, but because I'm using a framework (Angular) I can't change the way the HTML elements are encapsulated.
(NOTE: If I set max-height: -webkit-fill-available; on the .modal-content it works, but this property is not well supported so I can't use it)
Here is a code demonstrating the issue:
/* Centers the child */
.modal-container {
display: flex;
align-items: center;
justify-content: center;
}
/* The box in the middle, that should grow
organically, but be restricted as well */
.modal,
.modal-content--merged-with-modal {
width: 30rem;
max-width: calc(50vw - 3rem);
max-height: calc(100vh - 3rem);
/* Irrelevant styling */
background: rgba(255, 255, 255, 0.6);
border-radius: 3px;
line-height: 1.5rem;
}
.modal-content {
display: flex;
flex-direction: column;
min-height: 0;
}
.modal-content__body {
flex: 1;
min-height: 0;
overflow-y: scroll;
/* Irrelevant styling */
padding: 0.75rem;
background: rgba(0, 0, 255, 0.1);
}
.modal-content__footer {
/* Irrelevant styling */
border-top: 1px solid silver;
background: rgba(0, 255, 0, 0.1);
padding: 0.75rem;
}
/* Irrelevant styling to present the problem */
html {
font-family: arial, sans-serif;
font-size: 16px;
}
main {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
}
section {
flex: 1;
background: rgba(255, 0, 0, 0.1);
}
<main>
<section class="modal-container">
<div class="modal-content modal-content--merged-with-modal">
<div class="modal-content__body">
<code>BODY // </code> srollable<br>
<br> Container resizes as expected when<br> the container height is reduced.<br>
<br> In this case, the modal is the same<br> element, as the flexbox handling<br> the body and the footer.<br> .
<br> .
<br> .
<br> .
<br> .
<br> .
<br>
</div>
<div class="modal-content__footer">
<code>FOOTER // </code> Works
</div>
</div>
</section>
<section class="modal-container">
<div class="modal">
<div class="modal-content">
<div class="modal-content__body">
<code>BODY // </code>simply grows<br>
<br> Container overflows when<br> the container height is reduced.<br>
<br> In this case, the modal <strong>contains</strong><br> the flexbox, that handles the<br> body and the footer.<br> .
<br> .
<br> .
<br> .
<br> .
<br> .
<br>
</div>
<div class="modal-content__footer">
<code>FOOTER // </code> Doesn't work
</div>
</div>
</div>
</section>
</main>
A simple fix is to make the .modal a flex container with column direction.
/* Centers the child */
.modal-container {
display: flex;
align-items: center;
justify-content: center;
}
/* The box in the middle, that should grow
organically, but be restricted as well */
.modal, .modal-content--merged-with-modal {
width: 30rem;
max-width: calc(50vw - 3rem);
max-height: calc(100vh - 3rem);
/* Irrelevant styling */
background: rgba(255, 255, 255, 0.6);
border-radius: 3px;
line-height: 1.5rem;
}
.modal-content {
display: flex;
flex-direction: column;
min-height: 0;
}
.modal-content__body {
flex: 1;
min-height: 0;
overflow-y: scroll;
/* Irrelevant styling */
padding: 0.75rem;
background: rgba(0, 0, 255, 0.1);
}
.modal-content__footer {
/* Irrelevant styling */
border-top: 1px solid silver;
background: rgba(0, 255, 0, 0.1);
padding: 0.75rem;
}
.modal {
display:flex;
flex-direction:column;
}
/* Irrelevant styling to present the problem */
html {
font-family: arial, sans-serif;
font-size: 16px;
}
main {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
}
section {
flex: 1;
background: rgba(255, 0, 0, 0.1);
}
<main>
<section class="modal-container">
<div class="modal-content modal-content--merged-with-modal">
<div class="modal-content__body">
<code>BODY // </code> srollable<br>
<br>
Container resizes as expected when<br>
the container height is reduced.<br>
<br>
In this case, the modal is the same<br>
element, as the flexbox handling<br>
the body and the footer.<br>
.<br>
.<br>
.<br>
.<br>
.<br>
.<br>
</div>
<div class="modal-content__footer">
<code>FOOTER // </code> Works
</div>
</div>
</section>
<section class="modal-container">
<div class="modal">
<div class="modal-content">
<div class="modal-content__body">
<code>BODY // </code>simply grows<br>
<br>
Container overflows when<br>
the container height is reduced.<br>
<br>
In this case, the modal <strong>contains</strong><br>
the flexbox, that handles the<br>
body and the footer.<br>
.<br>
.<br>
.<br>
.<br>
.<br>
.<br>
</div>
<div class="modal-content__footer">
<code>FOOTER // </code> Doesn't work
</div>
</div>
</div>
</section>
</main>
Why?
Initially the .modal was a block element with a max-height set and the default overflow behavior (when there is an overflow) is visible and you are facing an overflow issue.
By making the .modal a flex container, you introduce the shrink effect as by default the flex item will have flex-shrink:1 so its height won't go beyond the height of the flex container (it will shrink to fit) and you will have the need result.
You may set flex-shrink:0 to .modal-content and you will see the same overflow issue as if there is no display:flex.
In order for the overflow property to work, it needs a fixed length limitation.
From MDN:
In order for overflow to have an effect, the block-level container must have either a set height (height or max-height) or white-space set to nowrap.
In your code, there is no height limitation on .modal-content__body (where the overflow is set):
.modal-content__body {
flex: 1;
min-height: 0;
overflow-y: scroll;
}
Nor is there a height limitation on the parent:
.modal-content {
display: flex;
flex-direction: column;
min-height: 0;
}
flex-basis: 0 – the relevant component of flex: 1 in .modal-content__body – isn't enough to trigger the overflow condition. But look what happens if you switch to flex-basis: 100px
/* Centers the child */
.modal-container {
display: flex;
align-items: center;
justify-content: center;
}
/* The box in the middle, that should grow
organically, but be restricted as well */
.modal, .modal-content--merged-with-modal {
width: 30rem;
max-width: calc(50vw - 3rem);
max-height: calc(100vh - 3rem);
/* Irrelevant styling */
background: rgba(255, 255, 255, 0.6);
border-radius: 3px;
line-height: 1.5rem;
}
.modal-content {
display: flex;
flex-direction: column;
min-height: 0;
}
.modal-content__body {
flex: 1 0 100px; /* new for demo 1 */
min-height: 0;
overflow-y: scroll;
/* Irrelevant styling */
padding: 0.75rem;
background: rgba(0, 0, 255, 0.1);
}
.modal-content__footer {
/* Irrelevant styling */
border-top: 1px solid silver;
background: rgba(0, 255, 0, 0.1);
padding: 0.75rem;
}
/* Irrelevant styling to present the problem */
html {
font-family: arial, sans-serif;
font-size: 16px;
}
main {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
}
section {
flex: 1;
background: rgba(255, 0, 0, 0.1);
}
<main>
<section class="modal-container">
<div class="modal">
<div class="modal-content">
<div class="modal-content__body">
<code>BODY // </code>simply grows<br>
<br> Container overflows when<br> the container height is reduced.<br>
<br> In this case, the modal <strong>contains</strong><br> the flexbox, that handles the<br> body and the footer.<br> .
<br> .
<br> .
<br> .
<br> .
<br> .
<br>
</div>
<div class="modal-content__footer">
<code>FOOTER // </code> Doesn't work
</div>
</div>
</div>
</section>
</main>
The scrolling works. A height limitation made the difference.
Here's a potential solution:
Since the height of .modal (the parent) and modal-content (the child) are the same, move the dimensions from the parent to the child. This brings the height limitation close enough to the content items to trigger the overflow.
Instead of this:
.modal {
width: 30rem;
max-width: calc(50vw - 3rem);
max-height: calc(100vh - 3rem);
}
.modal-content {
display: flex;
flex-direction: column;
min-height: 0;
}
Try this:
.modal { }
.modal-content {
display: flex;
flex-direction: column;
min-height: 0;
width: 30em;
max-width: calc(50vw - 3rem);
max-height: calc(100vh - 3rem);
}
/* Centers the child */
.modal-container {
display: flex;
align-items: center;
justify-content: center;
}
/* The box in the middle, that should grow
organically, but be restricted as well */
.modal, .modal-content--merged-with-modal {
/* Irrelevant styling */
background: rgba(255, 255, 255, 0.6);
border-radius: 3px;
line-height: 1.5rem;
}
.modal-content {
display: flex;
flex-direction: column;
min-height: 0;
width: 30rem;
max-width: calc(50vw - 3rem);
max-height: calc(100vh - 3rem);
}
.modal-content__body {
flex: 1;
min-height: 0;
overflow-y: scroll;
/* Irrelevant styling */
padding: 0.75rem;
background: rgba(0, 0, 255, 0.1);
}
.modal-content__footer {
/* Irrelevant styling */
border-top: 1px solid silver;
background: rgba(0, 255, 0, 0.1);
padding: 0.75rem;
}
/* Irrelevant styling to present the problem */
html {
font-family: arial, sans-serif;
font-size: 16px;
}
main {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
}
section {
flex: 1;
background: rgba(255, 0, 0, 0.1);
}
<main>
<section class="modal-container">
<div class="modal">
<div class="modal-content">
<div class="modal-content__body">
<code>BODY // </code>simply grows<br>
<br>
Container overflows when<br>
the container height is reduced.<br>
<br>
In this case, the modal <strong>contains</strong><br>
the flexbox, that handles the<br>
body and the footer.<br>
.<br>
.<br>
.<br>
.<br>
.<br>
.<br>
</div>
<div class="modal-content__footer">
<code>FOOTER // </code> Doesn't work
</div>
</div>
</div>
</section>
</main>
I have a 3-column body with fixed width on the sides and the middle column filling the remaining width.
I need however to make all columns fill the entire height of the page.
I set the height of all parents to height: 100% and I don't want to use a workaround with huge margin or padding, as I'm using a scroll-bar.
#container {
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-between;
height: 100%;
}
.col-side {
width: 240px;
height: 100%;
}
#col1 {
border-right: 2px solid rgba(0, 0, 0, 0.12);
}
#col3 {
border-left: 2px solid rgba(0, 0, 0, 0.12);
}
<div id="container">
<div class="col-side" id="col1">
Left
</div>
<div class="col" id="col2">
Center
</div>
<div class="col-side" id="col3">
Right
</div>
</div>
Small demo can be found here:
https://jsfiddle.net/ysn3q6aL/#&togetherjs=H9pEenhcqQ
When you create a flex container (display: flex or display: inline-flex), it automatically applies flex-direction: row and align-items: stretch (among other initial settings).
These default settings line up flex items in a row and give them each the full height of the container. However, if you set a height on a flex item, it overrides align-items. So remove any heights you've set on the items.
This should work for you:
#container {
display: flex;
justify-content: space-between;
height: 100vh;
}
.col-side {
flex: 0 0 240px;
}
#col2 { flex: 1; }
#container > div + div {
border-left: 2px solid rgba(0, 0, 0, 0.12);
}
#col1 { background-color: lightgreen; }
#col2 { background-color: tomato; }
#col3 { background-color: aqua; }
body { margin: 0; }
<div id="container">
<div class="col-side" id="col1">Left</div>
<div class="col" id="col2">Center</div>
<div class="col-side" id="col3">Right</div>
</div>
.col-side{
width: 240px;
height: 100%;
flex: 1 1 0;
}
might help. I was asking the same some time before, the flex: 1 1 0 part helped.
the defaults are 0 1 auto. The first param is flex grow, so you want them all to grow to the same height.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/#article-header-id-13
Set the container height to 100vh.
That's all
#container{
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-between;
height:100vh;
}
.col-side{
width: 240px;
height: 100%;
}
#col1{
border-right: 2px solid rgba(0, 0, 0, 0.12);
}
#col3{
border-left: 2px solid rgba(0, 0, 0, 0.12);
}
I have recently started using the Grid layout in CSS and I am trying to make the elements in one of the grid areas fill the whole area. It works to set the width to 100% of the parent. But I have a really hard time getting the height of my div to be the same as the parent div. Here is some code to showcase my problem:
body {
width: 100vw;
height: 100vh
}
.grid {
width: 100%;
height: 100%;
display: grid;
grid-template-columns: [sidebar-col-start] 15% [sidebar-col-end content-col-start] auto [content-col-end];
grid-template-rows: [sidebar-row-start content-row-start] auto [sidebar-row-end footer-row-start] 10% [footer-row-end];
}
.area {
grid-column: content-col-start / content-col-end;
grid-row: content-row-start / footer-row-start;
background-color: rgba(255, 0, 0, 0.4);
align-items: stretch;
}
.footer {
grid-column: sidebar-col-start / content-col-end;
grid-row: footer-row-start / footer-row-end;
background-color: rgba(0, 255, 0, 0.4);
}
.sidebar {
grid-column: sidebar-col-start / sidebar-col-end;
grid-row: sidebar-row-start / sidebar-row-end;
background-color: rgba(0, 0, 0, 0.4);
}
.red {
background-color: red;
height: 100%;
}
<div class="grid">
<div class="sidebar">
</div>
<div class="area">
<div class="red">
</div>
</div>
</div>
Link to Codepen: https://codepen.io/Martin36/pen/ayyoxv
My question is: How do I make a div fill the whole parent (which is a grid area)? Or more specifically, how do I make the height of the children match the parent's height?
Set .red with a min-height of 100vh.
body {
margin: 0;
width: 100vw;
height: 100vh
}
.grid {
width: 100vw;
height: 100vh;
display: grid;
grid-template-columns: [sidebar-col-start] 15% [sidebar-col-end content-col-start] auto [content-col-end];
grid-template-rows: [sidebar-row-start content-row-start] auto [sidebar-row-end footer-row-start] 10% [footer-row-end];
}
.area {
grid-column: content-col-start / content-col-end;
grid-row: content-row-start / footer-row-start;
background-color: rgba(255, 0, 0, 0.4);
align-items: stretch;
}
.footer {
grid-column: sidebar-col-start / content-col-end;
grid-row: footer-row-start / footer-row-end;
background-color: rgba(0, 255, 0, 0.4);
}
.sidebar {
grid-column: sidebar-col-start / sidebar-col-end;
grid-row: sidebar-row-start / sidebar-row-end;
background-color: rgba(0, 0, 0, 0.4);
}
.red {
background-color: red;
height: 100vh;
}
<div class="grid">
<div class="sidebar">
</div>
<div class="area">
<div class="red">
</div>
</div>
</div>
I would like a column of divs, of any number, each with width 100% and height 100% of their parent div, so one is visible initially, and the others overflow the parent downwards. I've set the divs to have flex: 0 0 100%;, inside a parent div with display: flex and flex-direction: column to achieve this.
The parent div is itself of unknown height, so it is also a child of a display: flex and flex-direction: column, set to flex: 1 0 0 to take remaining space in its container.
In Firefox the output is as I would like it:
However, not in Chrome:
How can I achieve the Firefox style in Chrome, without Javascript?
You can see this in action at http://plnkr.co/edit/WnAcmwAPnFaAhqqtwhLL?p=preview, as well as the corresponding version with flex-direction: row, which works consistently in both Firefox and Chrome.
For reference, the full CSS
.wrapper {
display: flex;
flex-direction: column;
height: 150px;
width: 200px;
border: 4px solid green;
margin-bottom: 20px;
}
.column-parent {
flex: 1 0 0;
display: flex;
flex-direction: column;
border: 2px solid blue;
}
.column-child {
flex: 0 0 100%;
border: 2px solid red;
}
and HTML
<div class="wrapper">
<p>Some content of unknown size</p>
<div class="column-parent">
<div class="column-child">
Should be inside green
</div>
<div class="column-child">
Should be outside green
</div>
</div>
</div>
This seems to be a bug with Chrome. Similar to the ones reported here (issue 428049) and perhaps related to (issue 346275).
This says:
- Browsers are supposed to resolve percentages on the flex item's child, *if* its flex-basis is definite.
- Gecko is *always* resolving percentages regardless of the flex-basis.
- Chrome is *never* resolving percentages, regardless of the flex-basis.
Summarily, Chrome is not resolving percent heights on flex-item's child (even if the child itself is a flex-item), while all other browsers do.
This can be demonstrated in the below snippet: (Fiddle here)
* { box-sizing: border-box; margin: 0; padding: 0; }
div.wrap {
height: 120px; width: 240px; margin: 0px 12px;
border: 1px solid blue; float: left;
display: flex; flex-direction: column;
}
div.parent {
flex: 0 0 100%;
border: 1px solid green;
display: flex; flex-direction: column;
}
div.item {
flex: 0 0 100%;
border: 1px solid red;
}
<div class="wrap">
<div class="item">a</div>
<div class="item">b</div>
<div class="item">c</div>
</div>
<div class="wrap">
<div class="parent">
<div class="item">a</div>
<div class="item">b</div>
<div class="item">c</div>
</div>
</div>
The second div should show the same behaviour as the first one. Other browsers (IE11, Edge, FF39) show it correctly. Chrome fails here and does not resolve div.item correctly. It needs a fixed height on its parent, without which it uses min-content as its height and thus does not overflow.
Whereas, in the first div, the div.items are correctly resolved and overflow accordingly. This is because there is a fixed height on the parent (i.e. div.wrap)
Possible Solution:
As a workaround, if you are sure to have only two elements (p and div) inside your wrapper, then you could give them a 50% height. You have to provide a height:50% to your .column-parent. Chrome needs a fixed height on parent as demonstrated above.
Then everything will work as you need to.
Demo Fiddle: http://jsfiddle.net/abhitalks/kqncm65n/
Relevant CSS:
.wrapper > p { flex: 0 0 50%; } /* this can be on flex-basis */
.column-parent {
flex: 1 0 auto; height: 50%; /* but, this needs to be fixed height */
display: flex; flex-direction: column;
border: 2px solid blue;
}
.column-child {
flex: 0 0 100%; /* this flex-basis is then enough */
border: 2px solid red;
}
PS: There also seem to be differences in the way jsfiddle and plnkr render. I don't know why, but sometimes I get different results!
As stated in Abhitalks response, there is a bug (or a different interpretation of the standard) in the way Chrome handles the height attribute here.
I have found a hack that is working both in Chrome FF and IE
The only issue is that you ned to have as many rules as posible children there are.
The trick is to set the flex-direction to row, set the flex-basis (that is now the width) to 100%, and then translate the elements
.container {
border: solid 2px blue;
height: 200px;
width: 200px;
display: flex;
flex-direction: column;
position: relative;
}
.filler {
border: solid 1px black;
flex: 0 0 80px;
background-color: lightgreen;
transition: flex 1s;
}
.container:hover .filler {
flex: 0 0 40px;
}
.test {
border: solid 1px red;
flex: 1 0 25px;
display: flex;
flex-direction: row;
position: relative;
}
.child {
background-color: rgba(200, 0, 0, 0.26);
flex: 0 0 100%;
}
.child:nth-child(2) {
background-color: rgba(255, 255, 0, 0.48);
transform: translateX(-100%) translateY(100%);
}
.child:nth-child(3) {
background-color: rgba(173, 216, 230, 0.28);
transform: translateX(-200%) translateY(200%);
}
<div class="container">
<div class="filler"></div>
<div class="filler"></div>
<div class="test">
<div class="child">1</div>
<div class="child">2</div>
<div class="child">3</div>
</div>
</div>
If there could be another child, you would need a nth-child(4) rule, and so on
I have added an hover effect to check how the size adapts
My previous answer is a hack that exploits a particular setup of the layout wanted.
An alternate way, more general, of getting around this Chrome bug is to use an intermediate element in the layout, and set this element size using top: 0px and bottom: 0px. (instead of height: 100%) There is still a bug in the way Chrome handles the calculus, that needs a fake animation to make it adjust properly
.container {
border: solid 2px blue;
height: 200px;
width: 200px;
display: flex;
flex-direction: column;
position: relative;
}
.filler {
border: solid 1px black;
flex: 0 0 94px;
background-color: lightgreen;
transition: 1s;
}
.container:hover .filler {
flex: 0 0 50px;
}
.test {
border: solid 1px red;
flex: 1 0 25px;
display: flex;
flex-direction: row;
position: relative;
}
#-webkit-keyframes adjust2 {
0% {flex-basis: 100%;}
100% {flex-basis: 100.1%;}
}
.child {
background-color: rgba(200, 0, 0, 0.26);
width: 100%;
height: 100%;
flex: 1 0 100%;
-webkit-animation: adjust2 1s infinite; /* only needed for webkit bug */
}
.intermediate {
width: 100%;
position: absolute;
top: 0px;
bottom: 0px;
display: flex;
flex-direction: column;
}
.child:nth-child(n+2) {
background-color: rgba(255, 255, 0, 0.48);
}
.child:nth-child(n+3) {
background-color: rgba(173, 216, 230, 0.28);
}
<div class="container">
<div class="filler"></div>
<div class="test">
<div class="intermediate">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
</div>
</div>
What about adding 100% to the container:
.column-parent {
flex: 1 0 100%;
}
And flex-grow to 1 in the contained element without adjusting the flex basis:
.column-child {
flex: 1 0 0;
}
Here's how it would look: http://plnkr.co/edit/H25NQxLtbi65oaltNVax?p=preview