2

In this example below I cannot find a way using the css flex model to make div B fill the height of div A. When flex-direction is column the child div still collapses even when no heights are specified.

.A {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  background: #00b;
  -ms-flex-direction: column;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  flex-direction: column;
}

.B {
  background: #b00;
  -ms-flex: 1 1 0%;
  -webkit-box-flex: 1;
  flex: 1 1 0%;
}
<div class="A">
  <div class="B">
    I WISH I WAS AS BIG AS MY DAD
  </div>
</div>
DreamTeK
  • 32,537
  • 27
  • 112
  • 171

1 Answers1

2

Revised answer based on a question edit.


This is one of IE's many flex bugs, where it won't recognize its parents height under some circumstances.

In this case, when using flex container with column direction, if you use a unitless value for flex-basis you'll get the same result cross browsers.

.A {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  background: #00b;
  -ms-flex-direction: column;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  flex-direction: column;
}

.B {
  background: #b00;
  -ms-flex: 1 1 0;
  -webkit-box-flex: 1;
  flex: 1 1 0;
}
<div class="A">
  <div class="B">
    I WISH I WAS AS BIG AS MY DAD
  </div>
</div>

If the sole purpose is to make the items fit the height of its parent, I recommend to use the longhand flex-grow: 1 instead.

Fiddle demo

Stack snippet

.A {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  background: #00b;
  -ms-flex-direction: column;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  flex-direction: column;
}

.B {
  background: #f66;
  -ms-flex-grow: 1;
  -webkit-box-flex: 1;
  flex-grow: 1;
}
<div class="A">
  <div class="B">
    I AM AS BIG AS MY DAD
  </div>
</div>

Here is also a fiddle sample, showing both a row and column version.

Asons
  • 84,923
  • 12
  • 110
  • 165
  • thanks for this however it doesn't solve the problem if no heights are set as in my second example. Any ideas? – DreamTeK Jul 26 '17 at 12:26
  • @Obsidian Updated my answer. – Asons Jul 26 '17 at 13:14
  • Thanks for this looks ok however I already added units into all my flex attributes because Chrome doesn't respect the values otherwise :) https://stackoverflow.com/questions/37386244/what-does-flex1-mean#answer-42630660 – DreamTeK Jul 26 '17 at 14:24
  • @Obsidian For the column direction it works in Chrome as well, when you use shorthand `flex` and unitless _flex-basis_ value, still, I recommend you use the longhand `flex-grow` instead. What is the reason you want to set the `flex-basis` to 0%? – Asons Jul 26 '17 at 14:31
  • Mainly for cross browsers issues. Shorthand `Flex:1` causes all kinds of issues. When I use expanded `Flex:1 1 0` there are further issues with both IE and Chrome unless units are specified. My main problem is people won't stop using IE! – DreamTeK Jul 26 '17 at 14:34
  • @Obsidian Then use my last sample code, which use the longhand `flex-grow`. Works cross all browsers flawless, for both row and column direction – Asons Jul 26 '17 at 14:35
  • 1
    Thanks for all your help. You have provided enough information for me to create a usable solution so thanks for your efforts where others offer none. – DreamTeK Jul 26 '17 at 14:58
  • 1
    @Obsidian You're welcome. Btw, I also added the previous fiddle with both row and column version into my answer – Asons Jul 26 '17 at 14:58