Blogger Information
Blog 17
fans 0
comment 0
visits 14888
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
CSS中使用grid进行布局的应用
未来星
Original
587 people have browsed it

简单地说,CSS Grid布局就是一个二维的基于网格的布局系统,它可以同时处理列(Columns)和行(rows),目标是改变我们基于网格设计的用户接口方式。

通过简单的Grid 布局例子来熟悉它:

  1. <div class="container">
  2. <!-- 先写一行,在行中再定义列 -->
  3. <!-- 一等份 -->
  4. <div class="row">
  5. <span class="item col-12">12列</span>
  6. </div>
  7. <!-- 二等份 -->
  8. <div class="row">
  9. <span class="item col-6">6列</span>
  10. <span class="item col-6">6列</span>
  11. </div>
  12. <!-- 三等份 -->
  13. <div class="row">
  14. <span class="item col-4">4列</span>
  15. <span class="item col-4">4列</span>
  16. <span class="item col-4">4列</span>
  17. </div>
  18. <!-- 二等份: 2: 10 -->
  19. <div class="row">
  20. <span class="item col-2">2列</span>
  21. <span class="item col-10">10列</span>
  22. </div>
  23. </div>

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. .container {
  13. min-width: 80vw;
  14. display: grid;
  15. gap: 0.5em;
  16. }
  17. .container > .row {
  18. display: grid;
  19. /* 任何一行都是由12列组成 */
  20. grid-template-columns: repeat(12, 1fr);
  21. min-height: 3em;
  22. gap: 0.5em;
  23. }
  24. .container > .row > .item {
  25. padding: 1em;
  26. background-color: lightcyan;
  27. border: 1px solid;
  28. }
  29. .col-12 {
  30. grid-area: auto / span 12;
  31. }
  32. .col-11 {
  33. grid-area: auto / span 11;
  34. }
  35. .col-10 {
  36. grid-area: auto / span 10;
  37. }
  38. .col-9 {
  39. grid-area: auto / span 9;
  40. }
  41. .col-8 {
  42. grid-area: auto / span 8;
  43. }
  44. .col-7 {
  45. grid-area: auto / span 7;
  46. }
  47. .col-6 {
  48. grid-area: auto / span 6;
  49. }
  50. .col-5 {
  51. grid-area: auto / span 5;
  52. }
  53. .col-4 {
  54. grid-area: auto / span 4;
  55. }
  56. .col-3 {
  57. grid-area: auto / span 3;
  58. }
  59. .col-2 {
  60. grid-area: auto / span 2;
  61. }
  62. .col-1 {
  63. grid-area: auto / span 1;
  64. }
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