Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. <html>
  2. <head>
  3. <style>
  4. /* Example of CSS Grid using grid-area and grid-template-areas */
  5. body {
  6. margin: 40px;
  7. }
  8.  
  9. .wrapper {
  10. /* We set the display to grid which lets us define the amount and size of columns/rows we want */
  11. display: grid;
  12. /* We want a perfect 3x3 of 100px rows and columns */
  13. grid-template-columns: 100px 100px 100px;
  14. grid-template-rows: 100px 100px 100px;
  15. /* grid-gap is the actual amount of space between grid elements */
  16. grid-gap: 10px;
  17. background-color: #fff;
  18. color: #444;
  19. }
  20.  
  21. .header {
  22. /* We use grid-area to label a section we can lay over a part of our grid */
  23. grid-area: header;
  24. background-color: aqua;
  25. }
  26.  
  27. .main {
  28. grid-area: main;
  29. background-color: #444;
  30. }
  31.  
  32. .sidebar {
  33. grid-area: sidebar;
  34. background-color: blueviolet;
  35. }
  36.  
  37. .footer {
  38. grid-area: footer;
  39. background-color: limegreen;
  40. }
  41.  
  42. @media (max-width: 600px) {
  43. .wrapper {
  44. /* We can map the grid-areas 1:1 to a text representation of our grid, remember it's a 3x3 of 100px boxes */
  45. grid-template-areas:
  46. 'header header header' /* header is 300px wide taking up a whole row */
  47. 'main main main'
  48. 'footer footer sidebar'; /* footer is 200px wide, taking 2 boxes, with sidebar taking the last 100xp box */
  49. }
  50. }
  51.  
  52. @media (min-width: 601px) {
  53. .wrapper {
  54. /* We can arbitrarily rearrange the grid areas based with media queries, also note the sidebar is spanning a column now, we are not limited to just rows */
  55. grid-template-areas:
  56. 'main main sidebar' /* sidebar is 100px wide and 200px tall as it spans two rows and one column */
  57. 'footer footer sidebar'
  58. 'header header header';
  59. }
  60. }
  61.  
  62. .box {
  63. color: #fff;
  64. border-radius: 5px;
  65. padding: 20px;
  66. font-size: 150%;
  67. }
  68. </style>
  69. </head>
  70. <body>
  71. <div class="wrapper">
  72. <div class="box header">Header</div>
  73. <div class="box footer">Footer</div>
  74. <div class="box main">Main</div>
  75. <div class="box sidebar">Sidebar</div>
  76. </div>
  77. </body>
  78. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement