如何解决找不到与HTML相同文件夹中的CSS文件
这是一个非常基本的问题,但是在过去的一周里,我一直在努力地解决这个问题。我刚刚开始将CSS添加到我的项目中,并将base_style.css链接到base.html。由于某种原因,服务器找不到base_style.css。
Base.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
如果有人知道发生了什么,我将为您提供帮助。
解决方法
尝试使用相对路径:
<link href = "./base_style.css" type = "text/css" rel = "stylesheet">
,
从private constexpr
运行应用程序时,您需要指定server
的路径
如果文件夹结构是这样的:root directory
然后路径将为web-app > public > base_style.css
因此:
public/base_style.css
从您的根文件夹指定路径,它将起作用:)
,要在服务器调用的HTML代码中添加CSS文件,必须从项目的基本目录开始路径。
应该是这样的:
<head>
<title> Chat </title>
<link href = "<path from project base dir to current dir>/base_style.css" type = "text/css" rel = "stylesheet">
</head>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。