博客列表 >Grid布局中的栅格布局

Grid布局中的栅格布局

辰辰
辰辰原创
2021年03月30日 15:39:46607浏览

栅格

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <link rel="stylesheet" href="demo1.css">
  9. </head>
  10. <body>
  11. <div class="container">
  12. <!-- 一等分 -->
  13. <div class="row">
  14. <span class="item col-12">12/12</span>
  15. </div>
  16. <!-- 二等分 -->
  17. <div class="row">
  18. <span class="item col-6">6/12</span>
  19. <span class="item col-6">6/12</span>
  20. </div>
  21. <!-- 三等分 -->
  22. <div class="row">
  23. <span class="item col-4">4/12</span>
  24. <span class="item col-4">4/12</span>
  25. <span class="item col-4">4/12</span>
  26. </div>
  27. <!-- 三等分 6:2:4 -->
  28. <div class="row">
  29. <span class="item col-6">6/12</span>
  30. <span class="item col-2">2/12</span>
  31. <span class="item col-4">4/12</span>
  32. </div>
  33. </div>
  34. </body>
  35. </html>

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. body {
  7. width: 100vw;
  8. height: 100vh;
  9. display: grid;
  10. place-content: center;
  11. }
  12. .container {
  13. display: grid;
  14. width: 80vw;
  15. gap: 0.5em;
  16. }
  17. .container .row {
  18. display: grid;
  19. grid-template-columns: repeat(12, 1fr);
  20. min-height: 3em;
  21. gap: 0.5em;
  22. }
  23. .container .row .item {
  24. padding: 1em;
  25. border: 1px solid;
  26. background-color: lightblue;
  27. }
  28. .col-12 {
  29. grid-area: auto / span 12;
  30. }
  31. .col-11 {
  32. grid-area: auto / span 11;
  33. }
  34. .col-10 {
  35. grid-area: auto / span 10;
  36. }
  37. .col-9 {
  38. grid-area: auto / span 9;
  39. }
  40. .col-8 {
  41. grid-area: auto / span 8;
  42. }
  43. .col-7 {
  44. grid-area: auto / span 7;
  45. }
  46. .col-6 {
  47. grid-area: auto / span 6;
  48. }
  49. .col-5 {
  50. grid-area: auto / span 5;
  51. }
  52. .col-4 {
  53. grid-area: auto / span 4;
  54. }
  55. .col-3 {
  56. grid-area: auto / span 3;
  57. }
  58. .col-2 {
  59. grid-area: auto / span 2;
  60. }
  61. .col-1 {
  62. grid-area: auto / span 1;
  63. }

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议