【问题标题】:Load "External" CSS (bootstrap) to specific DIV将“外部”CSS(引导程序)加载到特定的 DIV
【发布时间】:2020-01-06 09:30:39
【问题描述】:

目前我的整个页面都有自己的 CSS 文件

maincss.css 文件已加载到我的主页。

但目前我需要为我的附加模块包含“特定 CSS 文件”,我应该怎么做?

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>

我主页中的一个模块需要上面的代码,我应该如何为那个DIV应用上面的CSS和JS

【问题讨论】:

  • 如果您需要为单个模块包含 Bootstrap,我会考虑编写自己的模块..
  • 在 iframe 中加载它
  • 你可以使用less或sass。检查此问题的答案 (stackoverflow.com/questions/56803915/…)

标签: javascript html css


【解决方案1】:

考虑到您已经编写了自己的 CSS 样式表,包括外部库可能会导致冲突。从外部源编写/复制 CSS 并将其附加到现有的 CSS 文件 maincss.css 中可能符合您的最大利益。

【讨论】:

    【解决方案2】:

    当你写你的 css 时,你应该在链接标签中给出 css 的路径

    【讨论】:

      【解决方案3】:

      附加外部 css 的链接并添加您的 maincss.css。在特定的 DIV 上使用外部 css 指定的类名

      <html>
        <head>
          <meta name="generator" content="HTML Tidy for HTML5 (experimental) for Windows https://github.com/w3c/tidy-html5/tree/c63cc39" />
          <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous" />
      <link rel="stylesheet" href="/css/maincss.css" />
      <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
          <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
          <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
          <title>My Specific DIV</title>
        </head>
        <body>
        <!-- Specific DIV -->
        <div class="container">
        <div class="row">
          <div class="col-sm">
            One of three columns
          </div>
          <div class="col-sm">
            One of three columns
          </div>
          <div class="col-sm">
            One of three columns
          </div>
        </div>
      </div>
        </body>
      </html>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-10-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-19
        • 1970-01-01
        • 2020-10-11
        相关资源
        最近更新 更多