首页 > 解决方案 > 未找到与 HTML 位于同一文件夹中的 CSS 文件

问题描述

这是一个非常基本的问题,但在过去的一周里,我一直在努力解决这个问题。我刚开始将 CSS 添加到我的项目中,并将 base_style.css 链接到 base.html。由于某种原因,服务器找不到 base_style.css。

基础.html:

<head>
    <title> Chat </title>
    <link href = "base_style.css" type = "text/css" rel = "stylesheet">
    
</head>

base_style.css:

h1 {
    text-align: center;
}

但是,当我通过命令提示符运行服务器时,我得到:

[21/Aug/2020 23:35:25] "GET / HTTP/1.1" 200 517
Not Found: /base_style.css
[21/Aug/2020 23:35:25] "GET /base_style.css HTTP/1.1" 404 5153

即使通过 base_style.css 和 base.html 在同一个文件夹/目录中:

08/18/2020  07:48 PM    <DIR>          .
08/18/2020  07:48 PM    <DIR>          ..
08/21/2020  11:24 PM               584 base.html
08/21/2020  11:24 PM                51 base_style.css
08/17/2020  12:05 AM               622 chatroom.html
08/13/2020  05:03 PM               418 chatrooms.html
08/15/2020  09:53 PM               376 edit_message.html
08/13/2020  05:00 PM               295 index.html
08/13/2020  05:06 PM               272 new_chatroom.html
08/14/2020  04:00 PM               378 new_message.html
               8 File(s)          2,996 bytes
               2 Dir(s)  417,867,866,112 bytes free

如果有人知道发生了什么,我将不胜感激。

标签: htmlcsswebget

解决方案


尝试使用相对路径:

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

推荐阅读