Blogger Information
Blog 26
fans 0
comment 2
visits 35039
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Grid布局属性复习(1230前端开发学习)
小辰
Original
544 people have browsed it

1.手写属性图


2.效果图

3.上代码

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>对grid属性的实验</title>
  5. <style type="text/css">
  6. /*设置网格虚线边框*/
  7. * :not(body){
  8. outline: 1px dashed blue;
  9. }
  10. .container{
  11. width: 800px;
  12. /*font-size: 2rem;*/
  13. /*划分四列三行*/
  14. display: grid;
  15. grid-template-columns: repeat(4,1fr);
  16. grid-template-rows: repeat(3, 1fr);
  17. /*设置扩展后的隐式网格,只可以扩展行高*/
  18. grid-auto-rows:200px;
  19. /*设置格子之间的间距,上左下右*/
  20. grid-gap:5px ;
  21. /*设置 所有 项目的对齐方式居中*/
  22. /*place-items:center;*/
  23. }
  24. .container > .item:first-of-type {
  25. /*一号占据两格*/
  26. grid-area:1/1/2/3;
  27. background-color: red;
  28. /*对项目进行编号*/
  29. /*从第三列开始*/
  30. /*grid-column-start: 3;*/
  31. /*从第五列结束*/
  32. /*grid-column-end: 5;*/
  33. /*从第二行开始,从第四行结束,第几行主要是行号*/
  34. grid-row-start:2;
  35. grid-row-end:4;
  36. /*设置 单个 项目在单元格的对齐方式*/
  37. /*place-self:center;*/
  38. }
  39. /*使其正常需要注释掉字体大小*/
  40. .row {
  41. display: grid;
  42. /* 平均等比分成12份 */
  43. grid-template-columns: repeat(12, 1fr);
  44. grid-column-gap: 8px;
  45. height: 50px;
  46. margin-bottom: 10px;
  47. background-color: #eeeeee;
  48. }
  49. .col-1 {
  50. grid-column-end: span 1;
  51. }
  52. .col-2 {
  53. grid-column-end: span 2;
  54. }
  55. .col-3 {
  56. grid-column-end: span 3;
  57. }
  58. .col-4 {
  59. grid-column-end: span 4;
  60. }
  61. .col-5 {
  62. grid-column-end: span 5;
  63. }
  64. .col-6 {
  65. grid-column-end: span 6;
  66. }
  67. .col-7 {
  68. grid-column-end: span 7;
  69. }
  70. .col-8 {
  71. grid-column-end: span 8;
  72. }
  73. /*对15网格的命名划分*/
  74. .item15 {
  75. width: 600px;
  76. height: 150px;
  77. font-size: 2rem;
  78. display: grid;
  79. /* 给每一个单元格命名 */
  80. grid-template-areas: 'a b'
  81. }
  82. .item15 > .item:first-of-type {
  83. /* 项目命名: grid-area */
  84. grid-area: a;
  85. background-color: lightgreen;
  86. }
  87. </style>
  88. </head>
  89. <body>
  90. <div class="container">
  91. <div class="item">1</div>
  92. <div class="item">2</div>
  93. <div class="item">3</div>
  94. <div class="item">4</div>
  95. <div class="item">5</div>
  96. <div class="item">6</div>
  97. <div class="item">7</div>
  98. <div class="item">8</div>
  99. <div class="item">9</div>
  100. <div class="item">10</div>
  101. <div class="item">11</div>
  102. <div class="item">12</div>
  103. <div class="row">
  104. <span class="item col-2">2列</span>
  105. <span class="item col-3">3列</span>
  106. </div>
  107. <div class="item15">
  108. <span>1</span>
  109. <span>1</span>
  110. </div>
  111. </div>
  112. </body>
  113. </html>

4.小结

通过对grid属性的复习,我对grid布局有了进一步的了解,grid布局的方法比较多,我还比较倾向于,划分好网格,就像圣杯布局,我只要按照顺序在里面
添加东西,在划分号的特定区域里,进行felx布局,这样布局就方便多了。

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:grid布局肯定是会有以后几年的趋势, 早学早受益
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