Blogger Information
Blog 7
fans 0
comment 0
visits 4333
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Grid复写二手交易模块(1228)
建国
Original
568 people have browsed it

练习内容

使用grid布局重写二手交易模块样式

代码

html部分

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  6. <link rel="stylesheet" href="./style.css">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <div class="container">
  11. <div class="title">
  12. <a href="">抢好货</a>
  13. <span>0低价, 便捷,安全,快速</span>
  14. </div>
  15. <div class="nav">
  16. <span>热门分类</span>
  17. <div>
  18. <a href="">美女写真</a>
  19. <a href="">日本美女</a>
  20. <a href="">美国美女</a>
  21. <a href="">国内美女</a>
  22. <a href="">AV美女</a>
  23. </div>
  24. </div>
  25. <div class="goods-list">
  26. <div class="intro">
  27. <a href=""><img src="./static/images/shop/shop1.jpg" alt=""></a>
  28. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  29. <div>
  30. <span>&yen;333</span>
  31. <span>美女</span>
  32. </div>
  33. </div>
  34. <div class="intro">
  35. <a href=""><img src="./static/images/shop/shop1.jpg" alt=""></a>
  36. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  37. <div>
  38. <span>&yen;333</span>
  39. <span>美女</span>
  40. </div>
  41. </div>
  42. <div class="intro">
  43. <a href=""><img src="./static/images/shop/shop1.jpg" alt=""></a>
  44. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  45. <div>
  46. <span>&yen;333</span>
  47. <span>美女</span>
  48. </div>
  49. </div>
  50. <div class="intro">
  51. <a href=""><img src="./static/images/shop/shop1.jpg" alt=""></a>
  52. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  53. <div>
  54. <span>&yen;333</span>
  55. <span>美女</span>
  56. </div>
  57. </div>
  58. <div class="intro">
  59. <a href=""><img src="./static/images/shop/shop1.jpg" alt=""></a>
  60. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  61. <div>
  62. <span>&yen;333</span>
  63. <span>美女</span>
  64. </div>
  65. </div>
  66. <div class="intro">
  67. <a href=""><img src="./static/images/shop/shop1.jpg" alt=""></a>
  68. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  69. <div>
  70. <span>&yen;333</span>
  71. <span>美女</span>
  72. </div>
  73. </div>
  74. <div class="intro">
  75. <a href=""><img src="./static/images/shop/shop1.jpg" alt=""></a>
  76. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  77. <div>
  78. <span>&yen;333</span>
  79. <span>美女</span>
  80. </div>
  81. </div>
  82. <div class="intro">
  83. <a href=""><img src="./static/images/shop/shop1.jpg" alt=""></a>
  84. <a href="">美女性感写真海报墙艺术装饰画贴画图1</a>
  85. <div>
  86. <span>&yen;333</span>
  87. <span>美女</span>
  88. </div>
  89. </div>
  90. </div>
  91. <div class="quick-entry">
  92. <a><img src="./static/images/ad/1.png" alt=""></a>
  93. <a><img src="./static/images/ad/2.png" alt=""></a>
  94. <a><img src="./static/images/ad/3.png" alt=""></a>
  95. <a><img src="./static/images/ad/4.png" alt=""></a>
  96. <img src="./static/images/ad/image.png" alt="">
  97. <img src="./static/images/ad/ad2.jpg" alt="">
  98. </div>
  99. </div>
  100. </body>
  101. </html>

css部分

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. }
  5. body {
  6. background-color: #efefef;
  7. }
  8. a {
  9. text-decoration: none;
  10. color: black;
  11. }
  12. .container {
  13. width: 1200px;
  14. margin: auto;
  15. display: grid;
  16. grid-template-columns: 2fr 1fr;
  17. grid-template-rows: repeat(2, 60px) 460px;
  18. background-color: #fff;
  19. border-radius: 10px;
  20. padding: 0 20px 20px 20px;
  21. grid-column-gap: 20px;
  22. box-sizing: border-box;
  23. }
  24. /* 顶部 */
  25. .container > .title {
  26. grid-column-start: span 2;
  27. display: flex;
  28. align-items: center;
  29. border-bottom: 1px solid gray;
  30. }
  31. .container > .title > a {
  32. font-size: 24px;
  33. font-weight: bold;
  34. }
  35. .container > .title > span {
  36. padding: 10px 0 0 10px;
  37. color: red;
  38. }
  39. /* 中部 */
  40. .container > .nav {
  41. grid-column-start: span 2;
  42. display: flex;
  43. align-items: center;
  44. }
  45. .container > .nav > span {
  46. font-size: 24px;
  47. color: red;
  48. font-weight: bold;
  49. }
  50. .container > .nav > div {
  51. display: flex;
  52. padding: 15px 0 0 20px;
  53. }
  54. .container > .nav > div > a {
  55. margin-right: 20px;
  56. font-size: 16px;
  57. }
  58. /* 列表区 */
  59. .container > .goods-list {
  60. display: grid;
  61. grid-template-columns: repeat(4, auto);
  62. grid-template-rows: repeat(2, auto);
  63. grid-gap: 20px;
  64. }
  65. /*单个商品*/
  66. .container > .goods-list > .intro {
  67. display: flex;
  68. flex-direction: column;
  69. align-items: center;
  70. justify-content: space-between;
  71. flex-shrink: 1;
  72. }
  73. /*商品图片*/
  74. .container > .goods-list > .intro > :first-child > img {
  75. width: 176px;
  76. height: 120px;
  77. border-radius: 5px;
  78. }
  79. .container > .goods-list > .intro > div {
  80. display: flex;
  81. width: 100%;
  82. justify-content: space-between;
  83. font-size: 14px;
  84. }
  85. .container > .goods-list > .intro > div > :first-child {
  86. color: red;
  87. }
  88. .container > .goods-list > .intro > div > :last-child {
  89. background-color: #55ce9f;
  90. padding: 0 3px;
  91. border-radius: 2px;
  92. color: white;
  93. }
  94. /* 右侧快速入口 */
  95. .container > .quick-entry {
  96. display: grid;
  97. grid-template-columns: repeat(2, 1fr);
  98. grid-template-rows: 130px 130px 60px 60px;
  99. justify-content: space-between;
  100. align-content: space-between;
  101. grid-gap: 20px;
  102. }
  103. .container > .quick-entry > a > img {
  104. width: 100%;
  105. height: 130px;
  106. }
  107. .container > .quick-entry > img {
  108. grid-column-start: span 2;
  109. width: 100%;
  110. }

总结

还是有太多不明白的地方,对grid的容器属性和项目属性不了解,导致浪费了很多时间,做好后返回来一看,其实挺简单的,关键是思路清晰,知道哪里需要什么样的布局,另外搭配flex使用效果会更好

效果图

手写grid容器属性与部分项目属性


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