博客列表 >用表格制作简单的购物车和用户注册页面-web前端第5章6.12

用表格制作简单的购物车和用户注册页面-web前端第5章6.12

希望
希望原创
2020年06月17日 17:55:51876浏览

1.用表格制作简单的购物车


  • 如图:分为三部分:头部,主体,底部。

购物车

  • 以下是整体代码:

    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. html {
    9. font-size: 14px;
    10. }
    11. table {
    12. /* 把单元格之间的间隙去除 */
    13. border-collapse: collapse;
    14. /* 父容器的70% */
    15. width: 70%;
    16. /* 居中 */
    17. margin: auto;
    18. color: #666;
    19. /* 字体变细 */
    20. font-weight: lighter;
    21. /* 表格内容全部居中 */
    22. text-align: center;
    23. }
    24. /* 表格线直接添加到单元格上面 */
    25. table thead th,
    26. table td {
    27. /* 只加下边框 */
    28. border-bottom: 1px solid #000;
    29. /* 表格中内容与边框的距离拉大些 */
    30. padding: 10px;
    31. }
    32. /* 标题样式 */
    33. table caption {
    34. /* html的字体为参照 */
    35. font-size: 1.5rem;
    36. margin-bottom: 15px;
    37. /* 设置购物车这几个字的样式 */
    38. color: orange;
    39. }
    40. table th {
    41. /* id栏设置样式 */
    42. font-weight: lighter;
    43. color: hotpink;
    44. }
    45. /* id栏的背景色 */
    46. table thead {
    47. background-color: papayawhip;
    48. }
    49. /* 隔行变色 */
    50. table tbody tr:nth-of-type(even) {
    51. background-color: #efef;
    52. }
    53. /* 鼠标悬停时背景色 */
    54. table tbody tr:hover {
    55. background-color: skyblue;
    56. }
    57. /* 底部样式 */
    58. table tfoot td {
    59. /* 底部边框去掉 */
    60. border-bottom: none;
    61. color: tomato;
    62. font-size: 1.2rem;
    63. font-weight: bolder;
    64. }
    65. /* 结算样式 */
    66. body div:last-of-type {
    67. width: 70%;
    68. margin: 10px auto;
    69. }
    70. /* 结算按钮 */
    71. body div:first-of-type button {
    72. float: right;
    73. width: 120px;
    74. height: 34px;
    75. background-color: teal;
    76. color: white;
    77. border: none;
    78. /* 鼠标样式 变成手*/
    79. cursor: pointer;
    80. }
    81. /* 结算移入时效果 */
    82. body div:first-of-type button:hover {
    83. background-color: thistle;
    84. font-size: 1.1rem;
    85. }
    86. </style>
    87. </head>
    88. <body>
    89. <!-- 表格 -->
    90. <table>
    91. <!-- 标题 -->
    92. <caption>
    93. 购物车
    94. </caption>
    95. <!-- 头部 -->
    96. <thead>
    97. <tr>
    98. <th>ID</th>
    99. <th>品名</th>
    100. <th>单价/元</th>
    101. <th>单位</th>
    102. <th>数量</th>
    103. <th>金额/元</th>
    104. </tr>
    105. </thead>
    106. <!-- 主体 -->
    107. <tbody>
    108. <tr>
    109. <td>SN-1010</td>
    110. <td>MacBook Pro电脑</td>
    111. <td>18999</td>
    112. <td></td>
    113. <td>1</td>
    114. <td>18999</td>
    115. </tr>
    116. <tr>
    117. <td>SN-1020</td>
    118. <td>iPhone手机</td>
    119. <td>4999</td>
    120. <td></td>
    121. <td>2</td>
    122. <td>9998</td>
    123. </tr>
    124. <tr>
    125. <td>SN-1030</td>
    126. <td>智能AI音箱</td>
    127. <td>399</td>
    128. <td></td>
    129. <td>5</td>
    130. <td>1995</td>
    131. </tr>
    132. <tr>
    133. <td>SN-1040</td>
    134. <td>SSD移动硬盘</td>
    135. <td>888</td>
    136. <td></td>
    137. <td>2</td>
    138. <td>1776</td>
    139. </tr>
    140. <tr>
    141. <td>SN-1050</td>
    142. <td>黄山毛峰</td>
    143. <td>999</td>
    144. <td></td>
    145. <td>3</td>
    146. <td>2997</td>
    147. </tr>
    148. </tbody>
    149. <!-- 底部 -->
    150. <tfoot>
    151. <!-- 总计合并 -->
    152. <tr>
    153. <td colspan="4">总计:</td>
    154. <td>13</td>
    155. <td>35765</td>
    156. </tr>
    157. </tfoot>
    158. </table>
    159. <!-- 结算按钮 -->
    160. <div>
    161. <button>结算</button>
    162. </div>
    163. </body>
    164. </html>

2.用表格制作用户注册页面

  • 如图:了解表单的基本元素,注意点,样式

用户注册页面

  • 代码如下:

    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. /* 用户注册颜色灰一点并居中 */
    9. body {
    10. color: #555;
    11. }
    12. h3 {
    13. text-align: center;
    14. }
    15. form {
    16. width: 450px;
    17. margin: 30px auto;
    18. border-top: 1px solid #aaa;
    19. }
    20. /* 表的背景上色,椭圆角 */
    21. form fieldset {
    22. border: 1px solid seagreen;
    23. background-color: lightcyan;
    24. box-shadow: 2px 2px 4px #bbb;
    25. border-radius: 10px;
    26. margin: 20px;
    27. }
    28. /* 表头组件颜色,椭圆角 */
    29. form fieldset legend {
    30. background-color: rgb(178, 231, 201);
    31. border-radius: 10px;
    32. color: seagreen;
    33. padding: 5px 15px;
    34. }
    35. form div {
    36. margin: 5px;
    37. }
    38. /* 表格输入时底部颜色 */
    39. input:focus {
    40. background-color: darkgrey;
    41. }
    42. body p:first-of-type button {
    43. float: right;
    44. width: 120px;
    45. height: 34px;
    46. background-color: teal;
    47. color: white;
    48. border: none;
    49. /* 鼠标样式 变成手*/
    50. cursor: pointer;
    51. }
    52. /* 结算移入时效果 */
    53. body p:first-of-type button:hover {
    54. background-color: thistle;
    55. font-size: 1.1rem;
    56. }
    57. </style>
    58. </head>
    59. <body>
    60. <h3>用户注册</h3>
    61. <form action="" method="POST">
    62. <!-- 1.控件组 -->
    63. <fieldset>
    64. <legend>基本信息(必填)</legend>
    65. <div>
    66. <label for="username1">账号:</label>
    67. <input
    68. type="text"
    69. id="username1"
    70. name="username"
    71. placeholder="6-15个字符"
    72. autofocus
    73. required
    74. />
    75. </div>
    76. <div>
    77. <label for="email-id">邮箱:</label>
    78. <input
    79. type="email"
    80. name="email"
    81. id="email-id"
    82. placeholder="demo@example.com"
    83. required
    84. />
    85. </div>
    86. <!-- 密码 -->
    87. <div>
    88. <label for="pwd-1">密码:</label>
    89. <input
    90. type="password"
    91. name="password1"
    92. id="pwd-1"
    93. placeholder="不少于6位且字母+数字"
    94. />
    95. <button onclick="showPwd()" id="btn" type="button">显示密码</button>
    96. </div>
    97. <div>
    98. <label for="pwd-2">确认:</label>
    99. <input type="password" name="password2" id="pwd-2" />
    100. </div>
    101. </fieldset>
    102. <!-- <button>提交</button> -->
    103. <script>
    104. function showPwd(ele) {
    105. document.querySelector("#pwd-1").type = "text";
    106. }
    107. </script>
    108. <fieldset>
    109. <legend>扩展信息(选填)</legend>
    110. <div>
    111. <label for="birthday"
    112. >生日
    113. <input type="date" name="birthday" />
    114. </label>
    115. </div>
    116. <div>
    117. <!-- 单选按钮 :性别-->
    118. <label for="secret">性别</label>
    119. <input type="radio" name="gender" value="male" id="" />
    120. <label for=""></label>
    121. <input type="radio" name="gender" value="famale" id="" />
    122. <label for=""></label>
    123. <input type="radio" name="gender" value="secret" id="" checked />
    124. <label for="">保密</label>
    125. </div>
    126. <div>
    127. <!-- 复选框 -->
    128. <label for="">爱好</label>
    129. <input type="checkbox" name="hobby[]" id="game" value="game" />
    130. <label for="game">打游戏</label>
    131. <input
    132. type="checkbox"
    133. name="hobby[]"
    134. value="shoot"
    135. id="shoot"
    136. /><label for="shoot">摄影</label>
    137. <input
    138. type="checkbox"
    139. name="hobby[]"
    140. value="programme"
    141. id="programme"
    142. checked
    143. /><label for="programme">编程</label>
    144. </div>
    145. <!-- 选项列表 -->
    146. <div>
    147. <label for="brand">手机:</label>
    148. <input type="search" list="phone" name="brand" id="brand" />
    149. <datalist id="phone">
    150. <option value="apple"></option>
    151. <option value="huawei"></option>
    152. <option value="mi" label="小米"></option>
    153. </datalist>
    154. </div>
    155. </fieldset>
    156. <fieldset>
    157. <legend>其它信息(选填)</legend>
    158. <!--文件上传 ,用file上传文件-->
    159. <div>
    160. <label for="uploads">上传头像:</label>
    161. <input
    162. type="file"
    163. name="user_pic"
    164. id="uploads"
    165. accept="image/png, image/jpeg, image/gif"
    166. />
    167. </div>
    168. <!--文本域-->
    169. <div>
    170. <label for="resume">简历:</label>
    171. <!--注意文本域没有value属性-->
    172. <textarea
    173. name="resume"
    174. id="resume"
    175. cols="30"
    176. rows="5"
    177. placeholder="不超过100字"
    178. ></textarea>
    179. </div>
    180. </fieldset>
    181. <!-- 隐藏域, 用户Id, 注册,登录时间。。。。 -->
    182. <input type="hidden" name="user_id" value="123" />
    183. <p>
    184. <!-- <input type="submit" value="提交" class="btn" /> -->
    185. <!-- 一般用下面的botton -->
    186. <!-- <input type="submit" value="提交" class="btn" /> -->
    187. <button class="btn">提交</button>
    188. </p>
    189. </form>
    190. </body>
    191. </html>
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议