博客列表 >2020-01-01 购物车界面 PHP培训十期

2020-01-01 购物车界面 PHP培训十期

ys899
ys899原创
2020年01月06日 10:06:54624浏览

页面DOM结构

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <link rel="stylesheet" href="shop_shopping_cart.css">
  6. <title>商城系统的购物车</title>
  7. </head>
  8. <body>
  9. <!--商城购物车-->
  10. <div class="shop-shopping-cart">
  11. <h3>我的购物车</h3>
  12. <!--购物车头部-->
  13. <header>
  14. <!--flex-->
  15. <span>
  16. <input type="checkbox" id="all-selected" checked>
  17. <label for="all-selected">全选</label>
  18. </span>
  19. <span>商品</span>
  20. <span>单价</span>
  21. <span>数量</span>
  22. <span>小计</span>
  23. <span>操作</span>
  24. </header>
  25. <!--购物车主体-->
  26. <main>
  27. <div>
  28. <span>
  29. <label><input type="checkbox" name="choose" checked></label>
  30. </span>
  31. <!--图文介绍-->
  32. <span class="pic-intro">
  33. <a href=""><img src="../../../static/images/shop/shop1.jpg" alt=""></a>
  34. <a href="">商品简介...</a>
  35. </span>
  36. <span>500.00</span>
  37. <span>
  38. <label><input type="number" name="count" value="1" min="1"></label>
  39. </span>
  40. <span><i>¥</i>500.00</span>
  41. <span><a href="">删除</a></span>
  42. </div>
  43. <div>
  44. <span>
  45. <label><input type="checkbox" name="choose" checked></label>
  46. </span>
  47. <!--图文介绍-->
  48. <span class="pic-intro">
  49. <a href=""><img src="../../../static/images/shop/shop2.jpg" alt=""></a>
  50. <a href="">商品简介...</a>
  51. </span>
  52. <span>500.00</span>
  53. <span>
  54. <label><input type="number" name="count" value="1" min="1"></label>
  55. </span>
  56. <span><i>¥</i>500.00</span>
  57. <span><a href="">删除</a></span>
  58. </div>
  59. <div>
  60. <span>
  61. <label><input type="checkbox" name="choose" checked></label>
  62. </span>
  63. <!--图文介绍-->
  64. <span class="pic-intro">
  65. <a href=""><img src="../../../static/images/shop/shop3.jpg" alt=""></a>
  66. <a href="">商品简介...</a>
  67. </span>
  68. <span>500.00</span>
  69. <span>
  70. <label><input type="number" name="count" value="1" min="1"></label>
  71. </span>
  72. <span><i>¥</i>500.00</span>
  73. <span><a href="">删除</a></span>
  74. </div>
  75. <div>
  76. <span>
  77. <label><input type="checkbox" name="choose" checked></label>
  78. </span>
  79. <!--图文介绍-->
  80. <span class="pic-intro">
  81. <a href=""><img src="../../../static/images/shop/shop4.jpg" alt=""></a>
  82. <a href="">商品简介...</a>
  83. </span>
  84. <span>500.00</span>
  85. <span>
  86. <label><input type="number" name="count" value="1" min="1"></label>
  87. </span>
  88. <span><i>¥</i>500.00</span>
  89. <span><a href="">删除</a></span>
  90. </div>
  91. </main>
  92. <!--购物车底部-->
  93. <footer>
  94. <span>数量: <i>4</i></span>
  95. <span>金额: <i>2000</i></span>
  96. <button>去结算</button>
  97. </footer>
  98. </div>
  99. </body>
  100. </html>

全局CSS Code

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. /*参考线 */
  5. /* outline: 1px dashed red;*/
  6. }
  7. body {
  8. font-size: 13px;
  9. color: #555555;
  10. background-color: #efefef;
  11. }
  12. a {
  13. color: #404040;
  14. text-decoration: none;
  15. font-size: 13px;
  16. }
  17. li {
  18. list-style: none;
  19. }

购物车CSS

  1. @import url(../../public_reset.css);
  2. .shop-shopping-cart {
  3. width: 1200px;
  4. background-color: #fff;
  5. margin: 30px auto;
  6. padding: 15px 0;
  7. `border-radius`: 8px;
  8. `box-sizing`: border-box;
  9. }
  10. .shop-shopping-cart:hover {
  11. `box-shadow`: 0 0 8px #888888;
  12. }
  13. /*标题*/
  14. .shop-shopping-cart > h3 {
  15. font-size: 20px;
  16. text-align: center;
  17. font-weight: normal;
  18. margin-bottom: 20px;
  19. }
  20. /*购物车头部*/
  21. .shop-shopping-cart > header {
  22. height: 40px;
  23. border-bottom: 1px solid #cccccc;
  24. /*flex*/
  25. `display`: flex;
  26. `justify-content`: space-around;
  27. `align-items`: center;
  28. }
  29. /*购物车主体*/
  30. .shop-shopping-cart > main {
  31. margin: 20px 0;
  32. }
  33. /*购物车中的每一条记录, 每一个商品*/
  34. .shop-shopping-cart > main > div {
  35. height: 80px;
  36. /*flex*/
  37. display: flex;
  38. `justify-content`: space-around;
  39. `align-items`: center;
  40. }
  41. .shop-shopping-cart > main > div:hover {
  42. background-color: lightcyan;
  43. }
  44. .shop-shopping-cart > main > div .pic-intro {
  45. width: 250px;
  46. `display`: flex;
  47. `align-items`: center;
  48. }
  49. .shop-shopping-cart > main > div .pic-intro img {
  50. width: 60px;
  51. height: 45px;
  52. margin-right: 10px;
  53. }
  54. .shop-shopping-cart > main > div a:hover {
  55. color: lightcoral;
  56. }
  57. /*微调第一个复选框*/
  58. .shop-shopping-cart > main > div > span:first-of-type {
  59. position: relative;
  60. left: 25px;
  61. }
  62. .shop-shopping-cart > main > div > span.pic-intro {
  63. position: relative;
  64. left: -40px;
  65. }
  66. .shop-shopping-cart > main > div > span:nth-of-type(3) {
  67. position: relative;
  68. left: -80px;
  69. }
  70. .shop-shopping-cart > main > div > span:nth-of-type(4) {
  71. position: relative;
  72. left: -60px;
  73. }
  74. .shop-shopping-cart > main > div > span:nth-of-type(4) input {
  75. width: 60px;
  76. }
  77. .shop-shopping-cart > main > div > span:nth-last-of-type(2) {
  78. position: relative;
  79. left: -50px;
  80. }
  81. .shop-shopping-cart > main > div > span:last-of-type {
  82. position: relative;
  83. left: -50px;
  84. }
  85. .shop-shopping-cart > main > div > span:nth-last-of-type(2) i {
  86. color: green;
  87. font-size: 1.01rem;
  88. margin-right: 3px;
  89. }
  90. /*购物车底部*/
  91. .shop-shopping-cart > footer {
  92. height: 70px;
  93. padding: 20px;
  94. border-top: 1px solid #cccccc;
  95. box-sizing: border-box;
  96. display: flex;
  97. justify-content: flex-end;
  98. align-items: center;
  99. }
  100. .shop-shopping-cart > footer > *:not(:last-child) {
  101. width: 180px;
  102. }
  103. .shop-shopping-cart > footer > button {
  104. height: 40px;
  105. width: 120px;
  106. background-color: lightcoral;
  107. border: none;
  108. color: white;
  109. font-size: 1.1rem;
  110. }
  111. .shop-shopping-cart > footer > button:hover {
  112. background-color: seagreen;
  113. cursor: pointer;
  114. }

效果图

心得体会

购物车商品在页面上单行多列显示,适合flex的默认排列布局,由于商品的属性比较多,css细节控制需要耐心去微调,才能达到很好的显示效果。

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