html - 在另一个文件中包含一个 HTML 文件

标签 html css

<分区>

我有一个问题想解决。我创建了一个 style.css、index.html 和 cmenu.css(coolmenu 的 cmenu)文件。在我的 cmenu.css 中,我描述了我的 coolmenu 的样子。

这是我的网站:http://pjgini.funpic.de/ . 我的菜单链接位于 index.html 中。通过创建新站点,我必须在新站点中复制相同的链接。我不想在我的每个站点中复制和粘贴所有链接内容。

这是我的 index.html 文件中的菜单链接:

 <div id="klappmenu">
 <ul id="liste">
 <li><a href="#">Kategorie 1</a>
 <ul>
 <li><a href="/Seite.htm">Unterseite 1.1</a></li>
 <li><a href="/Seite.htm">Unterseite 1.2</a></li>
 <li><a href="/Seite.htm">Unterseite 1.3</a></li>
 </ul>
 </li>
 ...
 </div> 

现在我想将它们包含在任何 html 文档中!

最佳答案

PHP 似乎是最好的选择。

将您的菜单放入名为 main-menu.html 的 HTML 文件中。然后,在您希望菜单显示的任何地方包含此 html 代码,但请确保将文件保存为 .php 并且菜单的 html 文件的路径是正确的。

<?php
    include_once("path/to/main-menu.html");
?>

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. If you are new to PHP and want to get some idea of how it works, try the introductory tutorial. After that, check out the online manual.

来源。 php.net

关于html - 在另一个文件中包含一个 HTML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17903118/

上一篇:javascript - 检查背景图片javascript时必须写完整路径

下一篇:iphone - CSS 背景尺寸在移动设备上损坏

相关文章:

jquery - 如果 UL 的高度大于 X,如何将代码附加到具有相同类的 Uls?

html - 主页在 firefox 14.0.1 中无法正确显示

html - 影响所有相同起始名称样式的 CSS 前缀范围

asp.net - 寻呼机更小且没有边界线

html - 使用 Bootstrap 的文本和图像相对响应

html - 表单像背景 CSS 一样透明

php - 用 php 更改 css 背景图片

javascript - CSS Layout 嵌套 div 的奇怪行为

css - 我的链接未被其父 <div> 识别。为什么?

html - 最小 Div 大小?