The problem is vertically fitting as much text as possible in a child <div>
without having the child <div>
grow beyond the parent container <div>
and without knowing the amount of remaining space in the parent container in advance.
The container has a fixed height and two children. Here is a sample HTML snippet:
<div class="container">
<div class="title">
The title, this must grow as much as needed
</div>
<div class="text">
Some text that goes beyond the size of the container. I want this text to be cut with ellipsis when the container "ends"
</div>
</div>
and the corresponding stylesheet:
.container {
width: 15rem;
background-color: yellow;
height: 20rem;
}
.title {
font-size: 200%;
font-wieght: 600;
}
.text {
text-overflow: ellipsis;
border: 2px solid red;
}
The first child (the title) must adapt its size to the contained text. The other child must use up to the remaining vertical space, but it must not grow beyond the fizex height of its parent.
This jsfiddle shows what I'm trying to achieve.
I need a solution with CSS only, no Javascript possible. I can change the HTML structure if needed.
EDIT after the hints to add overflow: hidden
to the container:
Since doing exaclty what I need does not seem to be possible, I can live without the ellipsis, so the overflow: hidden
solution would be ok for me. However I've tried that but it does not seem to work: