大家好,我是网络编程的新手。我想创建一种 CSS 模板,其中除了页面内容外,所有页面看起来都一样。
所以我在顶部有一个 Logo 和一些选项卡,您可以在其中浏览网站,但页面的内容会有所不同(联系、关于、信息等)。
我该如何着手创建这个模板?
最佳答案
您可能想尝试使用纯 HTML + CSS 构建您的模板页面,然后使用简单的 PHP 包含来构建您的页面。例如,您可以将页面分成两个单独的文件:
header.php:
<!DOCTYPE html>
<html>
<head><title>Hello World</title></head>
<body>
<div id="main-content">
和 footer.php:
</div>
</body>
</html>
然后,对于使用该模板的任何文件,您将使用如下内容:
<?php include("header.php"); ?>
<!--All the content of your page goes here-->
<h1>Hello World!</h1>
<p>Lorem Ipsum</p>
<?php include("footer.php"); ?>
那么如果有人访问了之前的文件(假设它叫做 index.php),那么这些文件将被组装起来,最终的 HTML 输出将类似于:
<!DOCTYPE html>
<html>
<head><title>Hello World</title></head>
<body>
<div id="main-content">
<!--All the content of your page goes here-->
<h1>Hello World!</h1>
<p>Lorem Ipsum</p>
</div>
</body>
</html>
只要确保您的服务器上运行着 PHP,否则它根本无法工作。另外,如果您想在本地开发网站,我建议您使用 XAMPP获取本地 Apache 主机。
关于html - 模板 html 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3225159/