Let's take a look at this div element :
<div style="
text-align : center;
font-size : min(calc(var(--fp-title-font-ratio-h) *100vh),calc(var(--fp-title-font-ratio-w) *100vw));
color : var(--brand-color);
background : rgba(0,0,0,0.0);
margin-top : 0px;
z-index : 500;
width : fit-content;
left : calc(var(--fp-title-left-ratio-h) * 100vw - (var(--fp-title-left-ratio-w) * 100vw));
transform : translateX(0%);
position : absolute;
border-radius : 10px;
text-align : left;
font-family : 'Playfair Display', serif;
text-shadow : 1px 1px 2px #040b0a, 0 0 0.2em #040b0a;
">
MY TEXT IS VERY LONG ABCDEFGH
</div>
All the variables are set. When the page loads, the div initially fits the text properly.
However, the font size is updated afterward. Ideally, I would expect the font size to be calculated before rendering the text so that the div adjusts accordingly. Instead, it seems that the font size change occurs after the div has already expanded.
The issue lies in the fact that despite using width:fit-content
, the text breaks and wraps to a new line. This behavior can be observed in both Firefox (even with width:-moz-fit-content
) and Chromium browsers.
Query:
How can I make sure that the div fits the content after applying the CSS-defined font size?
Note: The problem becomes evident when the screen size is set to 1920x1080.
Potential Solution Attempted:
Trying out display:inline
or display:inline-block
did not yield any results. While I know this could be fixed later using JavaScript, I am hoping for a pure CSS solution without relying on JavaScript. Is there a way within CSS to address this issue effectively?
Thank you.