【问题标题】:include header in html在html中包含标题
【发布时间】:2016-01-31 08:58:47
【问题描述】:

如何在索引文件中包含正确的标题。我希望可以编辑我的标题,因为它在我的所有页面上。

假设我有一个标题:

<nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation">
        <div class="container topnav">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand topnav" href="#">Start Bootstrap</a>
            </div>
         </div>
    </nav

这段代码我已经复制到我的 header.php 中,所以我只有一次可以编辑它的地方。上面这段代码应该在body标签里面,还是我需要在我的头文件中有html、head和body标签?

<html>
<head>

</head>
<body>
   <-!-- Code here -->
</body>
</html>

【问题讨论】:

  • 我不明白«或者不需要在那里使用html»是什么意思,顺便说一句,是的,你应该把它放在body标签中。 See more
  • 使用 PHP 的 include 构造

标签: php html


【解决方案1】:
<html>
<head>
<!-- Latest compiled and minified CSS -->
 <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<!-- jQuery library -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

  <!-- Latest compiled JavaScript -->
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js">     </script>
  </head>
  <body>

<nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation">
    <div class="container topnav">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand topnav" href="#">Start Bootstrap</a>
        </div>
     </div>
</nav>
   </body>
  </html>

我相信你正在使用 BOOTSTRAP

【讨论】:

  • 啊,好吧,所以我还需要在该页面上包含 javascript、css 等。我实际上把它放在我的索引页上。谢谢
【解决方案2】:

鉴于所有文件都包含 PHP 代码,所有文件都应具有 .php 扩展名。

然后你可以像这样包含任何你想要的 HTML 粒子:将头文件命名为 header.php,将页脚文件命名为 footer.php: 等等。

<html>
<head>

</head>
<body>
     <?php include 'header.php'; ?>
       <-!-- Code here -->
     <?php include 'footer.php'; ?>
</body>
</html>

【讨论】:

    猜你喜欢
    • 2020-10-01
    • 1970-01-01
    • 2016-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-03
    • 2019-07-04
    • 2016-01-26
    相关资源
    最近更新 更多