Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a bug in Chrome with justify-content: space-between and min-height?

Here is code I working on:

.container {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 150px;
  background-color: #cbcbcb;
}
<div class="container">
  <div>should be on the TOP</div>
  <div>should be on the BOTTOM</div>
</div>

And I am getting predictable result in Firefox:

enter image description here

But in Chrome I am getting next result:

enter image description here

Why I am getting this space under the bottom element?

It could be fixed by changing css min-height to height, but in my context it's important to have min-height value here.

Try it in jsFiddle

P.S. This behavior is reproduced only in Chrome and Canary, and seems only on Windows.

My env: Chrome Version 56.0.2924.87 (64-bit) and Win 10

like image 990
ilyabasiuk Avatar asked Feb 10 '17 14:02

ilyabasiuk


2 Answers

It certainly looks like a bug.

In any case, you can work around it with an auto margin:

.container {
  display: flex;
  flex-direction: column;
  min-height: 150px;
  background-color: #cbcbcb;
}
.container > div:last-child {
  margin-top: auto;
}
<div class="container">
  <div>should be on the TOP</div>
  <div>should be on the BOTTOM</div>
</div>

Flex auto margins are part of the spec and can be used to align flex items.

Full explanation here: In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?

like image 59
Michael Benjamin Avatar answered Nov 16 '22 03:11

Michael Benjamin


I remember that I had similar problem a couple of moths ago. This is because the height is set to auto, try to set another value for height property and the problem will be solved.

.container {
    display: flex;
    flex-direction: column;
    justify-content: space-between;  
    height:0;
    min-height: 150px;
    background-color: #cbcbcb;
}
<div class="container">
   <div> should be on the TOP</div>
   <div> should be on the BOTTOM</div>
 </div>
like image 43
Paweł Avatar answered Nov 16 '22 04:11

Paweł