I have a div
that has inline-block
and a max-width
set on it, as well as some text content that may wrap inside. My problem is that the div
always takes the maximum width possible, but only if the text wraps. I wish to make the div
take the smallest width possible, in response to text wrapping.
div {
max-width: 120px;
width: auto;
display: inline-block;
border: 1px solid black;
padding: 0.2rem;
}
<div>Reallylongword test</div>
This does not work with restricting the width
with a parent, either.
I have searched around, and my code is using this method. I have also tried this (Fiddle), but it just doesn't work.
I am of aware using word-break: break-all
, but that is just really ugly.
Thank you.
Update
I am trying to make a navbar. It is currently using flexbox, not display: inline-block
. I just (or at least I thought I did) isolated the problem to single nav element. Apparantly, not all the answers seemed to match my original navbar problem. I'm sorry. I will preserve the original post if I don't get an answer to my actual problem.