I am trying to create a two-column layout that adjusts to the browser window width automatically. One of the columns contains a dynamic content that can be short, but can be long, too. The other column always has text that is always the same:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.container {
display: flex;
}
.left {
flex: 1;
background-color: cornflowerblue;
overflow-y: auto;
}
.right {
background-color: aquamarine;
flex: 1;
}
</style>
</head>
<body>
<div class="container">
<div class="left">
Potentially<br>long<br>content<br>that<br>might<br>need<br>a<br>scrollbar<br>1<br>2<br>3<br>4<br>5 Fusce pulvinar sit amet massa in vulputate. Cras eros ligula, condimentum non lacus nec, maximus lacinia orci.
</div>
<div class="right">
<p>The text that<br>does not change<br>and must always<br>be displayed<br>in its entirety<br>without scrollbar.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam euismod nibh ex, sit amet vulputate ipsum luctus non.</p>
</div>
</div>
</body>
</html>
https://jsfiddle.net/w3Lhjza1/1/
I want to make a scrollbar to appear in the .left
div whenever the height of its content is greater than the height of the content of the .right
div. When the amount of text in the .left
div is small, .right
text should still be displayed without scroll bars (this is covered by flex already, but using flex is not a requirement):
The obvious "solution" is to specify the max-height of the .left
element to something "reasonable", but I need it to adjust automatically for different screen widths.
Is it possible to do (without javascript) or I am doomed to specifying fixed height for blocks?