【问题标题】:import HTML to HTML将 HTML 导入 HTML
【发布时间】:2019-01-19 16:32:18
【问题描述】:

我需要将A.html和B.html和C.html导入Index.html

我尝试的方式.....它可以工作, 但不知道只有一个是正常的, 其他没有与他们的 css 链接


下面是我的 index.html

它可以工作,但只有 D.html 是链接它的 css。 其他人的 css 布局看起来不正确。

<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="css/A.css">
<link rel="stylesheet" href="css/B.css">
<link rel="stylesheet" href="css/C.css">
<link rel="stylesheet" href="css/D.css">


<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" defer></script>
<section ng-app="">
  <div ng-include="'section/A.html'"></div>
  <div ng-include="'section/B.html'"></div>
  <div ng-include="'section/C.html'"></div>
  <div ng-include="'section/D.html'"></div>
</section>

【问题讨论】:

  • 显示A、B、C、D内的代码
  • 但是太多......
  • 我们无法为您提供这么少的信息,这就像向我们展示汽车的窗户并询问我们发动机出了什么问题。
  • 我发现总是靠近 的可以捕捉到自己的 CSS,而其他的则不能——

标签: jquery html angularjs ajax


【解决方案1】:

这是我为帮助您解决问题而做的一个 codepen 项目: https://codepen.io/ideaguy3d/project/editor/AdzPdm

我刚刚添加了一个 Angular 应用并将 ng-app 指向它:

app.js:

angular.module('myApp', []);

index.html:

```

   <section ng-app="myApp">

        <div ng-include="'section/A.html'"></div>
        <div ng-include="'B.html'"></div>

    </section>

```

确保您的项目中也有一个名为“section”的文件夹。

【讨论】:

  • 非常感谢。但是A.html如何链接到A.css,B.html如何链接到B.css?
  • 我发现总是靠近 的可以捕捉到自己的 CSS,而其他的则不能
  • 按类名和特异性。如果您有styles.css 有一个样式a-include-section some-descendant {color: "red"},那么在A.html 中有&lt;section class = "a-include-section"&gt;&lt;div class = "some-descendant"&gt;&lt;/div&gt;&lt;/section&gt; 并记住在您的head 元素中包含styles.css。如果还有其他样式具有更高的特异性,那么您可能不得不求助于使用 id
猜你喜欢
  • 1970-01-01
  • 2021-12-01
  • 1970-01-01
  • 2021-09-24
  • 2012-02-13
  • 1970-01-01
  • 2020-04-27
  • 2018-07-28
  • 2023-03-12
相关资源
最近更新 更多