A great way to handle this using only CSS is by utilizing both max-height:450px;
and min-height:100%
In this scenario, the percentage refers to the height of the grid row rather than the grid container itself. The height will be determined by the tallest element in that specific row.
/* Not necessary for this solution */
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body * {
padding: 10px;
border: 1px solid;
}
/* Not necessary for this solution */
/* The solution */
[grid] {
display: grid;
grid-template-columns: 7fr 10fr 15fr;
border-top: 1px solid black;
border-right: 1px solid black;
width: 400px;
margin: 0 auto;
}
[details] {
max-height: 450px;
min-height: 100%;
overflow: auto;
}
<div grid>
<div flag>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim </div>
<div content>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim </div>
<div details> some text</div>
<div flag>
Lorem ipsum dolor sit amet, consectetur epteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div content>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
</div>
<div details>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div flag>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in
</div>
<div content>
Lorem ipsum dolor sit
</div>
<div details>
I'm as tall as my tallest sibling.
</div>
</div>
As outlined in the specifications, there are specific violations and how they affect computed values.
Scenario 1: Details exceeds 450px;
The Issue: height > max-height
.
In this case, the calculated height will adhere to our defined max-height:450px
The min-height:100%
will not impact the outcome since the details element dictates the height.
Scenario 2: Details falls short of 450px;
The Issue: height < min-height
.
If this occurs, the resulting height will match min-height:100%
(equivalent to the tallest sibling's height). Interestingly, the max-height
parameter is disregarded entirely.
This logic holds true for other similar cases as well.