
批改狀態(tài):合格
老師批語:寫的非常好,非常仔細(xì)認(rèn)真!繼續(xù)加油!
1.<table></table>表格,數(shù)據(jù)化格式的工具表格,數(shù)據(jù)化格式的工具
2.<caption></caption>表格的標(biāo)題表格的標(biāo)題
3.<colgroup></colgroup>用來定義表格bai列的分組
4.<thead></thead>頁眉
5.<tbody></tbody>主體
6.<tfool></tfool>頁腳
7.<tr></tr>定義 HTML 表格中的行
8.<th></th>定義表中的頭單元格
8.<td></td>定義 HTML 表格中的標(biāo)準(zhǔn)單元格
表格實(shí)戰(zhàn)效果圖示例:
HTML代碼樣式:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>表格</title>
</head>
<body>
<table>
<caption>
購物車
</caption>
<thead>
<tr>
<th>ID</th>
<th>品名</th>
<th>單價(jià)/元</th>
<th>單位</th>
<th>數(shù)量</th>
<th>金額/元</th>
</tr>
</thead>
<tbody>
<tr>
<td>SN-1010</td>
<td>MacBook Pro電腦</td>
<td>18999</td>
<td>臺(tái)</td>
<td>1</td>
<td>18999</td>
</tr>
<tr>
<td>SN-1020</td>
<td>iPhone手機(jī)</td>
<td>4999</td>
<td>部</td>
<td>2</td>
<td>9998</td>
</tr>
<tr>
<td>SN-1030</td>
<td>智能AI音箱</td>
<td>399</td>
<td>只</td>
<td>5</td>
<td>1995</td>
</tr>
<tr>
<td>SN-1040</td>
<td>SSD移動(dòng)硬盤</td>
<td>888</td>
<td>個(gè)</td>
<td>2</td>
<td>1776</td>
</tr>
<tr>
<td>SN-1050</td>
<td>黃山毛峰</td>
<td>999</td>
<td>斤</td>
<td>3</td>
<td>2997</td>
</tr>
</tbody>
<tfoot>
<!-- 總計(jì)合并 -->
<tr>
<td colspan="4">總計(jì):</td>
<td>13</td>
<td>35765</td>
</tr>
</tfoot>
</table>
</table>
</body>
</html>
樣式效果:
添加css樣式:
<style>
html {
font-size: 14px;
}
table {
/* 把單元格之間的間隙去除 */
border-collapse: collapse;
/* 父容器的70% */
width: 70%;
/* 居中 */
margin: auto;
color: #666;
/* 字體變細(xì) */
font-weight: lighter;
/* 表格內(nèi)容全部居中 */
text-align: center;
}
/* 表格線直接添加到單元格上面 */
table thead th,
table td {
/* 只加下邊框 */
border-bottom: 1px solid #000;
/* 表格中內(nèi)容與邊框的距離拉大些 */
padding: 10px;
}
/* 標(biāo)題樣式 */
table caption {
/* html的字體為參照 */
font-size: 1.5rem;
margin-bottom: 15px;
/* 設(shè)置購物車這幾個(gè)字的樣式 */
color: orange;
}
table th {
/* id欄設(shè)置樣式 */
font-weight: lighter;
color: hotpink;
}
/* id欄的背景色 */
table thead {
background-color: papayawhip;
}
/* 隔行變色 */
table tbody tr:nth-of-type(even) {
background-color: #efef;
}
/* 鼠標(biāo)懸停時(shí)背景色 */
table tbody tr:hover {
background-color: skyblue;
}
/* 底部樣式 */
table tfoot td {
/* 底部邊框去掉 */
border-bottom: none;
color: tomato;
font-size: 1.2rem;
font-weight: bolder;
}
/* 結(jié)算樣式 */
body div:last-of-type {
width: 70%;
margin: 10px auto;
}
/* 結(jié)算按鈕 */
body div:first-of-type button {
float: right;
width: 120px;
height: 34px;
background-color: teal;
color: white;
border: none;
/* 鼠標(biāo)樣式 變成手*/
cursor: pointer;
}
/* 結(jié)算移入時(shí)效果 */
body div:first-of-type button:hover {
background-color: thistle;
font-size: 1.1rem;
}
</style>
樣式效果:
添加結(jié)算按鈕:
<!-- 結(jié)算按鈕 -->
<div>
<button>結(jié)算</button>
</div>
效果圖:
示例效果圖:
<form>
標(biāo)簽用于創(chuàng)建 HTML 表單<input>
標(biāo)簽實(shí)現(xiàn)用戶輸入基本表單元素
類型 | 描述 |
---|---|
type="text" |
輸入文本類型 |
type="email" |
輸入 email 格式內(nèi)容 |
type="password" |
輸入密碼 |
type="date" |
輸入日期 |
type="radio" |
單選框 |
type="checkbox" |
復(fù)選框 |
type="search" |
搜索框 |
type="file" |
文件上傳 |
type="hidden" |
隱藏選項(xiàng) |
示例代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>表單基本元素</title>
<style>
/* 用戶注冊(cè)顏色灰一點(diǎn)并居中 */
body {
color: #555;
}
h3 {
text-align: center;
}
form {
width: 450px;
margin: 30px auto;
border-top: 1px solid #aaa;
}
/* 表的背景上色,橢圓角 */
form fieldset {
border: 1px solid seagreen;
background-color: lightcyan;
box-shadow: 2px 2px 4px #bbb;
border-radius: 10px;
margin: 20px;
}
/* 表頭組件顏色,橢圓角 */
form fieldset legend {
background-color: rgb(178, 231, 201);
border-radius: 10px;
color: seagreen;
padding: 5px 15px;
}
form div {
margin: 5px;
}
/* 表格輸入時(shí)底部顏色 */
input:focus {
background-color: darkgrey;
}
body p:first-of-type button {
float: right;
width: 120px;
height: 34px;
background-color: teal;
color: white;
border: none;
/* 鼠標(biāo)樣式 變成手*/
cursor: pointer;
}
/* 結(jié)算移入時(shí)效果 */
body p:first-of-type button:hover {
background-color: thistle;
font-size: 1.1rem;
}
</style>
</head>
<body>
<h3>用戶注冊(cè)</h3>
<form action="" method="POST">
<!-- 1.控件組 -->
<fieldset>
<legend>基本信息(必填)</legend>
<div>
<label for="username1">賬  號(hào):</label>
<input
type="text"
id="username1"
name="username"
placeholder="6-15個(gè)字符"
autofocus
required
/>
</div>
<div>
<label for="email-id">郵  箱:</label>
<input
type="email"
name="email"
id="email-id"
placeholder="demo@example.com"
required
/>
</div>
<!-- 密碼 -->
<div>
<label for="pwd-1">密  碼:</label>
<input
type="password"
name="password1"
id="pwd-1"
placeholder="不少于6位且字母+數(shù)字"
/>
<button onclick="showPwd()" id="btn" type="button">顯示密碼</button>
</div>
<div>
<label for="pwd-2">確認(rèn)密碼:</label>
<input type="password" name="password2" id="pwd-2" />
</div>
</fieldset>
<!-- <button>提交</button> -->
<script>
function showPwd(ele) {
document.querySelector("#pwd-1").type = "text";
}
</script>
<fieldset>
<legend>擴(kuò)展信息(選填)</legend>
<div>
<label for="birthday"
>生日:
<input type="date" name="birthday" />
</label>
</div>
<div>
<!-- 單選按鈕 :性別-->
<label for="secret">性別:</label>
<input type="radio" name="gender" value="male" id="" />
<label for="">男</label>
<input type="radio" name="gender" value="famale" id="" />
<label for="">女</label>
<input type="radio" name="gender" value="secret" id="" checked />
<label for="">保密</label>
</div>
<div>
<!-- 復(fù)選框 -->
<label for="">愛好:</label>
<input type="checkbox" name="hobby[]" id="game" value="game" />
<label for="game">打游戲</label>
<input
type="checkbox"
name="hobby[]"
value="shoot"
id="shoot"
/><label for="shoot">攝影</label>
<input
type="checkbox"
name="hobby[]"
value="programme"
id="programme"
checked
/><label for="programme">編程</label>
</div>
<!-- 選項(xiàng)列表 -->
<div>
<label for="brand">手機(jī):</label>
<input type="search" list="phone" name="brand" id="brand" />
<datalist id="phone">
<option value="apple"></option>
<option value="huawei"></option>
<option value="mi" label="小米"></option>
</datalist>
</div>
</fieldset>
<fieldset>
<legend>其它信息(選填)</legend>
<!--文件上傳 ,用file上傳文件-->
<div>
<label for="uploads">上傳頭像:</label>
<input
type="file"
name="user_pic"
id="uploads"
accept="image/png, image/jpeg, image/gif"
/>
</div>
<!--文本域-->
<div>
<label for="resume">簡歷:</label>
<!--注意文本域沒有value屬性-->
<textarea
name="resume"
id="resume"
cols="30"
rows="5"
placeholder="不超過100字"
></textarea>
</div>
</fieldset>
<!-- 隱藏域, 用戶Id, 注冊(cè),登錄時(shí)間。。。。 -->
<input type="hidden" name="user_id" value="123" />
<p>
<!-- <input type="submit" value="提交" class="btn" /> -->
<!-- 一般用下面的botton -->
<!-- <input type="submit" value="提交" class="btn" /> -->
<button class="btn">提交</button>
</p>
</form>
</body>
</html>
注意:單選按鈕中的name屬性名必須相同
瀏覽器顯示示例:
總結(jié):
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)