购物车表格实现和用户注册页面表单实现,div实现员工信息表格
程序员文章站
2022-03-24 09:45:46
...
1.购物车表格实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>表格实战:购物车</title>
<style>
table{
/* 将单元格之间的间隙去掉 */
border-collapse: collapse;
width: 70%;
margin: auto;
color: #666;
font-weight: lighter;
/* text-align: center;文本居中 */
text-align: center;
}
/* 表格线直接添加到单元格上面 */
table thead th,table td{
border-bottom: 1px solid #000;
padding: 10px;
}
/* 标题样式 */
table caption{
font-size: 30px;
margin-bottom: 15px;
color: seagreen;
}
/* 设置标题栏字体 */
table th {
font-weight: lighter;
color: seagreen;
}
/* 标题栏添加背景色 */
table thead{
background-color: seashell;
}
/* 隔行变色 */
table tbody tr:nth-of-type(even){
background-color: skyblue;
}
/* 鼠标悬停效果 */
table tbody tr:hover{
background-color: snow;
}
/* 底部样式 */
table tfoot td{
border-bottom: none;
color: violet;
font-size: 1.2rem;
font-weight: bolder;
}
/* 结算按钮 */
body div:last-of-type{
width: 70%;
margin: auto;
}
body div:first-of-type button{
/* 靠右 */
float: right;
width: 100px;
height: 32px;
background-color: seagreen;
color: wheat;
border: none;
/* 设置鼠标样式 */
cursor: pointer;
}
/* 设置鼠标悬停效果 */
body div:first-of-type button:hover{
background-color: coral;
font-size: 1.1rem;
}
</style>
</head>
<body>
<!-- 表格 -->
<table>
<!-- 标题 -->
<caption>购物车</caption>
<!-- 头部 -->
<thead>
<tr>
<th>ID</th>
<th>品牌名</th>
<th>单价/元</th>
<th>单位</th>
<th>数量</th>
<th>金额/元</th>
</tr>
</thead>
<!-- 主体 -->
<tbody>
<tr>
<td>SN-1010</td>
<td>MacBook Pro电脑</td>
<td>1888</td>
<td>台</td>
<td>1</td>
<td>1888</td>
</tr>
<tr>
<td>SN-1020</td>
<td>华为 电脑</td>
<td>1999</td>
<td>台</td>
<td>1</td>
<td>1999</td>
</tr>
<tr>
<td>SN-1030</td>
<td>华硕电脑</td>
<td>2888</td>
<td>台</td>
<td>1</td>
<td>2888</td>
</tr>
<tr>
<td>SN-1040</td>
<td>戴尔电脑</td>
<td>2088</td>
<td>台</td>
<td>1</td>
<td>2088</td>
</tr>
</tbody>
<!-- 底部 -->
<tfoot>
<tr>
<!-- colspan跨列 -->
<td colspan="4">总计:</td>
<td>13</td>
<td>12343</td>
</tr>
</tfoot>
</table>
<!-- 结算按钮 -->
<div>
<button>结算</button>
</div>
</body>
</html>
2.用户注册页面表单实现
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0" >
<title>用户注册</title>
<style>
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;
}
form p {
text-align: center;
}
form .btn {
width: 80px;
height: 30px;
border: none;
background-color: seagreen;
color: #ddd;
}
form .btn:hover {
background-color: coral;
color: white;
cursor: pointer;
}
input:focus {
background-color: rgb(226, 226, 175);
}
</style>
</head>
<body>
<h3>用户注册</h3>
<!-- form+input -->
<form action="" method="POST">
<!-- 控件组 -->
<fieldset>
<legend>基本信息(必填)</legend>
<div>
<label for="my-usernam">账号:</label>
<input type="text"
id="my-usernam"
name="usernam"
placeholder="6-15位字符"
autofocus
required
>
</div>
<div>
<label for="email-id">邮箱:</label>
<input type="email"
name="email"
id="email-id"
placeholder="demo@abc.com"
required
>
</div>
<!-- 密码 -->
<div>
<label for="pwd">密码:</label>
<input type="password"
name="password1"
id="pwd"
placeholder="不少于六位且字母+数字"
>
<button onclick="showPwd(this)" id="btn" type="button">显示密码</button>
</div>
<div>
<label for="pwd-1">确认密码:</label>
<input type="password" name="password2" id="pwd-1">
</div>
</fieldset>
<fieldset>
<legend>扩展信息(选填)</legend>
<div>
<label for="birthday">生日:</label>
<input type="date" name="birthday" id="birthday">
</div>
<div>
<!-- 单选按钮 -->
<label for="secret">性别:</label>
<!-- 单选按钮中的name属性名必须相同 -->
<input type="radio" name="gender" id="male" id="male">
<label for="male">男</label>
<input type="radio" name="gender" id="female" id="female">
<label for="female">女</label>
<input type="radio" name="gender" id="secret" id="secret" checked>
<label for="secret">保密</label>
</div>
<div>
<!-- 复选框 -->
<label for="programe">爱好</label>
<!-- 复选框返回是一个或多个值,最方便后端用数组来处理,所以将name名称设置为数组形式便于后端脚本处理 -->
<input type="checkbox" name="hoddy[]" id="game" value="game">
<label for="game">打游戏</label>
<input type="checkbox" name="hoddy[]" id="shoot" value="shoot">
<label for="shoot">摄影</label>
<input type="checkbox" name="hoddy[]" id="programe" value="programe" checked>
<label for="programe">编程</label>
</div>
<div>
<!-- 选项列表 -->
<label for="brand">手机</label>
<input type="search" name="brand" id="brand" list="phone">
<datalist id="phone">
<option value="apple" ></option>
<option value="huawei" label="华为"></option>
<option value="mi">小米</option>
</datalist>
</div>
</fieldset>
<fieldset>
<legend>其他信息(选填)</legend>
<!-- 文件上传 -->
<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="10"></textarea>
</div>
</fieldset>
<!-- 隐藏域,例如用户的ID,注册,登录的时间。。。。。 -->
<input type="hidden" name="user_id" value="123">
<p>
<input type="submit" value="提交" class="btn">
<button class="btn">提交</button>
</p>
</form>
<script>
// 显示密码
function showPwd(ele){
// const pwd=document.querySelector("#pwd").type="text";
const pwd=document.querySelector("#pwd");
pwd.type="text"
}
</script>
</body>
</html>
3.div实现员工信息表格
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>div实现员工信息表</title>
<style>
/* 表格 */
.table{
/* display: 规定元素应该生成的框的类型 */
display: table;
border: 1px solid #000;
width: 300px;
text-align: center;
margin: auto;
}
/* 标题 */
.table-caption{
display: table-caption;
margin-bottom: 10px;
font-size: 1.4rem;
}
/* 表头 */
.table-thead{
display: table-header-group;
background-color: darkcyan;
}
/* 行 */
.table-row{
display: table-row;
}
/* 列 */
.table-cell{
display: table-cell;
border: 1px solid #000;
padding: 5px;
}
/* 主体 */
.table-tbody{
display: table-row-group;
}
/* 底部 */
.table-tfoot{
display: table-footer-group;
}
/* 列分组table-colgroup */
.table-colgroup{
display: table-column-group;
}
/* 第一列 */
.table-colgroup .table-col:first-of-type{
display: table-column;
background-color: darkgray;
}
/* 其他列 */
.table-colgroup .table-col{
display: table-column;
background-color:darksalmon;
}
</style>
</head>
<body>
<!-- 表格:<table> -->
<div class="table">
<div class="table-caption">员工信息表</div>
<!-- 列分组<colgroup> -->
<div class="table-colgroup">
<div class="table-col"></div>
<div class="table-col"></div>
<div class="table-col"></div>
</div>
<!-- 表头:<thead> -->
<div class="table-thead">
<div class="table-row">
<div class="table-cell">ID</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">1</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">2</div>
<div class="table-cell">程序猿</div>
<div class="table-cell">IT</div>
</div>
</div>
<div class="table-tbody">
<div class="table-row">
<div class="table-cell">2</div>
<div class="table-cell">码农</div>
<div class="table-cell">小农农</div>
</div>
</div>
<!-- 底部:<tfoot> -->
<div class="table-tfoot">
<div class="table-row">
<div class="table-cell">ds</div>
<div class="table-cell">bs</div>
<div class="table-cell">cs</div>
</div>
</div>
</div>
</body>
</html>
上一篇: flex,简单丑陋的二级下拉菜单,
下一篇: 轮播图自动翻页功能实现