If you have containers breaking lines, after hours looking for a good CSS solution and finding none, I now use jQuery instead:
$('button').click(function(){_x000D_
_x000D_
$('nav ul').each(function(){_x000D_
_x000D_
$parent = $(this).parent();_x000D_
_x000D_
$parent.width( $(this).width() );_x000D_
_x000D_
});_x000D_
});
_x000D_
nav {_x000D_
display: inline-block;_x000D_
text-align: left; /* doesn't do anything, unlike some might guess */_x000D_
}_x000D_
ul {_x000D_
display: inline;_x000D_
}_x000D_
_x000D_
/* needed style */_x000D_
ul {_x000D_
padding: 0;_x000D_
}_x000D_
body {_x000D_
width: 420px;_x000D_
}_x000D_
_x000D_
/* just style */_x000D_
body {_x000D_
background: #ddd;_x000D_
margin: 1em auto;_x000D_
}_x000D_
button {_x000D_
display: block;_x000D_
}_x000D_
nav {_x000D_
background: #bbb;_x000D_
margin: 1rem auto;_x000D_
padding: 0.5rem;_x000D_
}_x000D_
li {_x000D_
display: inline-block;_x000D_
width: 40px;_x000D_
height: 20px;_x000D_
border: solid thin #777;_x000D_
margin: 4px;_x000D_
background: #999;_x000D_
text-align: center;_x000D_
}
_x000D_
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>_x000D_
_x000D_
<button>fix</button>_x000D_
_x000D_
<nav>_x000D_
<ul>_x000D_
<li>3</li>_x000D_
<li>.</li>_x000D_
<li>1</li>_x000D_
<li>4</li>_x000D_
</ul>_x000D_
</nav>_x000D_
_x000D_
<nav>_x000D_
<ul>_x000D_
<li>3</li>_x000D_
<li>.</li>_x000D_
<li>1</li>_x000D_
<li>4</li>_x000D_
<li>1</li>_x000D_
<li>5</li>_x000D_
<li>9</li>_x000D_
<li>2</li>_x000D_
<li>6</li>_x000D_
<li>5</li>_x000D_
<li>3</li>_x000D_
<li>5</li>_x000D_
</ul>_x000D_
</nav>
_x000D_