EDIT. The question is reworded as suggested by @Aziz in his comments. It was previously asking about achieving the same effect with inline-block
, which seems impossible, see the answer to
CSS when inline-block elements line-break, parent wrapper does not fit new width. The new question asks how else this effect can be achieved, so it is no more duplicate.
I have a parent row container with two child columns. I want each of the children to wrap their text content and then shrink to fit their width after the wrapping.
The example below almost achieves this effect:
.parent {
display: inline-block;
}
.child {
max-width: 180px;
display: inline-block;
border: solid thin;
}
<div class="parent">
<div class="child">
I am child with loooong text.
</div>
<div class="child">
I am child with loooong text.
</div>
</div>
The only problem is that each child does not completely shrink to fit its content. There is clear white space gap on the right of the text inside each child.