Blogger Information
Blog 7
fans 0
comment 0
visits 4729
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Grid布局实现二手商品交易组件-20191228作业
涡流
Original
642 people have browsed it

html代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <!--引入阿里字体图标库的css-->
  6. <link rel="stylesheet" href="../iconfont/iconfont.css">
  7. <link rel="stylesheet" href="second-hand.css">
  8. <title>二手商品交易</title>
  9. </head>
  10. <body>
  11. <!-- 页眉 -->
  12. <header>
  13. <a href="">抢好货</a>
  14. <span>0低价,便捷,安全,快速</span>
  15. </header>
  16. <!-- 导航 -->
  17. <nav>
  18. <span>热门分类</span>
  19. <a href="">家用电器</a>
  20. <a href="">日常百货</a>
  21. <a href="">运动器械</a>
  22. <a href="">户外装备</a>
  23. </nav>
  24. <!-- 主要内容 -->
  25. <main>
  26. <!-- 左边区域,这里采用grid布局 -->
  27. <div class="left">
  28. <div class="detail">
  29. <img src="img/shop6.jpg" alt="">
  30. <span>grid-template-colums:基于列定义网络线的名与与轨道大小</span>
  31. <div class="summary">
  32. <span>$ 333</span>
  33. <span>电器</span>
  34. </div>
  35. </div>
  36. <div class="detail">
  37. <img src="img/shop6.jpg" alt="">
  38. <span>grid-template-rows:基于行定义网络线的名与与轨道大小</span>
  39. <div class="summary">
  40. <span>$ 333</span>
  41. <span>电器</span>
  42. </div>
  43. </div>
  44. <div class="detail">
  45. <img src="img/shop6.jpg" alt="">
  46. <span>grid-template-colums:基于列定义网络线的名与与轨道大小</span>
  47. <div class="summary">
  48. <span>$ 333</span>
  49. <span>电器</span>
  50. </div>
  51. </div>
  52. <div class="detail">
  53. <img src="img/shop6.jpg" alt="">
  54. <span>grid-template-rows:基于行定义网络线的名与与轨道大小</span>
  55. <div class="summary">
  56. <span>$ 333</span>
  57. <span>电器</span>
  58. </div>
  59. </div>
  60. <div class="detail">
  61. <img src="img/shop6.jpg" alt="">
  62. <span>grid-template-colums:基于列定义网络线的名与与轨道大小</span>
  63. <div class="summary">
  64. <span>$ 333</span>
  65. <span>电器</span>
  66. </div>
  67. </div>
  68. <div class="detail">
  69. <img src="img/shop6.jpg" alt="">
  70. <span>grid-template-rows:基于行定义网络线的名与与轨道大小</span>
  71. <div class="summary">
  72. <span>$ 333</span>
  73. <span>电器</span>
  74. </div>
  75. </div>
  76. <div class="detail">
  77. <img src="img/shop6.jpg" alt="">
  78. <span>grid-template-colums:基于列定义网络线的名与与轨道大小</span>
  79. <div class="summary">
  80. <span>$ 333</span>
  81. <span>电器</span>
  82. </div>
  83. </div>
  84. <div class="detail">
  85. <img src="img/shop6.jpg" alt="">
  86. <span>grid-template-rows:基于行定义网络线的名与与轨道大小</span>
  87. <div class="summary">
  88. <span>$ 333</span>
  89. <span>电器</span>
  90. </div>
  91. </div>
  92. </div>
  93. <!-- 右边区域,6张图片,grid布局 -->
  94. <div class="right">
  95. <img src="img/1.png" alt="">
  96. <img src="img/2.png" alt="">
  97. <img src="img/3.png" alt="">
  98. <img src="img/4.png" alt="">
  99. <img src="img/image.png" alt="">
  100. <img src="img/ad2.jpg" alt="">
  101. </div>
  102. </main>
  103. </body>
  104. </html>

css代码

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. /* outline: 1px solid green; */
  5. font-size: 13px;
  6. }
  7. a {
  8. text-decoration: none;
  9. }
  10. /* 图片宽度设定占用父容的宽度 */
  11. img {
  12. width: 100%;
  13. }
  14. body {
  15. width: 1200px;
  16. margin: 0 auto;
  17. }
  18. header {
  19. padding: 10px;
  20. border-bottom: 1px solid grey;
  21. }
  22. header > a {
  23. font-size: 23px;
  24. }
  25. header > span {
  26. margin: 15px;
  27. color: red;
  28. }
  29. nav {
  30. padding: 10px;
  31. margin-bottom: 10px;
  32. }
  33. nav > span {
  34. font-size: 23px;
  35. color: red;
  36. }
  37. nav > a {
  38. margin-left: 10px;
  39. }
  40. /* 主体区域,网格,左宽2fr,右宽1fr */
  41. main {
  42. display: grid;
  43. grid-template-columns: 2fr 1fr;
  44. grid-gap: 10px;
  45. }
  46. /* 左:4列2行等分 */
  47. main > .left {
  48. /* width: 800px; */
  49. display: grid;
  50. grid-template-columns: repeat(4,1fr);
  51. grid-template-rows: repeat(2, 1fr);
  52. grid-gap: 10px;
  53. }
  54. /* 单元格采用grid布局,1列3行,行高自动 */
  55. main > .left > .detail {
  56. display: grid;
  57. /* grid-template-rows: repeat(3, auto); */
  58. grid-gap: 10px;
  59. }
  60. /* 图片宽设定100%比像素更好 */
  61. main > .left > .detail > img {
  62. /* width: 100%; */
  63. border-radius: 5px;
  64. }
  65. /* 价格所在行设定为FLEX,便于设置样式:两端对齐 */
  66. main > .left > .detail > .summary {
  67. display: flex;
  68. justify-content: space-between;
  69. }
  70. main > .left > .detail > .summary > span:first-of-type {
  71. color: red;
  72. }
  73. main > .left > .detail > .summary > span:last-of-type {
  74. padding: 0 5px;
  75. background-color: green;
  76. border-radius: 3px;
  77. }
  78. main > .left > .detail > .summary > span:last-of-type:hover {
  79. background-color: blue;
  80. cursor: pointer;
  81. color: white;
  82. }
  83. /* 右:2列4行,行高自动,第3、4行各独占一行 */
  84. main > .right {
  85. display: grid;
  86. grid-template-columns: repeat(2, 1fr);
  87. grid-template-rows: repeat(4, auto);
  88. /* grid-template-areas: "ad1 ad2" "ad3 ad4" "ad5 ad5" "ad6 ad6"; */
  89. grid-gap: 10px;
  90. }
  91. main > .right > img:nth-child(5) {
  92. grid-column: 1 / -1;
  93. }
  94. main > .right > img:nth-child(6) {
  95. grid-column: 1 / -1;
  96. }

抄写:

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!