博客列表 >Grid布局实践二手商城(12月28日)

Grid布局实践二手商城(12月28日)

孤心泪的博客
孤心泪的博客原创
2020年01月02日 15:14:07551浏览

1 分析布局


简单划分布局区域如上图(使用grid布局的主要为商品列表和快速入口部分)

2 html和css代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>grid版二手商城</title>
  6. <link rel="stylesheet" href="grid_second_hand.css">
  7. </head>
  8. <body>
  9. <!--二手交易专区-->
  10. <div class="public-second-hand">
  11. <!--标题1-->
  12. <div class="title1">
  13. <a href="">抢好货</a>
  14. <span>低价,便捷,安全,快速</span>
  15. </div>
  16. <!--标题2-->
  17. <div class="title2">
  18. <span>热门分类</span>
  19. <a href="">美女写真</a>
  20. <a href="">日本美女</a>
  21. <a href="">美国美女</a>
  22. <a href="">国内美女</a>
  23. <a href="">AV美女</a>
  24. </div>
  25. <!--商品展示区-->
  26. <div class="goods">
  27. <!--分为左右两个格子-->
  28. <!--1.左边商品列表-->
  29. <div class="goods-list">
  30. <!--商品简介-->
  31. <div class="intro">
  32. <a href=""><img src="../../image/shop/shop1.jpg" alt=""></a>
  33. <p>美女性感写真海报图片美女性感写真海报图</p>
  34. <div>
  35. <span>&yen;666</span>
  36. <span>美女</span>
  37. </div>
  38. </div>
  39. <div class="intro">
  40. <a href=""><img src="../../image/shop/shop1.jpg" alt=""></a>
  41. <p>美女性感写真海报图片美女性感写真海报图</p>
  42. <div>
  43. <span>&yen;666</span>
  44. <span>美女</span>
  45. </div>
  46. </div>
  47. <div class="intro">
  48. <a href=""><img src="../../image/shop/shop1.jpg" alt=""></a>
  49. <p>美女性感写真海报图片美女性感写真海报图</p>
  50. <div>
  51. <span>&yen;666</span>
  52. <span>美女</span>
  53. </div>
  54. </div>
  55. <div class="intro">
  56. <a href=""><img src="../../image/shop/shop1.jpg" alt=""></a>
  57. <p>美女性感写真海报图片美女性感写真海报图</p>
  58. <div>
  59. <span>&yen;666</span>
  60. <span>美女</span>
  61. </div>
  62. </div>
  63. <div class="intro">
  64. <a href=""><img src="../../image/shop/shop1.jpg" alt=""></a>
  65. <p>美女性感写真海报图片美女性感写真海报图</p>
  66. <div>
  67. <span>&yen;666</span>
  68. <span>美女</span>
  69. </div>
  70. </div>
  71. <div class="intro">
  72. <a href=""><img src="../../image/shop/shop1.jpg" alt=""></a>
  73. <p>美女性感写真海报图片美女性感写真海报图</p>
  74. <div>
  75. <span>&yen;666</span>
  76. <span>美女</span>
  77. </div>
  78. </div>
  79. <div class="intro">
  80. <a href=""><img src="../../image/shop/shop1.jpg" alt=""></a>
  81. <p>美女性感写真海报图片美女性感写真海报图</p>
  82. <div>
  83. <span>&yen;666</span>
  84. <span>美女</span>
  85. </div>
  86. </div>
  87. <div class="intro">
  88. <a href=""><img src="../../image/shop/shop1.jpg" alt=""></a>
  89. <p>美女性感写真海报图片美女性感写真海报图</p>
  90. <div>
  91. <span>&yen;666</span>
  92. <span>美女</span>
  93. </div>
  94. </div>
  95. </div>
  96. <!--2.右边的功能是快速入口-->
  97. <div class="quick-entry">
  98. <a href=""><img src="../../image/ad/1.png" alt=""></a>
  99. <a href=""><img src="../../image/ad/2.png" alt=""></a>
  100. <a href=""><img src="../../image/ad/3.png" alt=""></a>
  101. <a href=""><img src="../../image/ad/4.png" alt=""></a>
  102. <div>
  103. <a href=""><img src="../../image/ad/image.png" alt=""></a>
  104. <a href=""><img src="../../image/ad/ad2.jpg" alt=""></a>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </body>
  110. </html>

css

  1. /*引入重置样式*/
  2. @import "../reset.css";
  3. *:not(body){
  4. outline: 1px dashed red;
  5. }
  6. /*二手交易专区的样式表*/
  7. .public-second-hand {
  8. width: 1200px;
  9. padding: 10px;
  10. box-sizing: border-box;
  11. margin: auto;
  12. border-radius: 5px;
  13. background-color: #fff;
  14. }
  15. .public-second-hand:hover {
  16. box-shadow: 0 0 8px #888;
  17. }
  18. /*标题1*/
  19. .public-second-hand > .title1 {
  20. height: 50px;
  21. border-bottom: 1px solid #ccc;
  22. box-sizing: border-box;
  23. }
  24. .public-second-hand > .title1 >a{
  25. font-size: 23px;
  26. margin-right: 20px;
  27. }
  28. .public-second-hand > .title1 >span{
  29. color: red;
  30. }
  31. /*标题2*/
  32. .public-second-hand > .title2 {
  33. height: 55px;
  34. }
  35. .public-second-hand > .title2 >span {
  36. color: red;
  37. font-size: 23px;
  38. }
  39. .public-second-hand > .title2 >span ~a{
  40. padding-left: 20px;
  41. }
  42. .public-second-hand > .title2 >span ~a:hover{
  43. color: lightblue;
  44. }
  45. .goods{
  46. display: grid;
  47. grid-template-columns: 760px 1fr;
  48. }
  49. .goods-list {
  50. padding: 10px;
  51. box-sizing: border-box;
  52. display: grid;
  53. grid-template-columns:repeat(4,178px) ;
  54. grid-template-rows: repeat(2,200px);
  55. grid-column-gap: 10px;
  56. grid-row-gap: 10px;
  57. justify-content: space-between;
  58. }
  59. .goods-list > .intro {
  60. display: flex;
  61. flex-direction: column;
  62. justify-content: space-between;
  63. border-radius: 8px;
  64. }
  65. .public-second-hand>.goods>.goods-list>.intro span:first-of-type{
  66. color: red;
  67. }
  68. .public-second-hand > .goods > .goods-list > .intro>div{
  69. display: flex;
  70. justify-content: space-between;
  71. }
  72. /*商品图片*/
  73. .public-second-hand > .goods > .goods-list > .intro img {
  74. border: 1px solid #cccccc;
  75. border-radius: 5px;
  76. width: 176px;
  77. height: 120px;
  78. display: block;
  79. }
  80. /* 右侧快速入口*/
  81. .public-second-hand>.goods>.quick-entry{
  82. padding: 10px;
  83. box-sizing: border-box;
  84. display: grid;
  85. grid-template-columns:repeat(2,190px);
  86. grid-template-rows:repeat(2,130px) 136px ;
  87. grid-column-gap: 20px;
  88. grid-row-gap: 10px;
  89. justify-content: space-between;
  90. }
  91. .public-second-hand>.goods>.quick-entry>a> img{
  92. width: 190px;
  93. height: 130px;
  94. border-radius: 8px;
  95. }
  96. .public-second-hand>.goods>.quick-entry>div>a>img{
  97. width: 393px;
  98. height: 60px;
  99. display: block;
  100. }

总结

1.对grid布局还不够熟练,细致的地方掌握不到位,需要加强联系
2.对于复杂的结构,使用grid布局时划分不够清晰

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议