这是我的 HTML 文件的路径: C:\Users\Lorenzo\Desktop\Capstone Project\HTML\index.html
这是我的 CSS 文件的路径: C:\Users\Lorenzo\Desktop\Capstone Project\CSS\style.css
最佳答案
添加
<link rel="stylesheet" type="text/css" href="../CSS/style.css">
// or
<link rel="stylesheet" type="text/css" href="..\\CSS\\style.css">
到你的 index.html
文件
注意:如果您在 VSCode 上使用Live Server
(像我一样)。您必须使用文件夹 Capstone Project\
打开 VSCode,而不是 HTML\
,否则您会遇到错误
Refused to apply style from 'http://localhost:3000/CSS/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
那个错误已经讨论过here
关于html - 我想在我的 HTML 文件中链接到我的外部 CSS 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59510725/