Kevin321888999

CSS Grid CSS code

Jun 28th, 2024
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.74 KB | None | 0 0
  1.  
  2.  
  3. body{margin:30px;
  4. font-family:"Poppins";
  5. }
  6. .grid-container{
  7.     background:#eee;
  8.     /*Below is the max pixels in width */
  9.     max-width: 900px;
  10.     margin:0auto;
  11.     display:grid;
  12.     /*creates a gap of 50 pixels */
  13.     gap:30px 100px;
  14.     /* Below specifies that each column for each row is 300 px each*/
  15.     /*repeat(6,1fr) 6 is the argument for how many blocks you want in the grid*/
  16.     /* 1fr stands for 1 fraction of the avaliable space max being 900px. It divides the grid container into equal fractions. */
  17.     grid-template-columns:repeat(6,1fr);
  18. }
  19.    
  20.  
  21. /*Below is a CSS selector that is targeting all the <div> elements that are direct children with the class .grid-container*/
  22. /*'.grid-container' is targeting elements with the same name grid-container. In the index.html file <div class="grid-container"
  23.  is the thing that has grid-container >*/
  24.  /*> is the child combinator selector in CSS, this selects on the the direct children of the specified element.*/
  25.  /*div is the element selector, specifiying that the code is targeting <div> elements.*/
  26.  
  27.    
  28. .grid-container > div{
  29.     background:#CCC;
  30.     text-align:center;
  31.     padding:20px;
  32.     border: 1px solid black;
  33. }
  34. /*div:nth-child is a pseudo child selector that tells the code to look at the specific child and then modify it */
  35. /*in this case this is targeting the first child of grid container. */
  36. .grid-container > div:nth-child(1){
  37.     grid-column: 1/ span 2;
  38.     /*1/span2 this is telling the computer starting at column 1 the
  39.     the selected child is going to have a span of 2 columns*/
  40. }
  41. .grid-container > div:nth-child(2){
  42.     grid-column: 2/ span 2; /*This is selecting the second child, starting it at column 2 and giving it the span of 2 columns*/
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment