Guest User

Untitled

a guest
Mar 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. Emmet
  2.  
  3. First we create a div with the class *container* with 10 different
  4. divs inside with the class *Item*.
  5.  
  6. emmet .container>div.Item*10
  7.  
  8. should create:
  9. ----
  10. <div class="container">
  11. <div class="Item"></div>
  12. <div class="Item"></div>
  13. <div class="Item"></div>
  14. <div class="Item"></div>
  15. <div class="Item"></div>
  16. <div class="Item"></div>
  17. <div class="Item"></div>
  18. <div class="Item"></div>
  19. <div class="Item"></div>
  20. <div class="Item"></div>
  21. </div>
  22. ----
  23.  
  24. If you want 30 divs with the class name in sequential order and the content inside in sequential order use $.
  25. ----
  26. .item${$}*30{$}
  27. ----
  28.  
  29. To start our grid, in the CSS we modify *container* by giving it
  30. ----
  31. display: grid;
  32. ----
  33.  
  34. To modify its columns and rows which are called tracks. Tracks are numbered
  35. not by the column itself, but actually by the line that starts and stop. So we'll always
  36. have one more number than we've actually set.
  37.  
  38. With the 10 different divs, we can control it with this:
  39.  
  40. rid-template-columns: 300px 200px;
  41. That will give it 2 columns. 1st column is 300px and the 2nd column is 200px.
  42.  
  43. We can also control its rows:
  44. grid-template-rows: repeat(2, 200px);
  45. Here we will repeat the first two rows 200px.
  46.  
  47. grid-gap: 20px
  48. This will give it a padding around the boxes 20px.
  49.  
  50. Knowing the difference between explicit and implicit
  51.  
  52.  
  53. When there is a 2x2 grid and we set the two columns to be
  54.  
  55. grid-template-columns: 200px 400px
  56.  
  57. Explicit: we have explicitly set the columns to be 200px and 400px.
  58. Implicit: the Rows would be implicit because we didn't set anything for it.
  59.  
  60. If we added:
  61.  
  62. grid-template-rows: 200px 400px
  63.  
  64. Then the columns and rows would be explicit.
  65.  
  66. Now the good thing to know with implicit is that, if we've explicitly
  67. set rows or columns but was too lazy to set the extra ones that are
  68. created after that, we can just use *auto*.
  69.  
  70. grid-auto-rows: 100px;
  71. grid-auto-columns: 100px;
  72.  
  73. In firefox, you can only pass 1 value for implicit, but you can add more than 1 for chrome.
  74.  
  75. By default any extra columns that aren't set will be turned into a row automatically.
  76. grid-auto-flow: row;
  77.  
  78. However, if you want it to actually create another column instead, you can type:
  79. grid-auto-flow: column;
  80.  
  81. When defining the size to use grid and you want to give the 2nd or third the etc space, you
  82. use 1fr.
  83. for example:
  84. grid-template-columns: 100px 200px 1fr;
  85.  
  86. if you use 1fr together with another 1fr, they will split with each other evenly.
  87. grid-template-columns: 1fr 1fr;
  88. will have a complete half and half layout.
  89. If you want the first fr to have 2/3 of the layout, then you can set it 2fr.
  90. grid-template-columns: 2fr 1fr;
  91.  
  92. fr only works for column's view, and only works with row's content.
  93.  
  94. You can also use auto which will automatically set the width for content.
  95.  
  96.  
  97. If you want a div item to take up more spots, you set it with *span*.
  98. Example:
  99. ----
  100. grid-column: span 2;
  101. ----
  102. That will use up two of the column spots following after it if there's
  103. no space, then it will go to the next row. This will work with rows as well:
  104.  
  105. grid-row: span 2;
  106.  
  107. instead of span (or use it with span), you can use grid-column-start/end and grid-row-start/end to
  108. control how large and actually control where it gets placed using the grid's track.
  109. ----
  110. grid-column-start: 3;
  111. grid-column-end: 10;
  112. grid-row-start: 1;
  113. grid-row-end:9;
  114. ----
  115. shorthand
  116. ----
  117. grid-column: 3 / 10;
  118. grid-row: 1 / 9
  119. ----
  120.  
  121. if you want it to end at the very end but not sure what it'll be, you can use *-1*.
  122.  
  123. ----
  124. grid-column: 1 / -1;
  125. ----
  126.  
  127. Another thing to use with repeat() instead of giving it a number of items to use,
  128. we can use *auto-fill* which will input whatever is in there to fill the whole page no
  129. matter the resize.
  130.  
  131. when using repeat, we learned about auto-fill, and the second parameter is the size in px or something else.
  132. There's a more convenient thing to use which is minmax(minimum, maximum). That way when you resize the window, it won't
  133. cut anything off but will just send it to a new row.
  134.  
  135. auto-fill, minmax(150px, 1fr);
  136.  
  137. will keep it at 4 indexes but small.
  138.  
  139. auto-fit, minmax(150px, 1fr);
  140. will try to take up the whole space with the 4 divs.
  141.  
  142. if you like to use auto, there's also fit-content that will give a maximum.
Add Comment
Please, Sign In to add comment