【问题标题】:Cannot link index.html file to style.css file in another folder无法将 index.html 文件链接到另一个文件夹中的 style.css 文件
【发布时间】:2019-12-28 06:29:36
【问题描述】:

我正在尝试将我的 style.css 文件链接到我的 index.html 文件。这两个文件都位于不同的文件夹中。

文件夹结构:

/父母

  • /src/index.html
  • /css/style.css

我尝试使用的代码:

<link rel="stylesheet" type="text/css" href="../css/style.css">
<link rel="stylesheet" type="text/css" href="./css/style.css">
<link rel="stylesheet" type="text/css" href="/css/style.css">
<link rel="stylesheet" type="text/css" href="css/style.css">

我在终端中不断遇到同样的错误:

GET /css/style.css 404 1.542 毫秒 - 152

我正在使用带有实时服务器的 VS Code。

注意:当我将 index.html 文件放在父文件夹中的 src 文件夹之外时。路径 href="css/style.css" 有效。

【问题讨论】:

  • 试试 ../../css/style.css
  • @Albeis 同样的错误。

标签: html css simplehttpserver npm-live-server


【解决方案1】:

在根/parent 中启动live-server,然后导航到/src/index.html。 如果从包含index.html的目录开始就不能往上走。

【讨论】:

    【解决方案2】:

    您的 href 应如下所示:href="style.css"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-28
      • 2011-04-26
      • 2016-03-22
      • 2014-08-13
      • 2016-11-06
      • 2019-09-02
      • 1970-01-01
      • 2021-03-22
      相关资源
      最近更新 更多