<ul>
  <li>Home</li>
  <li>News</li>
  <li>About</li>
  <li>Contact</li>
</ul>
/*
Kudos to the friends at 

https://css-tricks.com/almanac/properties/w/width/
*/

ul {
  background: #1c7cbb;
  padding: 1em;
  width: -webkit-fit-content;
  width: -moz-fit-content;
  width: fit-content;
  margin: 1em auto;
}

li {
  display: inline-block;
  background: tomato;
  padding: 0.25em;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.