一.简易购物车(表格实现)
1.使用技术:CSS和HTML中的表格;
2.实现静态页面效果图,如图所示:
3.HTML代码部分:
<table>
<!-- 标题 -->
<caption>
购物车
</caption>
<!-- 头部 -->
<thead>
<tr>
<th>ID</th>
<th>名称</th>
<th>单价/元</th>
<th>数量</th>
<th>总价/元</th>
</tr>
</thead>
<tbody>
<tr>
<td>SQ_001</td>
<td>显示器</td>
<td>500</td>
<td>2</td>
<td>1000</td>
</tr>
<tr>
<td>SQ_002</td>
<td>篮球</td>
<td>55</td>
<td>10</td>
<td>550</td>
</tr>
<tr>
<td>SQ_003</td>
<td>华为手机</td>
<td>3999</td>
<td>1</td>
<td>3999</td>
</tr>
<tr>
<td>SQ_004</td>
<td>联系笔记本</td>
<td>5500</td>
<td>2</td>
<td>11000</td>
</tr>
<tr>
<td>SQ_005</td>
<td>智能AI音响</td>
<td>399</td>
<td>1</td>
<td>399</td>
</tr>
</tbody>
<tfoot>
<tr>
<!-- colspan:合并单员格 -->
<td colspan="3">总计:</td>
<td>16</td>
<td>16948</td>
</tr>
</tfoot>
</table>
<div class="jiesun"><button>去结算</button></div>
</body>
4.CSS代码部分:
<style>
table {
/* 去除单元格直接的边框间隙 */
border-collapse: collapse;
width: 75%;
/* 设置表格居中 */
margin: auto;
color: slategray;
font-size: lighter;
text-align: center;
}
td,
th {
/* 给所有单元格加边框 */
border-bottom: 1px solid rgb(216, 213, 213);
/* 设置内边距 */
padding: 10px;
}
table th {
background-color: rgb(30, 168, 223);
color: springgreen;
font-weight: lighter;
}
table caption {
font-size: 2rem;
margin-bottom: 15px;
}
table tbody tr:nth-of-type(even) {
background-color: #efef;
}
/* 鼠标悬停效果 */
table tbody tr:hover {
background-color: tomato;
}
table tfoot td {
border-bottom: none;
color: yellowgreen;
font-size: 1.5rem;
}
.jiesun {
width: 75%;
margin: auto;
margin-top: 20px;
}
.jiesun button {
background-color: rgb(12, 189, 189);
border: none;
border-radius: 45%;
float: right;
font-size: 1.2rem;
/* 设置鼠标移入边手样式 */
cursor: pointer;
}
.jiesun button:hover {
background-color: coral;
font-size: 1.5rem;
}
</style>
二.注册表单
1.使用技术:CSS和HTML中的表单及部分js;
2.实现静态页面效果图,密码显示与隐藏;如图所示:
3.HTML部分代码:
<body>
<h1>用户注册</h1>
<form action="" method="POST">
<!-- 控件组 -->
<fieldset>
<legend>基本信息(必填)</legend>
<div>
<label for="username">账号:</label>
<input
type="text"
name="username"
id="username"
placeholder="不能少于6个字符"
required
autofocus
/>
</div>
<div>
<label for="email">邮箱:</label>
<input
type="email"
name="email"
id="email"
placeholder="563463@qq.com"
required
/>
</div>
<div>
<label for="pwd">密码:</label>
<input
type="password"
name="pwd"
id="pwd"
placeholder="123456"
required
/>
<button onclick="showpwd()" id="btn" type="button">显示密码</button>
</div>
<div>
<label for="rpwd">确认密码:</label>
<input type="password" name="rpwd" id="rpwd" required />
</div>
</fieldset>
<fieldset>
<legend>其他信息(选填)</legend>
<div>
<label for="secrecy">性别:</label>
<input type="radio" name="sex" id="male" /><label>男</label>
<input type="radio" name="sex" id="female" /><label>女</label>
<input type="radio" name="sex" id="secrecy" /><label>保密</label>
</div>
<div>
<label
>生日:
<input type="date" name="brithday" />
</label>
</div>
<div>
<label for=""> 爱好:</label>
<input type="checkbox" name="hobby[]" id="" />旅游
<input type="checkbox" name="hobby[]" id="" />运动
<input type="checkbox" name="hobby[]" id="" />摄影
<input type="checkbox" name="hobby[]" id="" />钓鱼
<input type="checkbox" name="hobby[]" id="" />打游戏
</div>
<div>
<label for="search">手机品牌:</label>
<input type="search" name="search" id="search" list="phone" />
<datalist id="phone">
<option value="apple" label="苹果"></option>
<option value="huawei" label="华为"></option>
<option value="xiaomi" label="小米"></option>
</datalist>
</div>
</fieldset>
<fieldset>
<legend>扩展信息</legend>
<div>
<label for="userimg">上传头像:</label>
<input type="file" name="userimg" id="userimg" />
</div>
<div>
<label for="synopsis">简介:</label>
<textarea
name="synopsis"
id="synopsis"
cols="30"
rows="5"
placeholder="不超过100字符"
></textarea>
</div>
</fieldset>
<p><button class="btn">注册</button></p>
</form>
</body>
4.CSS代码部分:
<style>
h1 {
text-align: center;
}
form {
width: 500px;
border-top: 1px solid #000;
margin: 25px auto;
}
form fieldset {
background-color: rgb(147, 238, 238);
border: 1px solid seagreen;
box-shadow: 2px 2px 4px #bbb;
border-radius: 15px;
margin: 20px;
}
form fieldset legend {
background-color: darkorange;
color: darkslategrey;
box-shadow: 2px 2px 4px #bbb;
border-radius: 10px;
}
form p {
text-align: center;
}
.btn {
background-color: dimgrey;
color: ghostwhite;
box-shadow: 2px 2px 4px #bbb;
font-size: 1.5rem;
border-radius: 10px;
}
.btn:hover {
background-color: rgb(19, 196, 128);
font-size: 2.5rem;
cursor: pointer;
}
</style>
5.js代码部分:
<script>
// 隐藏/显示密码
function showpwd() {
const btntype = document.querySelector("#pwd").type;
if (btntype == "password") {
document.querySelector("#pwd").type = "text";
document.querySelector("#btn").innerHTML = "隐藏密码";
} else {
document.querySelector("#pwd").type = "password";
document.querySelector("#btn").innerHTML = "显示密码";
}
}
</script>