简体   繁体   English

无法将index.html文件链接到另一个文件夹中的style.css文件

[英]Cannot link index.html file to style.css file in another folder

I'm trying to link my style.css file to my index.html file. 我正在尝试将style.css文件链接到index.html文件。 Both files are located in separate folders. 这两个文件位于单独的文件夹中。

Folder structure: 资料夹结构:

/parent /父母

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

Codes that I have tried using: 我尝试使用的代码:

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

The same error I keep getting in the terminal: 我不断进入终端的相同错误:

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

I'm using VS Code with live-server. 我在实时服务器上使用VS Code。

Note: When I put my index.html file outside src folder in the parent folder. 注意:当我将index.html文件放在src文件夹之外的父文件夹中时。 The path href="css/style.css" works. 路径href =“ css / style.css”有效。

Start live-server in the Root /parent , then navigate to /src/index.html . 在Root /parent启动实时服务器 ,然后导航至/src/index.html If you start in the directory containing index.html you can Not go upwards. 如果从包含index.html的目录开始,则不能向上移动。

您的href看起来应该像这样:href =“ style.css”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM