min-height 100vh creates vertical scrollbar even though content is smaller than viewport

George Katsanos picture George Katsanos · Feb 28, 2017 · Viewed 40.3k times · Source

I'm applying min-height: 100vh; to a flexbox container and I get a vertical scrollbar when I use justify-content: space-around;

I don't want to force the height, but I don't understand why the scrollbar is there since the contents have smaller dimensions than the viewport.

Answer

Jazcash picture Jazcash · Feb 28, 2017

Adding flex-grow seems to do the trick:

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wrapper {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  justify-content: space-around;
}

https://jsfiddle.net/uxgaaccr/2/

Not sure why, but height: 100% on .wrapper doesn't seem to suffice, it needs flex-grow instead. I think there was some extra white-space coming from justify-content: space-around that was adding to the height. Not confident in my reasoning, but it seems to work...