If you apply a max-width
and display:inline-block;
to a div with text in it, the div will expand only as wide as the text is, until the text is so wide that a new line has to be started. Past this point, the div will take the maximum width allowed, regardless of how wide the widest line of text actually is.
My point is illustrated in this fiddle:
https://jsfiddle.net/nx570uu6/
<div class="wrapper">
<div class="item">
words
</div>
<div class="item">
wordswordswords wordswordswords wordswordswords
</div>
<div class="item">
words
</div>
</div>
.wrapper {
width:200px;
height:400px;
background:blue;
}
.item {
max-width:90%;
background:green;
margin:5px 0;
display:inline-block;
}
Is there a way to make the div only as wide as the widest line of text?
So instead of this:
|wordswordswords |
|wordswordswordswords |
|wordswords |
The div would look like this:
|wordswordswords |
|wordswordswordswords|
|wordswords |