作业内容:
- <iframe>写一个后台小案例: <a>+<iframe>实现
- 实例演示 标签,属性选择器, 以及群组选择器的使用场景
后台小案例
代码
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>php中文网后台管理系统</title>
<link rel="stylesheet" href="./css/admin.css"/>
</head>
<body>
<div class="content">
<div class="left">
<div class="logo">
<h3>php.cn 后台管理系统</h3>
</div>
<div class="menu">
<nav>
<a href="home.html" target="content">首页</a>
<a href="courses.html" target="content">课程管理</a>
<a href="teachers.html" target="content">教师管理</a>
<a href="orders.html" target="content">订单管理</a>
</nav>
</div>
</div>
<div class="right">
<header>
<section>
<em>admin</em>
<button onclick="location.href='logout.php'">退出</button>
</section>
</header>
<iframe src="home.html" name="content"></iframe>
</div>
</div>
</body>
</html>
home.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>首页</h1>
</body>
</html>
courses.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>课程管理</h1>
</body>
</html>
orders.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>订单管理</h1>
</body>
</html>
admin.css
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
a {
text-decoration: none;
color: #555;
}
.content {
height: 100vh;
width: 100vw;
display: grid;
grid-template-columns: 12em 1fr;
grid-template-areas:
"left right";
}
.left {
grid-area: left;
background-color: gray;
}
.right {
grid-area: right;
}
.logo {
color: whitesmoke;
background-color: seagreen;
height: 5.5em;
text-align: center;
padding-top: 30px;
}
body header {
background-color: white;
letter-spacing: 2px;
padding: 2em;
display: flex;
place-items: center;
border-bottom: #eee;
}
body header h1 {
color: grey;
font-weight: 500;
text-shadow: 1px 1px 1px #000;
}
body header section {
margin-left: auto;
padding-right: 2em;
}
body header section em {
color: grey;
margin-right: 1em;
}
body header section button {
padding: 3px 10px;
border: none;
outline: none;
transition: 0.3s;
}
body header section button:hover {
background-color: coral;
color: #fff;
cursor: pointer;
}
nav {
display: grid;
grid-auto-rows: min-content;
border-right: 1px solid currentColor;
background-color: gray;
padding: 1em;
list-style: none;
}
nav a {
padding: 0.5em 0;
border-bottom: 1px solid #555;
color: #fff;
}
nav a:hover {
transition: 0.3s;
font-size: 1.01em;
color: black;
}
body iframe {
width: calc(100vw - 10em);
height: calc(100vh - 6em);
border: none;
background-color: #efefef;
}
效果
选择器的使用
html
<div class="content">
<div class="left">
<div class="logo">
<h3>php.cn 后台管理系统</h3>
</div>
<div class="menu">
<nav>
<a class="active" href="home.html" target="content">首页</a>
<a href="courses.html" target="content">课程管理</a>
<a href="teachers.html" target="content">教师管理</a>
<a href="orders.html" target="content">订单管理</a>
</nav>
</div>
</div>
<table id="time-table">
<caption><h2>课程表</h2></caption>
<thead>
<tr>
<th colspan="2">节次\星期</th>
<th>星期一</th>
<th>星期二</th>
<th>星期三</th>
<th>星期四</th>
<th>星期五</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="7" style="background-color: lightgray;">
<p style="margin: 2;">早自习</p>
<p style="margin: 2;">07:00 - 07:50</p>
</td>
</tr>
<tr>
<th rowspan="4">上午</th>
<th>
<p>第一节</p>
<p>08:00 - 08:40</p>
</th>
<td>语文</td>
<td>数学</td>
<td>英语</td>
<td>化学</td>
<td>物理</td>
</tr>
<tr>
<th>
<p>第二节</p>
<p>08:50 - 09:30</p>
</th>
<td>语文</td>
<td>数学</td>
<td>英语</td>
<td>化学</td>
<td>物理</td>
</tr>
<tr>
<th>
<p>第三节</p>
<p>09:40 - 10:20</p>
</th>
<td>语文</td>
<td>数学</td>
<td>英语</td>
<td>化学</td>
<td>物理</td>
</tr>
<tr>
<th>
<p>第四节</p>
<p>10:30 - 11:20</p>
</th>
<td>语文</td>
<td>数学</td>
<td>英语</td>
<td>化学</td>
<td>物理</td>
</tr>
<tr>
<td colspan="7" style="background-color: lightgray;">
<p>午休</p>
<p>12:00 - 14:00</p>
</td>
</tr>
<tr>
<th rowspan="3">上午</th>
<th>
<p>第五节</p>
<p>14:00 - 14:40</p>
</th>
<td>语文</td>
<td>数学</td>
<td>英语</td>
<td>化学</td>
<td>物理</td>
</tr>
<tr>
<th>
<p>第六节</p>
<p>14:50 - 15:30</p>
</th>
<td>语文</td>
<td>数学</td>
<td>英语</td>
<td>化学</td>
<td>物理</td>
</tr>
<tr>
<th>
<p>第七节</p>
<p>15:40 - 16:40</p>
</th>
<td>语文</td>
<td>数学</td>
<td>英语</td>
<td>化学</td>
<td>物理</td>
</tr>
<td colspan="7" style="background-color: lightgray;">
<p>晚自习</p>
<p>19:00 - 21:50</p>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<!-- 水平方向合并/列合并 : colspan -->
<th colspan="2">课程表有效期:</th>
<td colspan="5">2022年10月1日-2023年5月1日</td>
</tr>
</tfoot>
</table>
</div>
CSS代码
标签选择器
h3 {
color: red;
}
a {
text-decoration: none;
color: gray;
}
#time-table p {
margin: 2px;
}
属性选择器
a.active {
color: orange;
}
群组选择器
/* 群组选择器, 多个选择器之间用逗号分开 */
#time-table, th, td{
border: solid gray 2px;
text-align: center;
}
/* 群组选择器, 多个选择器之间用逗号分开 */
tfoot th, tfoot td {
border: none;
}