Home > OS >  How to set auto height for flex element?
How to set auto height for flex element?

Time:10-24

Here are two flex divs:

<div style="display:flex">
   <div >Content</div>
   <div></div>
</div>

How to increase the height if first block if content is not fit inside?

I tried:

.content {
  flex: 1;
  height: 100%;
}

CodePudding user response:

The problem will be solved using 100vh instead of 100%.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .content {
        flex: 1;
        background-color: blue;
        height: 100vh; // modified
    }
</style>
<body>
    <div style="display:flex">
        <div >Content</div>
        <div>TEST</div>
    </div>
</body>
</html>

CodePudding user response:

.content {
  height: max-content;
}

In my opinion this problem is solved by max-content.
Here is height: max-content.
Give me your opinion. 
Thank you.
<div style="display:flex">
   <div >Content</div>
   <div></div>
</div>

  • Related