79676072

Date: 2025-06-23 11:21:30
Score: 4
Natty:
Report link

I am writing this answer since I do not have enough reputation to write a comment yet.

I have found this post whilst having the same problem and tried to recreate my own problematic code, since this was asked for in the comments, so this is just what I think could be the problem, rather than a solution.

In my case, the problem is the display type.
The element containing the text will only stay as wide as the text itself when using display: inline.

But since using this is not always an option, I think what the original poster needs is a way to limit the width to the text with non-inline display attribute values and without using width: min-content.

<div style="width: 65px;background: black;">
  <span style="display: block;background: gray;">Short Text</span>
</div>

Reasons:
  • RegEx Blacklisted phrase (1.5): I do not have enough reputation
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): having the same problem
  • Low reputation (1):
Posted by: kleenerStern