EDIT: It turns out this is currently impossible with just CSS. A good explanation can be found here: CSS Width / Max-Width on Line Wrap?
Below, I have an outer
class which specifies a fixed width, and an inner
class which contains text.
<div class="outer">
<div class="inner">
Lorem ipsum dolor sit, consectetur adipiscing elit, sed do eiusmod tempor
</div>
</div>
.inner {
padding: 0.25rem;
border: 1px solid grey;
}
.outer {
width: 12.5rem;
padding: 0.25rem;
border: 1px solid lightblue;
}
This leaves a gap to the right of the text:
But I would like the inner
class to wrap tightly to the text itself, like this:
How can I achieve B using CSS?
I need a solution that is more dynamic than specifying an exact width for inner
and doesn't change where the line breaks occur (e.g. using word-wrap: break-all
)!
Clarification
The padding is there just to help make the example look clearer. Without padding, the issue remains.
I get:
But I would like: