Html 如何为所有网页制作相同的布局

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9872912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:21:06  来源:igfitidea点击:

How to make same layout for all web pages

csshtml

提问by mainajaved

I am currently working on HTML I want to ask a question about website development.I am developing a website in which the basic layout remains same like menu, side menu etc but only the content changes.Currently I have make separate .html file for all web pages. Can any one tell me is there a way through which I can make a separate file having etc common to all and call it in my html file.I have heard about CSS but it will only change the style and layout. thanks

我目前正在研究 HTML 我想问一个关于网站开发的问题。我正在开发一个网站,其中基本布局保持不变,如菜单、侧菜单等,但只有内容发生变化。目前我为所有人制作了单独的 .html 文件网页。任何人都可以告诉我有没有一种方法可以让我制作一个对所有人通用的单独文件,并在我的 html 文件中调用它。我听说过 CSS 但它只会改变样式和布局。谢谢

回答by Manse

If your HTTP (apache 2and IISdo) server supports Server Side Includesthen you can just include another HTML file :

如果您的 HTTP(apache 2IIS支持)服务器支持服务器端包含,那么您只需包含另一个 HTML 文件:

<!--#include file="header.html"-->

your content

<!--#include file="footer.html"-->

no need for a server side language then - just plain HTML

不需要服务器端语言 - 只需简单的 HTML

回答by Starx

This is very big topic to include in just one answer. SO I will give only the logical part.

这是一个非常大的话题,只包含在一个答案中。所以我只会给出逻辑部分。

Separate your template into multiple chunks like:

将您的模板分成多个块,例如:

1. header.php
2. leftSidebar.php
4. rightsidebar.php
5. footer.php

Now, include these common part on your every page.

现在,将这些公共部分包含在您的每一页上。

For example: index.php

例如: index.php

<?php

    include "header.php";
    include "leftSidebar.php";
    echo "<div>".$thedifferentpart."</div>"; //Change only this part on every other page you will create.
    include "footer.php";

?>

NOTE:This is only a logical part, applying the concept on your code

注意:这只是一个逻辑部分,将概念应用于您的代码

回答by Luca Reghellin

Yes, your best bet is a server side language, as Adam said. Absolutely avoid using the old style html frames: they're deprecated, and cause a certain number of problems, both on the programming side and on google optimization.

是的,正如亚当所说,您最好的选择是服务器端语言。绝对避免使用旧样式的 html 框架:它们已被弃用,并会导致一定数量的问题,无论是在编程方面还是在谷歌优化方面。

By using a server side language, you'll still have entire pages, but they will be partially generated by php (or asp) by printing more files into one. For example:

通过使用服务器端语言,您仍将拥有整个页面,但它们将由 php(或 asp)通过将更多文件打印成一个来部分生成。例如:

http://www.php.net/manual/en/function.include.php

http://www.php.net/manual/en/function.include.php

Bye!

再见!

回答by KingCronus

Your best bet in the long term is to use a server side language like ASP.net or PHP

从长远来看,您最好的选择是使用服务器端语言,如 ASP.net 或 PHP

回答by PenguinCoder

I don't believe that is possible, strictly through HTML. However, you could use server side scripting like PHP to get it done. What you're talking about is a template, and is used quite often. What you would want, is to have your menu items (and CSS) and your header/footer code in separate pages. This way, if you make changes to the menu, or header/footer, it would be reflected in all the pages (written with PHP) you have scripted with the template method.

我不相信这是可能的,严格通过 HTML。但是,您可以使用像 PHP 这样的服务器端脚本来完成它。你所说的是一个template,并且经常使用。您想要的是将菜单项(和 CSS)和页眉/页脚代码放在不同的页面中。这样,如果您对菜单或页眉/页脚进行更改,它将反映在您使用模板方法编写脚本的所有页面(用 PHP 编写)中。

You would need the menu.html, header.html and footer.html in a place accessible by your main page code. That is, you would use the template method to write the content of your pages.

您需要将 menu.html、header.html 和 footer.html 放在主页面代码可访问的位置。也就是说,您将使用模板方法来编写页面的内容。

A psuedo code example in PHP would be like such:

PHP 中的伪代码示例如下所示:

<?php
   include('header.html');
   include('menu.html');

    echo "Your main content items here";

   include('footer.html');
?>