0

I have a flex column layout with a top and bottom part with content in the middle. The whole page is set to 100vh min-height. I use flex: 1 on the content to fill the space. Some pages have images in the content, which might be too large, so they increase the height of the page. The problem is I want other content (if there is any) to enlarge the website, but I want the images to only fill the space without increasing the height. Is there a way to do this without setting a specific height for the images?

Sample code on CodeSandbox and

html,
body {
  height: 100%;
  margin: 0;
}

p {
  margin: 0;
}

.container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: magenta;
}

.flex-1 {
  flex: 1;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>image flex div</title>
</head>

<body>
  <div class="container">
    <p>top text</p>
    <div class="flex-1">
      <img src="https://placekitten.com/500/2000" />
    </div>
    <p>bottom text</p>
  </div>
</body>

</html>

In this example, I want the kitten to fill the space as the page were 100vh.

Kameron
  • 7,250
  • 3
  • 6
  • 22
bkiac
  • 301
  • 1
  • 6
  • I don't believe it's a duplicate. I want it to grow but only until 100vh. With `flex-start` it will never grow, even if the content is smaller. – bkiac Mar 24 '22 at 14:28

0 Answers0