html - 无法将 index.html 文件链接到另一个文件夹中的 style.css 文件
问题描述
我正在尝试将我的 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">
我在终端中不断遇到同样的错误:
获取 /css/style.css 404 1.542 毫秒 - 152
我将 VS Code 与实时服务器一起使用。
注意:当我将 index.html 文件放在父文件夹中的 src 文件夹之外时。路径 href="css/style.css" 有效。
解决方案
在 Root 中启动live-server/parent
,然后导航到/src/index.html
. 如果你从包含index.html
你的目录开始就不能往上走。
推荐阅读
- python - 如何比较聚合后的列(Python,pandas)?
- python - 我的计算密集型 Numba 函数在 GPU 上的运行速度比在 CPU 上慢 10 倍。我错过了什么吗?
- javascript - 如何使用 ajax 删除或发布数据(POST,DELETE)
- php - Eloquent 'hasOne' 同时选择 Id 和 id 后面的对象
- php - mysqlCount 不能与 join 一起使用,显示错误的结果
- powershell - 集成的 powershell 核心在 vscode 终端中不起作用
- python - PyQt-Fit 安装失败
- docker - 盖茨比:环境变量 .env 返回未定义
- amazon-web-services - CloudWatch 警报错误百分比 API 网关
- pyspark - Spark Structure Streaming 中的临时视图