表格实现购物车、表单实现用户注册页面
购物车
购物车一:table
标签
标签 |
描述 |
<table></table> |
定义表格 |
<caption></caption> |
定义表格标题 |
<thead></thead> |
定义表格表头 |
<tbody></tbody> |
定义表格主要内容 |
<tfoot></tfoot> |
定义表格页脚 |
<tr></tr> |
表格的行 |
<th></th> |
表头中的项目 |
<td></td> |
表格中单元格内容 |
示例代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>购物车一:`table`标签</title>
<style>
table {
border-collapse: collapse;
width: 70%;
margin: auto;
text-align: center;
}
table caption {
font-size: 1.5rem;
font-weight: bolder;
margin-top: 20px;
margin-bottom: 20px;
}
table thead th {
height: 30px;
background-color: lightblue;
}
table tbody tr {
height: 30px;
border-bottom: 1px solid #ccc;
}
table tfoot {
color: coral;
}
table tfoot td:first-of-type {
text-align: right;
}
div {
width: 70%;
margin: 10px auto;
}
div button {
float: right;
border: none;
width: 100px;
height: 50px;
}
div button:hover {
background-color: red;
font-size: large;
}
</style>
</head>
<body>
<table>
<caption>
购物车
</caption>
<thead>
<tr>
<th>编码</th>
<th>名称</th>
<th>单价</th>
<th>数量</th>
<th>总价</th>
</tr>
</thead>
<tbody>
<tr>
<td>SN-1</td>
<td>显示器</td>
<td>1000</td>
<td>2</td>
<td>2000</td>
</tr>
<tr>
<td>SN-2</td>
<td>鼠标</td>
<td>100</td>
<td>2</td>
<td>200</td>
</tr>
<tr>
<td>SN-3</td>
<td>键盘</td>
<td>500</td>
<td>2</td>
<td>1000</td>
</tr>
<tr>
<td>SN-4</td>
<td>主板</td>
<td>700</td>
<td>1</td>
<td>700</td>
</tr>
<tr>
<td>SN-5</td>
<td>CPU</td>
<td>1000</td>
<td>2</td>
<td>2000</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3">总计:</td>
<td>9</td>
<td>5900</td>
</tr>
</tfoot>
</table>
<div>
<button>结算</button>
</div>
</body>
</html>
显示结果
购物车二:div
+css
CSS |
HTML |
display: table; |
<table></table> |
display: table-caption; |
<caption></caption> |
display: table-header-group; |
<thead></thead> |
display: table-row-group; |
<tbody></tbody> |
display: table-footer-group; |
<tfoot></tfoot> |
display: table-row; |
<tr></tr> |
display: table-cell; |
<td></td> |
示例代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>购物车二:`div`+`css`</title>
<style>
.table {
display: table;
width: 70%;
margin: auto;
text-align: center;
}
.table-caption {
display: table-caption;
font-size: 1.5rem;
font-weight: bolder;
margin-top: 20px;
margin-bottom: 20px;
}
.table-thead {
display: table-header-group;
}
.table-tbody {
display: table-row-group;
}
.table-tfoot {
display: table-footer-group;
color: coral;
}
.table-row {
display: table-row;
height: 30px;
}
.table-cell {
display: table-cell;
height: 30px;
}
.table-thead .table-cell {
background-color: lightblue;
}
.table-tbody .table-cell {
border-bottom: 1px solid #ccc;
}
.button {
width: 70%;
margin: 10px auto;
}
div button {
float: right;
border: none;
width: 100px;
height: 50px;
}
div button:hover {
background-color: red;
font-size: large;
}
</style>
</head>
<body>
<div class="table">
<div class="table-caption">购物车</div>
<div class="table-thead">
<div class="table-row">
<div class="table-cell">编码</div>
<div class="table-cell">名称</div>
<div class="table-cell">单价</div>
<div class="table-cell">数量</div>
<div class="table-cell">总价</div>
</div>
</div>
<div class="table-tbody">
<div class="table-row">
<div class="table-cell">SN-1</div>
<div class="table-cell">显示器</div>
<div class="table-cell">1000</div>
<div class="table-cell">2</div>
<div class="table-cell">2000</div>
</div>
<div class="table-row">
<div class="table-cell">SN-2</div>
<div class="table-cell">鼠标</div>
<div class="table-cell">100</div>
<div class="table-cell">2</div>
<div class="table-cell">200</div>
</div>
<div class="table-row">
<div class="table-cell">SN-3</div>
<div class="table-cell">键盘</div>
<div class="table-cell">500</div>
<div class="table-cell">2</div>
<div class="table-cell">1000</div>
</div>
<div class="table-row">
<div class="table-cell">SN-4</div>
<div class="table-cell">主板</div>
<div class="table-cell">700</div>
<div class="table-cell">1</div>
<div class="table-cell">700</div>
</div>
<div class="table-row">
<div class="table-cell">SN-5</div>
<div class="table-cell">CPU</div>
<div class="table-cell">1000</div>
<div class="table-cell">2</div>
<div class="table-cell">2000</div>
</div>
</div>
<div class="table-tfoot">
<div class="table-row">
<!-- 填充空格表示单元格合并 -->
<div class="table-cell"> </div>
<div class="table-cell"> </div>
<div class="table-cell">总计:</div>
<div class="table-cell">9</div>
<div class="table-cell">5900</div>
</div>
</div>
</div>
<div class="button">
<button>结算</button>
</div>
</body>
</html>
显示结果
用户注册页面
<form>
标签用于创建 HTML 表单- 使用
<input>
标签实现用户输入
类型 |
描述 |
type="text" |
输入文本类型 |
type="email" |
输入 email 格式内容 |
type="password" |
输入密码 |
type="date" |
输入日期 |
type="radio" |
单选框 |
type="checkbox" |
复选框 |
type="search" |
搜索框 |
type="file" |
文件上传 |
type="hidden" |
隐藏选项 |
示例代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>表单实现用户注册页面</title>
<style>
body {
background-color: lightgrey;
}
.register h3 {
text-align: center;
}
.register .base {
background-color: lightseagreen;
}
</style>
</head>
<body>
<div class="register">
<h3>用户注册</h3>
<form action="" method="">
<fieldset>
<legend>基本信息(必填)</legend>
<div class="Base">
<label for="Name">账号:</label>
<input
type="text"
name="myName"
id="Name"
placeholder="6-15个字符"
required
autofocus
/>
</div>
<div>
<label for="Email">邮箱:</label>
<input
type="email"
name="myEmail"
id="Email"
placeholder="demo@example.com"
required
/>
</div>
<div>
<label for="Pwd1">密码:</label>
<input
type="password"
name="myPassword1"
id="Pwd1"
placeholder="********"
/>
</div>
<div>
<label for="Pwd2">确认:</label>
<input
type="password"
name="myPassword2"
id="Pwd2"
placeholder="********"
/>
</div>
</fieldset>
<fieldset>
<legend>扩展信息(选填)</legend>
<div>
<label for="Birth">生日:</label>
<input type="date" name="myBirth" id="Birth" />
</div>
<div>
<label for="">性别:</label>
<input type="radio" name="myGender" value="male" />
<label for="">男</label>
<input type="radio" name="myGender" value="female" />
<label for="">女</label>
<input type="radio" name="myGender" value="secret" checked />
<label for="">保密</label>
</div>
<div>
<label for="">爱好:</label>
<input type="checkbox" name="myHobby[]" id="Game" value="game" />
<label for="Game">打游戏</label>
<input type="checkbox" name="myHobby[]" id="Shoot" value="shoot" />
<label for="Shoot">拍摄</label>
<input
type="checkbox"
name="myHobby[]"
id="Prog"
value="program"
checked
/>
<label for="Prog">编程</label>
</div>
<div>
<label for="">手机:</label>
<input type="search" list="lists" name="myBrand" id="Brand" />
<datalist id="lists">
<option value="apple">苹果</option>
<option value="huawei">华为</option>
<option value="xiaomi">小米</option>
</datalist>
</div>
<div>
<label for="">文件:</label>
<input type="file" name="" id="" />
</div>
</fieldset>
</form>
<div>
<button>提交</button>
</div>
</div>
</body>
</html>
显示结果
总结