Let's assume we have a <span>
element with the following css:
span {
display: inline-block;
max-width: 250px;
}
In case our text is short and it fits in only one row, the width of the span will have exactly the width of the content. Otherwise, if the text is larger and it needs to break on multiple lines, the width of the span will be exactly the max-width (250px) and not the width of the content.
I would like my span
to always have the width of the content itself. Is this possible somehow?
span {
display: inline-block;
max-width: 250px;
}
<span style="background-color: green">Lorem ipsum</span>
<br>
<br>
<span style="background-color: red">Lorem ipsum dolor sit amet, consectetur adipiscing elit</span>