Blogger Information
Blog 10
fans 0
comment 0
visits 5563
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0329作业
手机用户1615433136
Original
427 people have browsed it

使用grid实现一个12列栅格布局的组件

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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>使用grid实现一个12列栅格布局的组件</title>
  8. <link rel="stylesheet" href="gird.css" />
  9. </head>
  10. <body>
  11. <div class="container">

先写行,在行中再定一列

  • 一等分
    1. <div class="row">
    2. <span class="item col-12">12列</span>
    3. </div>
  • 二等分
    1. <div class="row">
    2. <span class="item col-6">6列</span>
    3. <span class="item col-6">6列</span>
    4. </div>
  • 三等分
    1. <div class="row">
    2. <span class="item col-4">4列</span>
    3. <span class="item col-4">4列</span>
    4. <span class="item col-4">4列</span>
    5. </div>
  • 二等分 2:10
    1. <div class="row">
    2. <span class="item col-2">2列</span>
    3. <span class="item col-10">10列</span>
    4. </div>
    5. </div>
    6. </body>
    7. </html>

    grid.css部分

    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. .containter {
    13. min-width: 80vw;
    14. display: grid;
    15. gap: 0.5em;
    16. }
    17. .containter > .row {
    18. display: grid;
    19. /* 任何一行都是由12列组成 */
    20. grid-template-columns: repeat(12, 1fr);
    21. min-height: 3em;
    22. gap: 0.5em;
    23. }
    24. .containter > .row > .item {
    25. padding: 1em;
    26. border: 1px solid;
    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. }

    使用grid实现12列栅格布局组件来完成圣杯布局

    1. <!DOCTYPE html>
    2. <html lang="zh-CN">
    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>使用grid实现12列栅格布局组件来完成圣杯布局</title>
    8. <link rel="stylesheet" href="gird.css" />
    9. </head>
    10. <style>
    11. .row:nth-of-type(2) {
    12. height: 80vh;
    13. }
    14. </style>
    15. <body>
    16. <div class="containter">
    17. <!-- 页眉0 -->
    18. <div class="row">
    19. <div class="item col-12 header">header</div>
    20. </div>
    21. <!-- 主体 -->
    22. <div class="row">
    23. <!-- 左2列,中间8列,右边2列 -->
    24. <div class="item col-2 left">left</div>
    25. <div class="item col-8 main">main</div>
    26. <div class="item col-2 right">right</div>
    27. </div>
    28. <!-- 页脚 -->
    29. <div class="row">
    30. <div class="item col-12 footer">footer</div>
    31. </div>
    32. </div>
    33. </body>
    34. </html>
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post