06-44-flexbox-navbar-flexsize-grow-2-1.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Navbar using flexbox, no width</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. -webkit-box-flex: 1;
  30. -webkit-flex: 1 0 0%;
  31. -moz-box-flex: 1;
  32. -ms-flex: 1 0 0%;
  33. flex: 1 0 0%;
  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. .navbar li:first-child {
  43. -webkit-box-flex: 2;
  44. -webkit-flex-grow: 2;
  45. -moz-box-flex: 2;
  46. -ms-flex-positive: 2;
  47. flex-grow: 2;
  48. }
  49. .navbar li a {
  50. display: block;
  51. text-decoration: none;
  52. line-height: 1.75em;
  53. padding: 1em;
  54. color: #fff;
  55. }
  56. </style>
  57. </head>
  58. <body>
  59. <nav class="navbar">
  60. <ul>
  61. <li><a href="/home">Home</a></li>
  62. <li><a href="/spaceships">Spaceships</a></li>
  63. <li><a href="/planets">Planets</a></li>
  64. <li><a href="/stars">Stars</a></li>
  65. </ul>
  66. </nav>
  67. </body>
  68. </html>