07-22-grid-layout-alignment.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Grid layout with grid track alignment</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. body {
  13. padding: 2em;
  14. }
  15. .grid {
  16. display: -webkit-grid;
  17. display: grid;
  18. height: 100px;
  19. margin-bottom: 4em;
  20. outline: 2px dashed #666;
  21. width: 500px;
  22. -webkit-grid-template-rows: 100px;
  23. grid-template-rows: 100px;
  24. -webkit-grid-template-columns: repeat(8, 50px);
  25. grid-template-columns: repeat(8, 50px);
  26. justify-content: start; /* implied, default */
  27. }
  28. .grid-end {
  29. -webkit-justify-content: end;
  30. justify-content: end;
  31. }
  32. .grid-center {
  33. -webkit-justify-content: center;
  34. justify-content: center;
  35. }
  36. .grid-space-between {
  37. -webkit-justify-content: space-between;
  38. justify-content: space-between;
  39. }
  40. .grid-space-around {
  41. -webkit-justify-content: space-around;
  42. justify-content: space-around;
  43. }
  44. .grid-space-evenly {
  45. -webkit-justify-content: space-evenly;
  46. justify-content: space-evenly;
  47. }
  48. .grid > * {
  49. outline: 1px solid #fff;
  50. background-color: #ccc;
  51. }
  52. </style>
  53. </head>
  54. <body>
  55. <div class="grid">
  56. <div></div>
  57. <div></div>
  58. <div></div>
  59. <div></div>
  60. <div></div>
  61. <div></div>
  62. <div></div>
  63. <div></div>
  64. </div>
  65. <div class="grid grid-end">
  66. <div></div>
  67. <div></div>
  68. <div></div>
  69. <div></div>
  70. <div></div>
  71. <div></div>
  72. <div></div>
  73. <div></div>
  74. </div>
  75. <div class="grid grid-center">
  76. <div></div>
  77. <div></div>
  78. <div></div>
  79. <div></div>
  80. <div></div>
  81. <div></div>
  82. <div></div>
  83. <div></div>
  84. </div>
  85. <div class="grid grid-space-between">
  86. <div></div>
  87. <div></div>
  88. <div></div>
  89. <div></div>
  90. <div></div>
  91. <div></div>
  92. <div></div>
  93. <div></div>
  94. </div>
  95. <div class="grid grid-space-around">
  96. <div></div>
  97. <div></div>
  98. <div></div>
  99. <div></div>
  100. <div></div>
  101. <div></div>
  102. <div></div>
  103. <div></div>
  104. </div>
  105. <div class="grid grid-space-evenly">
  106. <div></div>
  107. <div></div>
  108. <div></div>
  109. <div></div>
  110. <div></div>
  111. <div></div>
  112. <div></div>
  113. <div></div>
  114. </div>
  115. </body>
  116. </html>