I have a unique challenge with resizing text to fit within specific elements. The texts may vary in length and I want to ensure that the longest line fits perfectly within the container's width.
For example, consider this code snippet:
.container {
width: 400px;
border: 1px solid green;
padding: .5em;
}
.container>div {
border: 1px dotted gray;
}
<div class="container">
<div>Lorem ipsum dolor sit amet.</div>
<div>Lorem ipsum.</div>
<div>Lorem ipsum dolor sit amet, consetetur sadipscing elitr,<br />sed diam nonumy eirmod tempor invidunt<br />ut labore et dolore magna aliquyam erat, sed diam voluptua.</div>
</div>
This should ideally result in something like this:
https://i.sstatic.net/vPtep.jpg
I've explored using relative font sizing units without success, as manually adjusting the font-size
for each child element is not feasible. Additionally, solutions for dynamically scaling text based on viewport size don't apply here due to varying text lengths.
Is there a CSS solution to this problem, or would a JavaScript approach be more appropriate? Considering the complexity of fonts with varying letter sizes, finding a suitable method is crucial.