06-27-flexbox-navbar-justify-center.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Navbar using flexbox, justified to center</title>
  6. <script src="js/html5shiv.min.js"></script>
  7. <style>
  8. nav {
  9. display: block;
  10. }
  11. .navbar ul {
  12. display: -webkit-flex;
  13. display: -ms-flexbox;
  14. display: -webkit-box;
  15. display: -moz-box;
  16. display: flex;
  17. -webkit-justify-content: center;
  18. -ms-flex-pack: center;
  19. -webkit-box-pack: center;
  20. -moz-box-pack: center;
  21. justify-content: center;
  22. font-family: 'Avenir Next', Avenir, Corbel, 'Franklin Gothic', 'Century Gothic', CenturyGothic, AppleGothic, sans-serif;
  23. list-style: none;
  24. padding: 0;
  25. background-color: #486a8e;
  26. }
  27. .navbar li {
  28. text-transform: uppercase;
  29. text-align: center;
  30. -moz-box-sizing: border-box;
  31. box-sizing: border-box;
  32. background-color: #12459e;
  33. outline: 1px solid #fff;
  34. }
  35. .navbar li a {
  36. display: block;
  37. text-decoration: none;
  38. line-height: 1.75em;
  39. padding: 1em;
  40. color: #fff;
  41. }
  42. </style>
  43. </head>
  44. <body>
  45. <nav class="navbar">
  46. <ul>
  47. <li><a href="/home">Home</a></li>
  48. <li><a href="/spaceships">Spaceships</a></li>
  49. <li><a href="/planets">Planets</a></li>
  50. <li><a href="/stars">Stars</a></li>
  51. </ul>
  52. </nav>
  53. </body>
  54. </html>