I would like to have a two columns layout where the first column can grown as high as necessary and the second column will be 100% the height of the first one, but if the first one is not higher enough to show all the content of the second column, then this one should show scrolling bar and be limited to the height of the first column.
I tried this but this only works if I set a fix height for the main container instead of a percentage.
HTML:
<div class="container">
<div class="column1">Phasellus viverra ac diam nec viverra. Phasellus viverra ac diam nec viverra.</div>
<div class="column2">Phasellus viverra ac diam nec viverra. Aliquam gravida ante at est laoreet pulvinar. Vestibulum scelerisque ut quam nec semper. Duis porta aliquam velit in porttitor.</div>
</div>
CSS:
.container {
height: 150px;
}
.column1, .column2 {
float: left;
width: 50%;
}
.column2 {
color: red;
overflow: auto;
height: 100%;
}
https://jsfiddle.net/r4hdcwy2/
Many thanks for your suggestions!
What you need to do is make 2nd column's position absolute, so its height is relative to parent's.
If the 1st column's height grows, 2nd column will follow accordingly. If the 1st column's height is shorter than 2nd column's, 2nd column will keep parent div's height, which is
150px
by default.Here is a working example: