博客列表 >用表格制做购物车列表和表单实现用户注册页

用表格制做购物车列表和表单实现用户注册页

知行合一
知行合一原创
2020年06月23日 10:50:301080浏览

今天我们讲解两个知识点。用表格制做购物车列表和表单实现用户注册页。我们仍然用代码和效果图来进行展示。

表格实现购物车列表

表格实现购物车列表

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>购物车-表格</title>
  7. <style>
  8. caption {
  9. margin-bottom: 20px;
  10. color: darkred;
  11. font-size: 20px;
  12. font-weight: bold;
  13. }
  14. table {
  15. width: 70%;
  16. margin: 0 auto;
  17. border-collapse: collapse;
  18. }
  19. table td,
  20. table th {
  21. border: 1px solid rgb(241, 237, 237);
  22. padding: 10px;
  23. text-align: center;
  24. }
  25. thead tr {
  26. background-color: coral;
  27. }
  28. tbody tr:nth-child(even) {
  29. background-color: darkcyan;
  30. color: white;
  31. }
  32. tbody tr:hover {
  33. background-color: yellow;
  34. }
  35. tbody tr:nth-child(even):hover {
  36. color: black;
  37. }
  38. div {
  39. width: 70%;
  40. margin: 20px auto 0;
  41. }
  42. div button {
  43. width: 150px;
  44. height: 40px;
  45. border: none;
  46. background-color: cadetblue;
  47. float: right;
  48. color: white;
  49. }
  50. div button:hover {
  51. background-color: violet;
  52. }
  53. </style>
  54. </head>
  55. <body>
  56. <table>
  57. <caption>
  58. 购物车
  59. </caption>
  60. <colgroup></colgroup>
  61. <thead>
  62. <tr>
  63. <th>编号</th>
  64. <th>名称</th>
  65. <th>单价</th>
  66. <th>数量</th>
  67. <th>金额</th>
  68. </tr>
  69. </thead>
  70. <tbody>
  71. <tr>
  72. <td>001</td>
  73. <td>苹果</td>
  74. <td>2.0</td>
  75. <td>5</td>
  76. <td>10</td>
  77. </tr>
  78. <tr>
  79. <td>002</td>
  80. <td>西瓜</td>
  81. <td>3.0</td>
  82. <td>10</td>
  83. <td>30</td>
  84. </tr>
  85. <tr>
  86. <td>003</td>
  87. <td>橘子</td>
  88. <td>5.0</td>
  89. <td>4</td>
  90. <td>20</td>
  91. </tr>
  92. <tr>
  93. <td>004</td>
  94. <td>芒果</td>
  95. <td>3.0</td>
  96. <td>5</td>
  97. <td>15</td>
  98. </tr>
  99. <tr>
  100. <td>005</td>
  101. <td>葡萄</td>
  102. <td>4.0</td>
  103. <td>10</td>
  104. <td>40</td>
  105. </tr>
  106. <tr>
  107. <td>006</td>
  108. <td>荔枝</td>
  109. <td>10.0</td>
  110. <td>10</td>
  111. <td>40</td>
  112. </tr>
  113. <tr>
  114. <td>007</td>
  115. <td>草莓</td>
  116. <td>4.0</td>
  117. <td>10</td>
  118. <td>40</td>
  119. </tr>
  120. </tbody>
  121. <tfoot>
  122. <tr>
  123. <td colspan="3">总计</td>
  124. <td>16</td>
  125. <td>120元</td>
  126. </tr>
  127. </tfoot>
  128. </table>
  129. <div><button>立即结算</button></div>
  130. </body>
  131. </html>

用户注册表单

用户注册表单

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>表单</title>
  7. <style>
  8. fieldset {
  9. border: rgb(216, 159, 2) 1px solid;
  10. padding: 15px 15px;
  11. width: 50%;
  12. margin: 0 auto;
  13. margin-bottom: 30px;
  14. }
  15. legend {
  16. padding: 5px;
  17. background-color: tomato;
  18. color: white;
  19. }
  20. fieldset div {
  21. margin-bottom: 10px;
  22. }
  23. textarea {
  24. width: 300px;
  25. }
  26. .btn {
  27. width: 50%;
  28. margin: 20px auto;
  29. text-align: center;
  30. }
  31. button {
  32. width: 150px;
  33. height: 35px;
  34. line-height: 35px;
  35. color: white;
  36. background-color: tomato;
  37. border: none;
  38. cursor: pointer;
  39. }
  40. button:hover {
  41. background-color: teal;
  42. }
  43. </style>
  44. </head>
  45. <body>
  46. <form method="POST" action="">
  47. <div>
  48. <fieldset>
  49. <legend>基本信息</legend>
  50. <div>
  51. <label for="username">帐号:</label>
  52. <input name="username" id="username" type="text" placeholder="6-12位字符" required autofocus>
  53. </div>
  54. <div>
  55. <label for="email">邮箱:</label>
  56. <input name="email" id="email" type="email" placeholder="demo@demo.com" required>
  57. </div>
  58. <div>
  59. <label for="pwd1">密码:</label>
  60. <input name="pwd1" id="pwd1" type="password" placeholder="不少于6位且必须子母加数字" required>
  61. </div>
  62. <div>
  63. <label for="pwd2">确认密码:</label>
  64. <input name="pwd2" id="pwd2" type="password" required>
  65. </div>
  66. </fieldset>
  67. <fieldset>
  68. <legend>扩展信息</legend>
  69. <div>
  70. <label>生日:
  71. <input name="birthda" type="date" required></label>
  72. <!--label中不写for,可以将表单元素放在label中,也可实现点击Label文字,表单获取焦点-->
  73. </div>
  74. <div>
  75. <label for="secret">性别:</label>
  76. <input type="checkbox" name="gender" id="male" value="male">
  77. <label for="male"></label>
  78. <input type="radio" name="gender" id="female" value="female">
  79. <label for="female"></label>
  80. <input type="radio" name="gender" id="secret" value="secret">
  81. <label for="secret">保密</label>
  82. </div>
  83. <div>
  84. <label for="game">爱好:</label>
  85. <input type="checkbox" name="hobby[]" id="sleep" value="sleep">
  86. <label for="sleep">睡觉</label>
  87. <input type="checkbox" name="hobby[]" id="book" value="book">
  88. <label for="book">看书</label>
  89. <input type="checkbox" name="hobby[]" id="game" value="game" checked>
  90. <label for="game">游戏</label>
  91. </div>
  92. <!--选项列表-->
  93. <div>
  94. <label for="brand">手机品牌:</label>
  95. <input type="search" list="phone" id="brand" name="brand">
  96. <!--上面的id和name不可与list的值一致-->
  97. <datalist id="phone">
  98. <!--id要和上面的List绑定,是一致的-->
  99. <option value="mi" label="小米"></option>
  100. <option value="apple" label="苹果"></option>
  101. <option value="huawei" label="华为"></option>
  102. </datalist>
  103. </div>
  104. </fieldset>
  105. <fieldset>
  106. <legend>其它信息</legend>
  107. <div><label for="pic">上传头像:</label><input type="file" name="pic" id="pic"
  108. accept="image/jpg,image/png,image/gif"></div>
  109. <div><label for="resume">简历:</label><textarea name="resume" rows="5" placeholder="不超过100字"
  110. id="resume"></textarea></div>
  111. </fieldset>
  112. <!--隐藏域-->
  113. <input type="hidden" name="userid" id="userid" value="111">
  114. <div class="btn"> <button>提交</button></div>
  115. </form>
  116. </body>
  117. </html>

此表单将常用的表单元素都应用上了,是一个很好的测试项目。

总结

HTML5的知识点很多,但是都不复杂,多学习,勤加练习就可掌握。只看不练,等于白搭。

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