0

I would like to know why clm1 with height: 100%; does not resize the div when display flex is being used.

How to fix this problem, I need the div resize as clm2 content? Why does not work my version?

I need the orange div to matchs the size of the blue div.

#container {
  background-color: red;
  width: 500px;
  height: 400px;
}

#flex {
  background-color: yellow;
  display: flex;
  flex-direction: row;
}

#clm1 {
  background-color: orange;
  width: 20%;
  height: 100%;
}

#clm2 {
  background-color: blue;
  width: 80%;
}
<div id="container">
  <div id="flex">
    <div id="clm1">
      1
    </div>
    <div id="clm2">

      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
      survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum
    </div>
  </div>
</div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Radex
  • 7,815
  • 23
  • 54
  • 86

3 Answers3

2

Because the parent height is not set. Add height:100% (or any height) to parent and it will work.

#container {
  background-color: red;
  width: 500px;
  height: 400px;
}

#flex {
  background-color: yellow;
  display: flex;
  flex-direction: row;
  height: 100%;
}

#clm1 {
  background-color: orange;
  width: 20%;
  height: 100%;
}

#clm2 {
  background-color: blue;
  width: 80%;
}
<div id="container">
  <div id="flex">
    <div id="clm1">
      1
    </div>
    <div id="clm2">

      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
      survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum
    </div>
  </div>
</div>

Or simply remove the height:100% from child as with the default behavior of flex it will be stretched to parent height. This is due to the property align-items set to stretch by default.

#container {
  background-color: red;
  width: 500px;
  height: 400px;
}

#flex {
  background-color: yellow;
  display: flex;
  flex-direction: row;
}

#clm1 {
  background-color: orange;
  width: 20%;
}

#clm2 {
  background-color: blue;
  width: 80%;
}
<div id="container">
  <div id="flex">
    <div id="clm1">
      1
    </div>
    <div id="clm2">

      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
      survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum
    </div>
  </div>
</div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
-1

'cause your #clm2 is 100% height of... the #flex, which is auto height, not the #container that has a defined 400px.

So set the #flex to height 100% (or 400px) and it will work

#container {
  background-color: red;
  width: 500px;
  height: 400px;
}

#flex {
  background-color: yellow;
  display: flex;
  flex-direction: row;
  height:100%;
}

#clm1 {
  background-color: orange;
  width: 20%;
  height: 100%;
}

#clm2 {
  background-color: blue;
  width: 80%;
}
<div id="container">
  <div id="flex">
    <div id="clm1">
      1
    </div>
    <div id="clm2">

      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
      survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum
    </div>
  </div>
</div>
Facundo Corradini
  • 3,825
  • 9
  • 24
-2

You have clm1 and clm2 in the div flex and you set c1lm1 to height 100% clm2 to height 80%. Since height property fills in the parent, the total height would be 180% which is not possible. Try making the clm1 and clm2 height percentages add up to 100%

Tim Lee
  • 358
  • 2
  • 8