1

I have made a demo to demonstrate my problem

<style>
.main {
  display: grid;
  grid-template-rows: 1fr auto;
  background-color: red;
  width: 300px;
  height: 120px;
}
.top {
  height: 50px;
  background-color: blue;
}
.bottom {
  display: grid;
  grid-template-columns: minmax(100px, 30%) auto;
  column-gap: 10px;
  margin: 10px;
}
.left {
  background-color: green;
  max-height: 100%;
  overflow-y: scroll;
}
.right {
  background-color: yellow;
}
</style>

<div class="main">
  <div class="top">My content</div>
  <div class="bottom">
    <div class="left">Left hkjs ajsgf dh a sk si sk dils k lkao one sp shek siej</div>
    <div class="right">Right</div>
  </div>
</div>

The green div exceeds the height of its parent div. I want the green div to be within the red div and have a scroll bar whenever the content exceeds the height of the parent.

I don't know how clear I have explained my problem but please help me.

TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

3

Add min-height:0 to the parent element.

<style>
.main {
  display: grid;
  grid-template-rows: 1fr auto;
  background-color: red;
  width: 300px;
  height: 120px;
}
.top {
  height: 50px;
  background-color: blue;
}
.bottom {
  display: grid;
  grid-template-columns: minmax(100px, 30%) auto;
  column-gap: 10px;
  margin: 10px;
  min-height:0;
}
.left {
  background-color: green;
  max-height: 100%;
  overflow-y: scroll;
}
.right {
  background-color: yellow;
}
</style>

<div class="main">
  <div class="top">My content</div>
  <div class="bottom">
    <div class="left">Left hkjs ajsgf dh a sk si sk dils k lkao one sp shek siej</div>
    <div class="right">Right</div>
  </div>
</div>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161