在每个页面上都包含页眉/页脚?

时间:2016-03-03 10:34:47

标签: php html css

我正在创建一个包含多个页面的网站,其中包含关于信息,项目,活动等的信息。

我的第一个问题是,如何在不复制每个文件的完整代码的情况下,将导航栏,页眉和页脚包含在所有html文件中? 我的第二个问题是,html结构应该如何在单独的页眉/页脚文件中查找,以便我可以将它们包含在我的页面html' s中?

如果你提到PHP作为解决方案,请指出我的过程的一些链接/教程。

4 个答案:

答案 0 :(得分:2)

如果您使用php文件,您可以执行以下操作:

的index.php:

<? 
    include("header.php");
?>

    //page content

<?
    include("footer.php")
?>

的header.php:

<head>
    //head
</head>
<body>

footer.php:

<footer>
    //footer
</footer>
</body>

在header.php中你可以放置标签等。 在每个页面中,您只能包含这些文件而不是

答案 1 :(得分:0)

你可以使用AngularJS。如果您不想使用服务器端脚本 http://www.w3schools.com/angular/

<body ng-app="">

<div ng-include="'header.htm'"></div>
     Your page goes here
</body>

不要忘记添加AngularJS库,也可以使用cdn。

答案 2 :(得分:0)

您可以为页眉和页脚创建特定文件,并在您需要的页面中使用它们。

require 'footer.php'
require 'header.php'

答案 3 :(得分:0)

首先,您需要制作三个文件 navbar.php,header.php footer.php ,这些文件分别包含其代码。

现在,在每个网页中放置以下代码。

include('header.php'); //Your website header code will be load from header.php
include('navbar.php'); //Your website navbar code will be load from navbar.php
include('footer.php');//Your website footer code will be load from footer.php