博主信息
博文 11
粉丝 0
评论 0
访问量 10646
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
前端表格与表单实战
new
原创
1022人浏览过

1.购物车(表格实现)

表格主要标签

标签 描述
table 定义表格
th 定义表头
tr 定义行
td 定义列
caption 定义标题
thead 定义表格头部
tbody 定义表格主体
tfoot 定义表格底部
display 设置元素显示类型

购物车代码

  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. width: 70%;
  15. margin: auto;
  16. color: #666;
  17. font-weight: lighter;
  18. text-align: center;
  19. }
  20. /* 表格线直接添加到单元格上面 */
  21. table thead th,
  22. table td {
  23. border-bottom: 1px solid #ccc;
  24. padding: 10px;
  25. }
  26. /* 标题样式 */
  27. table caption {
  28. font-size: 1.5rem;
  29. margin-bottom: 15px;
  30. color: green;
  31. }
  32. table th {
  33. font-weight: lighter;
  34. color: green;
  35. }
  36. table thead tr:first-of-type {
  37. background-color: cyan;
  38. }
  39. /* 隔行变色 */
  40. table tbody tr:nth-of-type(even) {
  41. background-color: yellow;
  42. }
  43. /* 鼠标悬停效果 */
  44. table tbody tr:hover {
  45. background-color: pink;
  46. }
  47. /* 底部样式 */
  48. table tfoot td {
  49. border-bottom: none;
  50. color: coral;
  51. font-size: 1.2rem;
  52. font-weight: bolder;
  53. }
  54. /* 结算按钮 */
  55. body div:last-of-type {
  56. width: 70%;
  57. margin: 10px auto;
  58. }
  59. body div:first-of-type button {
  60. /* 靠右 */
  61. float: right;
  62. width: 120px;
  63. height: 32px;
  64. background-color: seagreen;
  65. color: white;
  66. border: none;
  67. /* 设置鼠标样式 */
  68. cursor: pointer;
  69. }
  70. body div:first-of-type button:hover {
  71. background-color: coral;
  72. font-size: 1.1rem;
  73. }
  74. </style>
  75. </head>
  76. <body>
  77. <table>
  78. <!-- 标题 -->
  79. <caption>购物车</caption>
  80. <!-- 头部 -->
  81. <thead>
  82. <tr>
  83. <th>序号</th>
  84. <th>名称</th>
  85. <th>单价</th>
  86. <th>数量</th>
  87. <th>总价</th>
  88. </tr>
  89. </thead>
  90. <!-- 主体 -->
  91. <tbody>
  92. <tr>
  93. <td>1</td>
  94. <td>华为P40Pro</td>
  95. <td>5800</td>
  96. <td>1</td>
  97. <td>5800</td>
  98. </tr>
  99. <tr>
  100. <td>2</td>
  101. <td>联想X1笔记本电脑</td>
  102. <td>13000</td>
  103. <td>1</td>
  104. <td>13000</td>
  105. </tr>
  106. <tr>
  107. <td>3</td>
  108. <td>飞利浦理发器</td>
  109. <td>240</td>
  110. <td>1</td>
  111. <td>240</td>
  112. </tr>
  113. <tr>
  114. <td>4</td>
  115. <td>电脑椅</td>
  116. <td>2500</td>
  117. <td>1</td>
  118. <td>2500</td>
  119. </tr>
  120. </tbody>
  121. <!-- 底部 -->
  122. <tfoot>
  123. <td colspan="4">合计</td>
  124. <td>21540</td>
  125. </tfoot>
  126. </table>
  127. <!-- 结算 -->
  128. <div>
  129. <button>结算</button>
  130. </div>
  131. </body>
  132. </html>

运行结果

2用户注册页面(表单实现)

主要标签

标签 描述
<fieldset>.. < /fieldset> 控件组
placeholder 提示信息
autofocus 自动获取焦点
<input type="email"> email类型
<input type="password" name="password"> 密码类型
<legend> ..</legend> 扩展信息
radio 单选
checkbox 复选/多选
<input type="date"> 日期选择器
textarea 文本域
file 文件上传
hidden 隐藏域

代码

  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. body {
  9. color: #555;
  10. }
  11. h3 {
  12. text-align: center;
  13. }
  14. form {
  15. width: 450px;
  16. margin: 30px auto;
  17. border-top: 1px solid #aaa;
  18. }
  19. form fieldset {
  20. border: 1px solid seagreen;
  21. background-color: lightcyan;
  22. box-shadow: 2px 2px 4px #bbb;
  23. border-radius: 10px;
  24. margin: 20px;
  25. }
  26. form fieldset legend {
  27. background-color: rgb(178, 231, 201);
  28. border-radius: 10px;
  29. color: seagreen;
  30. padding: 5px 15px;
  31. }
  32. form div {
  33. margin: 5px;
  34. }
  35. form p {
  36. text-align: center;
  37. }
  38. form .btn {
  39. width: 80px;
  40. height: 30px;
  41. border: none;
  42. background-color: seagreen;
  43. color: #ddd;
  44. }
  45. form .btn:hover {
  46. background-color: coral;
  47. color: white;
  48. cursor: pointer;
  49. }
  50. input:focus {
  51. background-color: rgb(226, 226, 175);
  52. }
  53. </style>
  54. </head>
  55. <body>
  56. <h3>用户注册</h3>
  57. <!-- form+input.... -->
  58. <form action="" method="POST">
  59. <!-- 控件组 -->
  60. <fieldset>
  61. <legend>基本信息(必填)</legend>
  62. <div>
  63. <label for="my-username">账号:</label>
  64. <input type="text" id="my-username" name="username" placeholder="6-15位字符" autofocus />
  65. </div>
  66. <div>
  67. <label for="email-id">邮箱:</label>
  68. <input type="email" name="email" id="email-id" placeholder="demo@example.com" />
  69. </div>
  70. <!-- 密码 -->
  71. <div>
  72. <label for="pwd-2">密码:</label>
  73. <input type="password"" name=" password1" id="pwd-2" placeholder="不少于6位且字母+数字" />
  74. </div>
  75. <div>
  76. <label for="pwd-1">确认:</label>
  77. <input type="password" name="password2" id="pwd-1" />
  78. </div>
  79. </fieldset>
  80. <fieldset>
  81. <legend>扩展信息(选填)</legend>
  82. <div>
  83. <label>生日:
  84. <input type="date" name="birthday" />
  85. </label>
  86. </div>
  87. <div>
  88. <!-- 单选按钮 -->
  89. <label for="secret">性别:</label>
  90. <!-- 单选按钮中的name属性名必须相同 -->
  91. <input type="radio" name="gender" value="male" id="male" /><label for="male"></label>
  92. <input type="radio" name="gender" value="female" id="female" /><label for="female"></label>
  93. <input type="radio" name="gender" value="secret" id="secret" checked /><label for="secret">保密</label>
  94. </div>
  95. <div>
  96. <!-- 复选框 -->
  97. <label for="programme">爱好</label>
  98. <!-- 因为复选框返回是一个或多个值,最方便后端用数组来处理, 所以将name名称设置为数组形式便于后端脚本处理 -->
  99. <input type="checkbox" name="hobby[]" id="game" value="game" /><label for="game">打游戏</label>
  100. <input type="checkbox" name="hobby[]" value="shoot" id="shoot" /><label for="shoot">摄影</label>
  101. <input type="checkbox" name="hobby[]" value="programme" id="programme" checked /><label
  102. for="programme">编程</label>
  103. </div>
  104. <div>
  105. <!-- 选项列表 -->
  106. <label for="brand">手机:</label>
  107. <input type="search" list="phone" name="brand" id="brand" />
  108. <datalist id="phone">
  109. <option value="apple"> </option>
  110. <option value="huawei" label="华为"></option>
  111. <option value="mi" label="小米"> </option>
  112. </datalist>
  113. </div>
  114. </fieldset>
  115. <fieldset>
  116. <legend>其它信息(选填)</legend>
  117. <!--文件上传-->
  118. <div>
  119. <label for="uploads">上传头像:</label>
  120. <input type="file" name="user_pic" id="uploads" accept="image/png, image/jpeg, image/gif" />
  121. </div>
  122. <!--文本域-->
  123. <div>
  124. <label for="resume">简历:</label>
  125. <!--注意文本域没有value属性-->
  126. <textarea name="resume" id="resume" cols="30" rows="5" placeholder="不超过100字"></textarea>
  127. </div>
  128. </fieldset>
  129. <!-- 隐藏域, 例如用户的Id, 注册,登录的时间。。。。 -->
  130. <input type="hidden" name="user_id" value="123" />
  131. <p>
  132. <input type="submit" value="提交" class="btn" />
  133. <button class="btn">提交</button>
  134. </p>
  135. </form>
  136. </body>
  137. </html>

运行结果

批改老师:WJWJ

批改状态:合格

老师批语:写的不错,很认真仔细!
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学