首页 > 解决方案 > 无法将 index.html 文件链接到另一个文件夹中的 style.css 文件

问题描述

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

文件夹结构:

/父母

我尝试使用的代码:

<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">

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

获取 /css/style.css 404 1.542 毫秒 - 152

我将 VS Code 与实时服务器一起使用。

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

标签: htmlcsssimplehttpservernpm-live-server

解决方案


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


推荐阅读