When I have an HTML paragraph (<p>
tag) that has its max-width
set, sometimes, depending on the text, the paragraph takes up more horizontal space than necessary. I would like to prevent this, i.e. make the paragraph shrink so that it only takes up the minimum horizontal space it needs for the text. The following are my design requirements:
max-width
property is given- the text itself should look the same, so for example, it should not be hyphenated at line breaks
- it should have a background color in its exact area, overflowing is not allowed
For example, in this fiddle, the first paragraph's width is 123px while 104px would be enough to fit its content, as shown by the second paragraph.
The following picture shows the extra space that I would like to remove, along with the desired outcome (second paragraph):
How can I achieve this?