1.css
部分
.header {
background-color: brown;
height: 30px;
}
.nav li {
list-style:none;
min-width:80px;
line-height: 30px;
float: left;
}
.nav li a {
text-decoration: none;
color: white;
}
.nav {
overflow: hidden;
}
.footer {
background-color: #ccddcc;
height: 30px;
display: flex;
justify-content: center;
align-items: center;
}
2.header.php
通用头部文件
<?php
//列表数组
$data = [
'gc' => [
'title' => '国产好剧',
'img' => 'static/1.jpg',
'yp' => [
'倚天屠龙记',
'都挺好',
'如果可以爱'
],
],
'om' => [
'title' => '欧美猛片',
'img' => 'static/4.jpg',
'yp' => [
'阿凡提',
'泰坦尼克号',
'蜘蛛侠'
],
],
'rh' => [
'title' => '日韩推荐',
'img' => 'static/7.jpg',
'yp' => [
'苍井空',
'武藤兰',
'波多野结衣'
],
],
];
//导航数组
$navArr = [
[
'url' => 'index.php',
'title' => '首页',
],
[
'url' => 'gc.php',
'title' => '国产好剧',
],
[
'url' => 'om.php',
'title' => '欧美猛片',
],
[
'url' => 'rh.php',
'title' => '日韩推荐',
]
];
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>影视网站</title>
<link rel="stylesheet" href="static/style1.css">
</head>
<body>
<!-- 头部-->
<div class="header">
<ul class="nav">
<?php
foreach ($navArr as $arr){
echo '<li><a href="' . $arr['url'] . '">' . $arr['title'] . '</a></li>';
}
?>
</ul>
</div>
3.footer.php
通用底部文件
<!--底部版权-->
<div class="footer">
<p class="copyright">Jason版权所有</p>
</div>
</body>
</html>
4.index.php
首页文件
<?php
require_once 'header.php';
foreach ($data as $arr){
echo '<h2>' . $arr['title'] . '</h2>';
echo '<ol>';
foreach ($arr['yp'] as $str){
echo '<li>' . $str . '</li>';
}
echo '</ol>';
}
require_once 'footer.php';
?>
5.gc.php
国产好剧文件
<?php
require_once 'header.php';
echo '<h2>' . $data['gc']['title'] .'</h2>';
echo '<img src="' .$data['gc']['img'] . '" alt="">';
echo '<ol>';
foreach ($data['gc']['yp'] as $str){
echo '<li>' . $str . '</li>';
}
echo '</ol>';
require_once 'footer.php';
?>
6.om.php
欧美猛片文件
<?php
require_once 'header.php';
echo '<h2>' . $data['om']['title'] . '</h2>';
echo '<img src="' . $data['om']['img'] . '" alt="">';
echo '<ol>';
foreach ($data['om']['yp'] as $str){
echo '<li>' . $str. '</li>';
}
echo '</ol>';
require_once 'footer.php';
?>
7.rh.php
日韩推荐文件
<?php
require_once 'header.php';
echo '<h2>'. $data['rh']['title'] .'</h2>';
echo '<img src="' . $data['rh']['img'] . '" alt="">';
echo '<ol>';
foreach ($data['rh']['yp'] as $str){
echo '<li>' . $str . '</li>';
}
echo '</ol>';
require_once 'footer.php';
?>
手写代码
运行效果