06-30-flexbox-navbar-marginauto.html 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Navbar using flexbox, automatic right margin on first item</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. font-family: 'Avenir Next', Avenir, Corbel, 'Franklin Gothic', 'Century Gothic', CenturyGothic, AppleGothic, sans-serif;
  18. list-style: none;
  19. padding: 0;
  20. background-color: #486a8e;
  21. }
  22. .navbar li {
  23. text-transform: uppercase;
  24. text-align: center;
  25. -moz-box-sizing: border-box;
  26. box-sizing: border-box;
  27. background-color: #12459e;
  28. outline: 1px solid #fff;
  29. }
  30. .navbar li:first-child {
  31. margin-right: auto;
  32. }
  33. .navbar li a {
  34. display: block;
  35. text-decoration: none;
  36. line-height: 1.75em;
  37. padding: 1em;
  38. color: #fff;
  39. }
  40. </style>
  41. </head>
  42. <body>
  43. <nav class="navbar">
  44. <ul>
  45. <li><a href="/home">Home</a></li>
  46. <li><a href="/spaceships">Spaceships</a></li>
  47. <li><a href="/planets">Planets</a></li>
  48. <li><a href="/stars">Stars</a></li>
  49. </ul>
  50. </nav>
  51. </body>
  52. </html>