Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

html - Css: set a div element 100% of its parent when its child is less then 100% height

I have a flex div that contains 2 elements. I want the 2 elements to be the parent height when their content should be auto height, but I always get the inner content height.

my code:

<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<style>
    html, body {
        height: 100%;
        margin: 0px;
    }
  .parent {
    background: gray;
    display:flex;
    align-items: center;
  }
  .child {
    height: 100%;
    background: blue;
    border: 1px solid white;
  }
</style>
</head>
<body>
  <div class="parent">
    <div class="child">
      <div>
        <div>abc</div>
        <div>abc</div>
    </div>
    </div>
     <div class="child">
      <div>abc</div>
    </div>
  </div>
</body>
</html>
question from:https://stackoverflow.com/questions/65679908/css-set-a-div-element-100-of-its-parent-when-its-child-is-less-then-100-heigh

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Instead of height: 100%, try align-self: stretch on the child class.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...