Whenever I set a <p>
tag with a specific max-width
, the paragraph sometimes ends up taking more horizontal space than necessary due to text formatting. Is there a way to make it shrink to fit the minimum required horizontal space without altering the text visually? Below are my design criteria:
- The
max-width
property is specified - The text appearance remains unchanged, avoiding hyphenation at line breaks
- A background color should fill exactly within the defined area, no overflow allowed
For illustration, in this demo, the first paragraph's width measures 123px although 104px would suffice for its content, similar to the second example.
An image presented highlights the excess space that needs removing, contrasting with the desired outcome displayed in the second paragraph:
https://i.sstatic.net/i2Zo6.png
Any suggestions on how to accomplish this?