Blogger Information
Blog 22
fans 1
comment 0
visits 17700
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
第十期Grid重写二手商品交易组件页面(2019-12-28)
齐齐
Original
530 people have browsed it

Grid重写二手商品交易组件页面最终效果

网页dom结构分析和思路

采用flex布局的二手交易html代码,并做了一点细微的调整。将其放入一个三行两列的网格中,根据自己的习惯也可以先分成一个一行两列的网格。这里是分的三行两列,并创建网格区域模板。

在网格容器中,抢好货(title1)合并第一行的2个单元格效果,html代码中div(class=title1)项目通过grid-area:title1让内容放入指定网格区中。热门分类(title2)实现的方式和抢好货(title1)一样。
热门分类下方的商品展示区(goode-list),画出一个两行四列的网格,通过grid-gap设置列和行的间距。
右侧功能快速入口区(quick-entry)是一个四行两列的单元格,第三行和第四行合并同行的单元格。

html代码和css样式

html代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <link rel="stylesheet" href="public_second_hand.css">
  6. <title>公共二手交易区组件</title>
  7. </head>
  8. <body>
  9. <!--导入大标题组件-->
  10. <div class="public-headline">
  11. <span>二手交易</span>
  12. </div>
  13. <!--二手交易区-->
  14. <div class="public-second-hand">
  15. <!--标题一-->
  16. <div class="title1">
  17. <a href="">抢好货</a>
  18. <span>0低价,便捷,安全,快速</span>
  19. </div>
  20. <!--标题二-->
  21. <div class="title2">
  22. <span>热门分类</span>
  23. <a href="">美女写真</a>
  24. <a href="">日本美女</a>
  25. <a href="">美国美女</a>
  26. <a href="">国内美女</a>
  27. <a href="">AV美女</a>
  28. </div>
  29. <!-- 商品展示区-->
  30. <!-- 1.左侧为商品列表 -->
  31. <div class="goods-list">
  32. <!--商品简介-->
  33. <div class="intro">
  34. <a href="">
  35. <img src="../../static/images/shop/shop1.jpg" alt="" width="176" height="120">
  36. </a>
  37. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  38. <div>
  39. <span>¥333</span>
  40. <span>美女</span>
  41. </div>
  42. </div>
  43. <div class="intro">
  44. <a href="">
  45. <img src="../../static/images/shop/shop1.jpg" alt="" width="176" height="120">
  46. </a>
  47. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  48. <div>
  49. <span>¥333</span>
  50. <span>美女</span>
  51. </div>
  52. </div>
  53. <div class="intro">
  54. <a href="">
  55. <img src="../../static/images/shop/shop1.jpg" alt="" width="176" height="120">
  56. </a>
  57. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  58. <div>
  59. <span>¥333</span>
  60. <span>美女</span>
  61. </div>
  62. </div>
  63. <div class="intro">
  64. <a href="">
  65. <img src="../../static/images/shop/shop1.jpg" alt="" width="176" height="120">
  66. </a>
  67. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  68. <div>
  69. <span>¥333</span>
  70. <span>美女</span>
  71. </div>
  72. </div>
  73. <div class="intro">
  74. <a href="">
  75. <img src="../../static/images/shop/shop1.jpg" alt="" width="176" height="120">
  76. </a>
  77. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  78. <div>
  79. <span>¥333</span>
  80. <span>美女</span>
  81. </div>
  82. </div>
  83. <div class="intro">
  84. <a href="">
  85. <img src="../../static/images/shop/shop1.jpg" alt="" width="176" height="120">
  86. </a>
  87. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  88. <div>
  89. <span>¥333</span>
  90. <span>美女</span>
  91. </div>
  92. </div>
  93. <div class="intro">
  94. <a href="">
  95. <img src="../../static/images/shop/shop1.jpg" alt="" width="176" height="120">
  96. </a>
  97. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  98. <div>
  99. <span>¥333</span>
  100. <span>美女</span>
  101. </div>
  102. </div>
  103. <div class="intro">
  104. <a href="">
  105. <img src="../../static/images/shop/shop1.jpg" alt="" width="176" height="120">
  106. </a>
  107. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  108. <div>
  109. <span>¥333</span>
  110. <span>美女</span>
  111. </div>
  112. </div>
  113. </div>
  114. <!--2.右侧功能快速入口 -->
  115. <div class="quick-entry">
  116. <a href=""><img src="../../static/images/ad/1.png" alt=""></a>
  117. <a href=""><img src="../../static/images/ad/2.png" alt=""></a>
  118. <a href=""><img src="../../static/images/ad/3.png" alt=""></a>
  119. <a href=""><img src="../../static/images/ad/4.png" alt=""></a>
  120. <a href=""><img src="../../static/images/ad/image.png" alt=""></a>
  121. <a href=""><img src="../../static/images/ad/ad2.jpg" alt=""></a>
  122. </div>
  123. </div>
  124. </body>
  125. </html>

css代码

  1. /*导入元素的公共初始化样式表*/
  2. @import "../public_reset.css";
  3. /*大标题组件*/
  4. @import url(../public_headline/public_headline.css);
  5. .public-second-hand{
  6. width: 1200px;
  7. padding: 10px;
  8. box-sizing: border-box;
  9. margin: auto;
  10. background: white;
  11. border-radius: 5px;
  12. /*将容器转为grid容器*/
  13. display:grid;
  14. /*画网格,整体分为三行两列布局*/
  15. grid-template-columns: 760px 440px;
  16. grid-template-rows: 50px 55px 440px;
  17. /*给网格区域命名*/
  18. grid-template-areas: 'title1 title1'
  19. 'title2 title2'
  20. 'goods-list quick-entry';
  21. }
  22. .public-second-hand:hover{
  23. box-shadow: 0 0 8px #888;
  24. }
  25. .public-second-hand >.title1{
  26. /*给项目命名*/
  27. grid-area: title1;
  28. border-bottom: 1px solid #ccc;
  29. }
  30. .public-second-hand >.title1 > a{
  31. font-size: 23px;
  32. margin-right: 20px;
  33. }
  34. .public-second-hand >.title1 > span{
  35. color:red;
  36. }
  37. .public-second-hand >.title2{
  38. /*给项目命名*/
  39. grid-area: title2;
  40. }
  41. .public-second-hand >.title2>span{
  42. color:red;
  43. font-size: 23px;
  44. }
  45. .public-second-hand >.title2>a{
  46. padding-left:20px;;
  47. }
  48. .public-second-hand >.goods-list{
  49. padding: 10px;
  50. /*给项目命名*/
  51. grid-area: goods-list;
  52. /*转为grid容器*/
  53. display: grid;
  54. /*将主体划分为两行四列网格*/
  55. grid-template-columns: repeat(4,178px);
  56. grid-template-rows: repeat(2,200px);
  57. /*行间距15px,列间距10px*/
  58. grid-gap: 15px 10px;
  59. }
  60. .public-second-hand >.goods-list img{
  61. border-radius: 5px;
  62. border: 1px solid #ccc;
  63. display: block;
  64. }
  65. .public-second-hand >.goods-list a{
  66. display: block;
  67. margin-bottom: 13px;}
  68. .public-second-hand >.goods-list img:hover{
  69. box-shadow: 0 0 8px #ccc;
  70. }
  71. .public-second-hand >.goods-list>.intro>div{
  72. /*为了不使用float属性,转为flex容器*/
  73. display: flex;
  74. justify-content: space-between;
  75. }
  76. .public-second-hand >.goods-list>.intro>div>span:first-of-type{
  77. color:red;
  78. }
  79. .public-second-hand >.goods-list>.intro>div>span:last-of-type{
  80. background: #55a532;
  81. color: white;
  82. padding: 0 3px;
  83. }
  84. .public-second-hand >.quick-entry{
  85. padding: 10px;
  86. /*给项目命名*/
  87. grid-area: quick-entry;
  88. /*转为grid容器*/
  89. display: grid;
  90. /*将主体划分为四行两列网格*/
  91. grid-template-columns: repeat(2,190px);
  92. grid-template-rows: 130px 130px 60px 60px;
  93. /*行间距12px,列间距25px*/
  94. grid-gap: 12px 25px;
  95. /*网格区域命名*/
  96. grid-template-areas:'img1 img2'
  97. 'img3 img4'
  98. 'img5 img5'
  99. 'img6 img6';
  100. }
  101. .public-second-hand >.quick-entry a img{
  102. width: 190px;
  103. height: 130px;
  104. }
  105. .public-second-hand >.quick-entry a:nth-of-type(5){
  106. grid-area: img5;
  107. }
  108. .public-second-hand >.quick-entry a:last-of-type{
  109. grid-area: img6;
  110. }
  111. .public-second-hand >.quick-entry a:nth-of-type(5) img,.public-second-hand >.quick-entry a:last-of-type img{
  112. width: 393px;
  113. height: 60px;
  114. }

手写grid.md课堂文档

总结

写代码不管是前端还是后端,走出动手的第一步才行。起初一直怕写不出来,躲避不去动手写。当写了后才发现,真的没那么难。结构分析,有了思路,能够更快的写出网站dom结构。

简单的文字链接直接用a标签,纯文本推荐span标签。标签gird布局虽然不错,但是在处理细节部分真赶不上flex布局好用。flex和gird相配合,能够更快的实现效果。需要注意的是,放在同一个网格中的每个项目必须是同级关系才能放进去。

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:其实前面的二个title并不适合用grid的, 用flex会更好, 为什么呢? 因为下面的图文应该是从数据表中读出一条记录, 如果把他们封装到一个容器中, 利于写模板数据循环, 而不要把title包括进去
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