【问题标题】:HTML File src/link file paths not workingHTML 文件 src/链接文件路径不起作用
【发布时间】:2018-06-22 18:55:00
【问题描述】:

我有一个 html 文件系统,目前是这样的:

root:
    index.html
    |-css
       -simple-sidebar.css
    |-vendor:
       |-bootstrap:
          |-css:
             -bootstrap.min.css
          |js:
             -bootstrapp.bundle.js
       |-jquery
          -jquery.min.js

使用文件路径完美运行:

 <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
 <link href="css/simple-sidebar.css" rel="stylesheet">
 <script src="vendor/jquery/jquery.min.js"></script>
 <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

但是,当我将所有文件放入名为 static 的文件夹中,并将 index.html 放入名为 templates 的文件夹中时:

 root:
        |-templates:
            -index.html
        |-static
            |-css:
               -simple-sidebar.css
            |-vendor:
               |-bootstrap:
                  |-css:
                     -bootstrap.min.css
                  |js:
                     -bootstrapp.bundle.js
               |-jquery
                  -jquery.min.js

使用这些文件路径:

<link href  ="/static/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/css/simple-sidebar.css" rel="stylesheet">
<script src="/static/vendor/jquery/jquery.min.js"></script>
<script src="/static/vendor/bootstrap/js/bootstrap.bundle.js"></script>

文件加载失败,我做错了什么?

【问题讨论】:

  • 尝试在路径前添加“..”
  • 成功了!谢谢!

标签: html path


【解决方案1】:

只是为了详细说明我的评论:

路径前面需要有../ 而不仅仅是/

../ 放在路径前面可以让您在文件夹结构中上一层
您也可以连续多次使用它来上多个级别。
例如,../../ 会上升 2 级,../../../ 会上升 3 级,等等。

【讨论】:

    猜你喜欢
    • 2023-04-05
    • 2017-03-03
    • 2021-04-23
    • 1970-01-01
    • 2017-07-12
    • 2019-10-08
    • 1970-01-01
    • 2020-12-11
    • 2014-08-10
    相关资源
    最近更新 更多