I want to have a div
with a given max-width
that tightly fits its width to its child's span
. Everything works fine as long as the span
is only one line, but as soon as the line break happens the parent div
will have the maximum width.
.content {
margin: 10px;
max-width: 150px;
border: 1px dotted black;
display: inline-block;
}
<div class="content">
<span>1 line works</span>
</div>
<br>
<div class="content">
<span>2 lines dont workworkwork</span>
</div>
The first div has a tight fit, the second div however is set at the maximum width - but it could be tighter and I want it tighter. See also my pen at http://codepen.io/sheinzle/pen/gpVjbG
Is getting a tighter fit even possible in HTML?