07-26-2-grid-layout-implicit-auto-dense.html 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Grid layout using the auto algorithm – dense</title>
  6. <!-- the base styles and "housekeeping" styles are in here: -->
  7. <link rel="stylesheet" href="css/grid-base.css">
  8. <!-- the HTML5 shiv, to help older browsers understand styling
  9. on newer HTML5 elements: -->
  10. <script src="js/html5shiv.min.js"></script>
  11. <style>
  12. /* grid styling */
  13. .grid-auto-rows {
  14. list-style: none;
  15. padding: 0;
  16. display: -webkit-grid;
  17. display: grid;
  18. -webkit-grid-template-rows: auto;
  19. grid-template-rows: auto;
  20. -webkit-grid-template-columns: repeat(5, 1fr);
  21. grid-template-columns: repeat(5, 1fr);
  22. -webkit-grid-auto-flow: row dense;
  23. grid-auto-flow: row dense;
  24. /* grid-auto-rows: auto; - this is implied */
  25. margin: 1.5em -.6875em;
  26. }
  27. /* some stories with different spans */
  28. .story:nth-child(1),
  29. .story:nth-child(2) {
  30. -webkit-grid-column: span 3;
  31. grid-column: span 3;
  32. }
  33. .story:nth-child(4) {
  34. -webkit-grid-column: span 2;
  35. grid-column: span 2;
  36. }
  37. .story {
  38. padding: .6875em;
  39. margin: 0 .6875em 1.375em;
  40. background-color: #eee;
  41. }
  42. </style>
  43. </head>
  44. <body>
  45. <div class="wrapper">
  46. <main>
  47. <div class="subsection">
  48. <ul class="grid-auto-rows">
  49. <li class="story">
  50. <h3><a href="#">Story 1</a></h3>
  51. </li>
  52. <li class="story">
  53. <h3><a href="#">Story 2</a></h3>
  54. </li>
  55. <li class="story">
  56. <h3><a href="#">Story 3</a></h3>
  57. </li>
  58. <li class="story">
  59. <h3><a href="#">Story 4</a></h3>
  60. </li>
  61. <li class="story">
  62. <h3><a href="#">Story 5</a></h3>
  63. </li>
  64. <li class="story">
  65. <h3><a href="#">Story 6</a></h3>
  66. </li>
  67. <li class="story">
  68. <h3><a href="#">Story 7</a></h3>
  69. </li>
  70. <li class="story">
  71. <h3><a href="#">Story 8</a></h3>
  72. </li>
  73. <li class="story">
  74. <h3><a href="#">Story 9</a></h3>
  75. </li>
  76. </ul>
  77. </div>
  78. </main>
  79. </div>
  80. </body>
  81. </html>