为什么我的html导入标签不起作用?

问题描述 投票:1回答:2

我一直在研究代码可重用性(例如)并且一直在试验HTML导入标签。我想在每个网页中自动包含我的引导代码,并希望使用一行代码而不是多行代码。

在网上做了一些研究后,答案似乎是使用标签,大多数是以下格式:

<head>
    <import rel="import" href="includes/bootstrap.html">
</head>

我的bootstrap.html文件只是一些正常的bootstrap链接,如下所示:

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

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

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

我只是想避免在我的所有页面中导入相同的三行。但是,我的浏览器(Chrome)似乎没有以任何方式实现包括,即使我使用Bootstrap以外的原因。

我应该如何在我的所有页面的头部正确包含我的引导程序文件?

亚历克斯

html css twitter-bootstrap
2个回答
1
投票

将导入标记更改为链接标记

<head>
    <link rel="import" href="includes/bootstrap.html">
</head>

请参阅this


1
投票

如何用这样的链接创建头文件'header.php',

<head>
<title>Your Title</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" ></script>
</head>

当你编写代码时,只需要包含header.php部分。

<html>
<? include ("header.php");?>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.