可能有“继承”在HTML? [英] Possible to have "inheritance" in html?

查看:89
本文介绍了可能有“继承”在HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的所有html页面都有一个顶部栏和横幅,其内容相同。
而不是在所有html页面上复制这些内容的代码,是否可以让页面从基本html页面继承内容?



例如: base.html可以有顶部横条,横幅等(所有重复内容)
剩余页面(index.html,about.html等)可以从base.html继承内容,然后添加更多内容。



这是可能的html吗?还是我必须始终复制并粘贴重复内容?

解决方案

在这种情况下(据我所知)


  1. 您可以使用基于模板的编辑器,如Dreamweaver
  2. >
  3. 您可以使用framesets(不要使用它们)。

  4. 您可以使用iframe(meh。)

  5. 可以将文件转换为PHP,并使用单个包含命令(Y)复制并粘贴整个文件,当您获得100页时,尝试添加一个新菜单...
  6. li>

我也想看看其他解决方案。



E xample:

可以说我创建了一个 template.html ,就像

 < HTML> 
< head>
< title> asd< / title>
风格标签关键字bla bla bla
< / head>
< body>
< div class =menu>
是啊我的菜单设计得很好
< / div>
< div class =content>
独特的内容在这里
< / div>
< / body>
< / html>

好的,这是我的一个html文件。让我们拿到页面的顶部。菜单将是相同的,但内容将被改变,所以这是页面的顶部:

 < html> 
< head>
< title> asd< / title>
风格标签关键字bla bla bla
< / head>
< body>
< div class =menu>
是啊我的菜单设计得很好
< / div>

将此部分保存为 top.php 现在让我们看看我们还剩下什么:

 < div class =content> 
独特的内容在这里
< / div>
< / body>
< / html>

这将是我们的帖子页面。但是,我们如何从top.php获取代码?就像那样:

 <?php include(top.php); ?> 
< div class =content>
独特的内容在这里
< / div>
< / body>
< / html>

现在,将其保存为 page1.php BINGO!你没有写关于菜单的关于,但包含方法会为你带来。



包括基本上写入从文件到另一个文件的所有内容。您可以检查include_once,require和require_once的差异。



好的,我们创建了第一页。第二个呢?完全相同:

 <?php include(top.php); ?> 
< div class =content>
我的第二页在这里
< / div>
< / body>
< / html>

另存为 page2.php $ b

好吧,您现在需要更改菜单,但有两页,两百页,两百万页...谁在乎。只需更改 top.php 即可。



请注意,在此代码中, top.php,page1.php和page2.php位于SAME目录中。如果你想包含其他路径,你必须使用例如:

 <?php include(../ top .PHP); ?> 
// OR
<?php include(myFiles / theme / top.php);?>

,具体取决于你的路径。



我希望这有助于你阅读包含PHP的指南,这非常简单。
$ b

您需要测试服务器(或者您可以使用本地服务器,如WAMP,XAMP等)执行PHP文件。


Let's say all of my html pages will have a top bar and banner with the same content. Rather than copy the code for these content on all html pages, is it possible to have pages inherit the content from a base html page?

For example : base.html can have the top bar, banner, etc (all repeated content) Remaining pages (index.html, about.html, etc) can inherit the content from base.html and then add more content.

Is this possible in html or do I have to copy and paste repeating content all the time?

解决方案

In this situations (as far as I know)

  1. You can use template based editors like Dreamweaver
  2. You can use framesets (don't use them)
  3. You can use iframe (meh.)
  4. You can convert your files to PHP and just use a single include command (Y)
  5. Copy and paste whole thing and when you get 100 pages, try to add a new menu...

I'd like to see other solutions too.

Example:

Lets say I've created a template.html it's something like

<html>
   <head>
    <title>asd</title>
    style tags keywords bla bla bla 
   </head>
<body>
   <div class="menu">
      yeah I've my menu here well designed
   </div>
   <div class="content">
      unique content here
   </div>
</body>
</html>

Allright this is my one html file. Lets take top section of the page. Menu will be same but content will be changed so this is top of the page:

<html>
   <head>
    <title>asd</title>
    style tags keywords bla bla bla 
   </head>
<body>
   <div class="menu">
      yeah I've my menu here well designed
   </div>

Save this part as top.php Now let's see what have we left:

<div class="content">
          unique content here
       </div>
    </body>
    </html>

This will be our post page. But how can we get codes from top.php? Just like that:

<?php include("top.php"); ?>
<div class="content">
          unique content here
       </div>
    </body>
    </html>

Now, save this as page1.php BINGO! You did not wrote anthing about menu but include method will bring it for you.

Include basically writes everything from a file to another. You can check differences for include_once, require, require_once too.

Allright, we've created our first page. What about second one? Exactly the same:

<?php include("top.php"); ?>
<div class="content">
          my second page here
       </div>
    </body>
    </html>

Save this as page2.php

Well, you need to change your menu now but there are two pages, two hundred pages, two million pages... Who cares. Just change top.php that's all.

Please note that in this codes; top.php, page1.php and page2.php are in SAME directory. If you want to include from another path, you must use for example:

<?php include("../top.php"); ?>
//OR
<?php include("myFiles/theme/top.php); ?>

depending on your path.

I hope this helps. Read PHP guides for include. It's really easy.

You need a testing server (or you can use a local server like WAMP, XAMP etc.) to execute PHP files.

这篇关于可能有“继承”在HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆