Blogger Information
Blog 55
fans 3
comment 0
visits 54661
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php中文网grid布局实战
王佳祥
Original
866 people have browsed it

php中文网grid布局实战

  • php中文网原图:


  • 自己写的效果:


  • 代码:
  1. <!-- php入门精品课程开始 -->
  2. <div class="content5 flexCompatible flexVertical flexShrinkFixed">
  3. <div class="flexCompatible flexVertical">
  4. <div class="top">
  5. <span class="iconfont icon-daima2"></span>
  6. <h2>PHP入门精品课程</h2>
  7. <span class="iconfont icon-daima2"></span>
  8. </div>
  9. <div class="bottom ">
  10. <ul>
  11. <li><img src="images/入门精品课程.jpg" alt=""></li>
  12. <li>
  13. <a href="">
  14. <img src="images/t1.jpg" alt="">
  15. <div>
  16. <div>
  17. <span class="span1">中级</span>
  18. <span>ThinkPHP6.0极速入门</span>
  19. </div>
  20. <div><span class="span2">4W+次播放</span></div>
  21. </div>
  22. </a>
  23. </li>
  24. <li>
  25. <a href="">
  26. <img src="images/t2.png" alt="">
  27. <div>
  28. <div>
  29. <span class="span1">初级</span>
  30. <span>编程学习方法分享直播</span>
  31. </div>
  32. <div><span class="span2">1W+次播放</span></div>
  33. </div>
  34. </a>
  35. </li>
  36. <li>
  37. <a href="">
  38. <img src="images/t3.jpg" alt="">
  39. <div>
  40. <div>
  41. <span class="span1">初级</span>
  42. <span>2018前端入门_HTML5</span>
  43. </div>
  44. <div><span class="span2">18W+次播放</span></div>
  45. </div>
  46. </a>
  47. </li>
  48. <li>
  49. <a href="">
  50. <img src="images/t4.jpg" alt="">
  51. <div>
  52. <div>
  53. <span class="span1">中级</span>
  54. <span>CSS视频教程-玉女心经</span>
  55. </div>
  56. <div><span class="span2">10W+次播放</span></div>
  57. </div>
  58. </a>
  59. </li>
  60. <li>
  61. <a href="">
  62. <img src="images/t5.jpg" alt="">
  63. <div>
  64. <div>
  65. <span class="span1">初级</span>
  66. <span>JavaScript极速入门</span>
  67. </div>
  68. <div><span class="span2">18W+次播放</span></div>
  69. </div>
  70. </a>
  71. </li>
  72. <li>
  73. <a href="">
  74. <img src="images/t6.jpg" alt="">
  75. <div>
  76. <div>
  77. <span class="span1">中级</span>
  78. <span>孤独九剑(6)_jQuery</span>
  79. </div>
  80. <div><span class="span2">12W+次播放</span></div>
  81. </div>
  82. </a>
  83. </li>
  84. <li>
  85. <a href="">
  86. <img src="images/t7.jpeg" alt="">
  87. <div>
  88. <div>
  89. <span class="span1">初级</span>
  90. <span>30分钟学会网站布局</span>
  91. </div>
  92. <div><span class="span2">6W+次播放</span></div>
  93. </div>
  94. </a>
  95. </li>
  96. <li>
  97. <a href="">
  98. <img src="images/t8.jpg" alt="">
  99. <div>
  100. <div>
  101. <span class="span1">初级</span>
  102. <span>[公益直播课]Web前端</span>
  103. </div>
  104. <div><span class="span2">5W+次播放</span></div>
  105. </div>
  106. </a>
  107. </li>
  108. <li>
  109. <a href="">
  110. <img src="images/t9.jpg" alt="">
  111. <div>
  112. <div>
  113. <span class="span1">初级</span>
  114. <span>phpSyudy极速入门视频</span>
  115. </div>
  116. <div><span class="span2">40W+次播放</span></div>
  117. </div>
  118. </a>
  119. </li>
  120. <li>
  121. <a href="">
  122. <img src="images/t10.jpg" alt="">
  123. <div>
  124. <div>
  125. <span class="span1">中级</span>
  126. <span>孤独九剑(4)_PHP视频</span>
  127. </div>
  128. <div><span class="span2">50W+次播放</span></div>
  129. </div>
  130. </a>
  131. </li>
  132. <li>
  133. <a href="">
  134. <img src="images/t11.jpg" alt="">
  135. <div>
  136. <div>
  137. <span class="span1">初级</span>
  138. <span>php完全自学手册</span>
  139. </div>
  140. <div><span class="span2">20W+次播放</span></div>
  141. </div>
  142. </a>
  143. </li>
  144. <li>
  145. <a href="">
  146. <img src="images/t12.jpg" alt="">
  147. <div>
  148. <div>
  149. <span class="span1">初级</span>
  150. <span>MySQL权威开发指南</span>
  151. </div>
  152. <div><span class="span2">2W+次播放</span></div>
  153. </div>
  154. </a>
  155. </li>
  156. <li>
  157. <a href="">
  158. <img src="images/t13.jpg" alt="">
  159. <div>
  160. <div>
  161. <span class="span1">中级</span>
  162. <span>[公益直播课]php实战</span>
  163. </div>
  164. <div><span class="span2">3W+次播放</span></div>
  165. </div>
  166. </a>
  167. </li>
  168. </ul>
  169. </div>
  170. </div>
  171. </div>
  172. <!-- php入门精品课程结束 -->

  • css代码:
  1. .content5 {
  2. width: 1200px;
  3. height: 666px;
  4. }
  5. .content5 > div {
  6. width: 1200px;
  7. height: 646px;
  8. margin-top: 20px;
  9. background: #fff;
  10. border-radius: 10px;
  11. box-shadow: 0 0 5px #888888;
  12. }
  13. .content5 > div > .top {
  14. width: 1200px;
  15. height: 50px;
  16. display: grid;
  17. grid-template-columns: 1fr 170px 1fr;
  18. }
  19. .content5 > div > .top > span {
  20. color: RGB(95, 159, 255);
  21. font-weight: bold;
  22. }
  23. .content5 > div > .top > span:first-of-type {
  24. align-self: center;
  25. justify-self: end;
  26. }
  27. .content5 > div > .top > span:last-of-type {
  28. align-self: center;
  29. }
  30. .content5 > div > .top > h2 {
  31. font-size: 20px;
  32. font-family: "宋体";
  33. color: RGB(77, 85, 93);
  34. padding: 0 5px;
  35. align-self: center;
  36. justify-self: center;
  37. }
  38. .content5 > div > .bottom ul {
  39. width: 1200px;
  40. height: 576px;
  41. display: grid;
  42. grid-template-columns: repeat(5, 217px);/*3行5列*/
  43. grid-template-rows: repeat(3, 172px);
  44. grid-gap: 20px 19px;
  45. margin: 15px 0 0 19px;
  46. }
  47. .content5 > div > .bottom > ul > li {
  48. width: 217px;
  49. height: 172px;
  50. position: relative;
  51. box-shadow: 0 0 5px #888888;
  52. border-radius: 5px;
  53. }
  54. .content5 > div > .bottom > ul > li:first-of-type {
  55. width: 217px;
  56. height: 362px;
  57. grid-row: 1/3;
  58. border-radius: 5px;
  59. box-shadow: 0 0 5px #888888;
  60. }
  61. .content5 > div > .bottom > ul > li:first-of-type img {
  62. width: 217px;
  63. height: 362px;
  64. border-radius: 5px;
  65. box-shadow: 0 0 5px #888888;
  66. }
  67. .content5 > div > .bottom > ul > li img {
  68. width: 217px;
  69. height: 124px;
  70. border-radius: 5px 5px 0 0;
  71. z-index: 10;
  72. }
  73. .content5 > div > .bottom > ul > li > a > div {
  74. width: 217px;
  75. height: 80px;
  76. z-index: 99;
  77. background: #fff;
  78. position: absolute;
  79. top: 92px;
  80. border-radius: 5px;
  81. }
  82. .content5
  83. > div
  84. > .bottom
  85. > ul
  86. > li:not(:first-of-type)
  87. > a
  88. > div
  89. > div:first-of-type {
  90. width: 217px;
  91. height: 40px;
  92. color: RGB(87, 96, 100);
  93. display: grid;
  94. grid-template-columns: repeat(11, 1fr);
  95. }
  96. .content5 > div > .bottom > ul > li:not(:first-of-type) > a .span1 {
  97. background: RGB(147, 153, 159);
  98. padding: 0 2px;
  99. margin: 0;
  100. color: #fff;
  101. grid-column: 2/4;
  102. align-self: end;
  103. justify-self: start;
  104. }
  105. .content5
  106. > div
  107. > .bottom
  108. > ul
  109. > li:not(:first-of-type)
  110. > a
  111. > div
  112. > div:first-of-type
  113. > span:last-of-type {
  114. grid-column: 4/12;
  115. align-self: end;
  116. justify-self: start;
  117. }
  118. .content5
  119. > div
  120. > .bottom
  121. > ul:first-of-type
  122. > li:not(:first-of-type)
  123. > a
  124. > div
  125. > div:last-of-type {
  126. width: 217px;
  127. height: 40px;
  128. display: grid;
  129. grid-template-columns: repeat(11, 1fr);
  130. }
  131. .content5
  132. > div
  133. > .bottom
  134. > ul:first-of-type
  135. > li:not(:first-of-type)
  136. > a
  137. .span2 {
  138. color: RGB(147, 153, 159);
  139. font-size: 14px;
  140. grid-column: 2/8;
  141. align-self: center;
  142. justify-self: start;
  143. }
  144. .content5 > div > .bottom > ul > li a {
  145. color: RGB(87, 96, 100);
  146. }

学习总结

1.grid基本概念

  1. 采用网格布局的区域,称为"容器"container
  2. 容器内部采用网格定位的子元素,称为"项目"item
  3. 容器里面的水平区域称为"行"row),垂直区域称为"列"column
  4. 行和列的交叉区域,称为"单元格"cell
  5. 划分网格的线,称为"网格线"grid line

2.容器属性

  1. display: grid指定一个容器采用网格布局
  2. grid-template-columns属性定义每一列的列宽 px / % / fr
  3. grid-template-rows属性定义每一行的行高 px / % / fr
  4. repeat()函数,简化重复的值,第一个参数是重复的次数,第二个参数是所要重复的值
  5. auto-fill关键字表示自动填充
  6. fr关键字相当于auto,系统自动计算
  7. minmax()函数产生一个长度范围,表示长度就在这个范围之中。它接受两个参数,分别为最小值和最大值
  8. grid-row-gap属性设置行与行的间隔(行间距),grid-column-gap属性设置列与列的间隔(列间距)
  9. grid-gap属性是grid-column-gapgrid-row-gap的合并简写形式,
  10. grid-gap: <grid-row-gap> <grid-column-gap>;
  11. grid-template-areas属性用于定义区域,一个区域由单个或多个单元格组成
  12. 如果某些区域不需要利用,则使用"点"(.)表示
  13. grid-auto-flow属性决定容器子元素的排列顺序
  14. 默认值是row,即"先行后列";也可以将它设成column,变成"先列后行;
  15. row dense, 表示"先行后列",并且尽可能紧密填满,尽量不出现空格
  16. column dense, 表示"先列后行",并且尽量填满空格
  17. justify-items 属性设置单元格内容的水平位置(左中右)
  18. align-items 属性设置单元格内容的垂直位置(上中下)
  19. place-items 属性是align-items属性和justify-items属性的合并简写形式
  20. place-items: <align-items> <justify-items>;
  21. grid-template属性是grid-template-columns、grid-template-rows和grid-template-areas这三个属性的合并简写形式
  22. grid属性是grid-template-rows、grid-template-columns、grid-template-areas、 grid-auto-rows、grid-auto-columns、grid-auto-flow这六个属性的合并简写形式

3.项目属性

  1. 项目的位置是可以指定的,具体方法就是指定项目的四个边框,分别定位在哪根网格线
  2. grid-column-start属性:左边框所在的垂直网格线
  3. grid-column-end属性:右边框所在的垂直网格线
  4. grid-row-start属性:上边框所在的水平网格线
  5. grid-row-end属性:下边框所在的水平网格线
  6. 这四个属性的值还可以使用span关键字,表示"跨越",即左右边框(上下边框)之间跨越多少个网格
  7. 使用这四个属性,如果产生了项目的重叠,则使用z-index属性指定项目的重叠顺序
  8. grid-column属性是grid-column-startgrid-column-end的合并简写形式
  9. grid-row属性是grid-row-start属性和grid-row-end的合并简写形式
  10. grid-area属性指定项目放在哪一个区域
  11. grid-area属性还可用作grid-row-startgrid-column-startgrid-row-endgrid-column-end的合并简写形式,直接指定项目的位置
  12. justify-self属性设置单元格内容的水平位置(左中右),跟justify-items属性的用法完全一致,但只作用于单个项目。
  13. align-self属性设置单元格内容的垂直位置(上中下),跟align-items属性的用法完全一致,也是只作用于单个项目
  14. place-self属性是align-self属性和justify-self属性的合并简写形式
  15. place-self: <align-self> <justify-self>;
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:很棒,注意class的命名
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