07-26-1-grid-layout-implicit-auto-sparse.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Grid layout using the auto algorithm – sparse</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. /**
  13. * 1. The grid has only one auto-sized row.
  14. * 2. We can use the repeat()-function for sequences of same-size tracks.
  15. * 3. By default, grids outside of the defined grid end up in auto-created
  16. * tracks. This is called the implicit grid.
  17. * 4. The auto-rows are sized with grid-auto-rows: the default value is "auto".
  18. */
  19. .grid-auto-rows {
  20. list-style: none;
  21. padding: 0;
  22. display: -webkit-grid;
  23. display: grid;
  24. -webkit-grid-template-rows: auto; /* 1 */
  25. grid-template-rows: auto; /* 1 */
  26. -webkit-grid-template-columns: repeat(5, 1fr); /* 2 */
  27. grid-template-columns: repeat(5, 1fr); /* 2 */
  28. /* grid-auto-flow: row; - this is implied. */ /* 3 */
  29. /* grid-auto-rows: auto; - this is implied */ /* 4 */
  30. margin: 1.5em -.6875em;
  31. }
  32. /* some stories with different spans */
  33. .story:nth-child(1),
  34. .story:nth-child(2) {
  35. -webkit-grid-column: span 3;
  36. grid-column: span 3;
  37. }
  38. .story:nth-child(4) {
  39. -webkit-grid-column: span 2;
  40. grid-column: span 2;
  41. }
  42. .story {
  43. padding: .6875em;
  44. margin: 0 .6875em 1.375em;
  45. background-color: #eee;
  46. }
  47. </style>
  48. </head>
  49. <body>
  50. <div class="wrapper">
  51. <main>
  52. <div class="subsection">
  53. <ul class="grid-auto-rows">
  54. <li class="story">
  55. <h3><a href="#">Story 1</a></h3>
  56. </li>
  57. <li class="story">
  58. <h3><a href="#">Story 2</a></h3>
  59. </li>
  60. <li class="story">
  61. <h3><a href="#">Story 3</a></h3>
  62. </li>
  63. <li class="story">
  64. <h3><a href="#">Story 4</a></h3>
  65. </li>
  66. <li class="story">
  67. <h3><a href="#">Story 5</a></h3>
  68. </li>
  69. <li class="story">
  70. <h3><a href="#">Story 6</a></h3>
  71. </li>
  72. <li class="story">
  73. <h3><a href="#">Story 7</a></h3>
  74. </li>
  75. <li class="story">
  76. <h3><a href="#">Story 8</a></h3>
  77. </li>
  78. <li class="story">
  79. <h3><a href="#">Story 9</a></h3>
  80. </li>
  81. </ul>
  82. </div>
  83. </main>
  84. </div>
  85. </body>
  86. </html>