前往:HTML找不到CSS档案

So i'm writing a web application in Golang. The html references a css file like so: <link href="/css/index.css"..., but the css file is never found!.

Here is the bummer though, i have a couple of css files and they are all in the same folder, and they all work!.

If i create another css file and name it index2.css and copy the contents of index.css into index2.css, this works perfectly, but for some reason, the name index.css does not work!

Also, when i go to the link http://localhost:8080/css/ this list all my css files. If i click on any of them, it opens up perfectly except index.css; i get a 404 not found.

This is really strange, any idea what could be the problem?

All files in css folder:

enter image description here

index.css not found:

enter image description here

<head>
    <title>Title</title>
    <link href="/css/index2.css" rel="stylesheet" type="text/css" media="screen"/>
    <link rel="icon" type="image/png" href="/images/img.png"/>
    <script src="/scripts/jquery.min.js"></script>
    <script src="/scripts/scroll.js"></script>
</head>

When i like to <link href="/css/index2.css" rel="stylesheet"... i can see the css style on my page. When i link to <link href="/css/index.css" rel="stylesheet"... i can't.

index.css exists in my folder:

enter image description here

EDIT

It works now. I think it was a permission issue. I deleted the old index.css and created a new one and it works now. Thanks for the help.

dongzhunqiu4841
dongzhunqiu4841 嗯。这可能是权限问题。我删除了旧的,并创建了新的,现在可以使用了。有趣的是,我之前曾这样做过,但仍然无法正常工作。哦好吧,我想欢迎您来编程...
3 年多之前 回复
dpt1712
dpt1712 路径正确吗?
3 年多之前 回复
doulu3808
doulu3808 如果您使用的是Mac或Linux,则应检查index.css的权限。
3 年多之前 回复
dqxyh48864
dqxyh48864 对不起。该代码只是纯html,认为没有用。但是我刚刚上传了一些代码以及一些图片
3 年多之前 回复
drpph80800
drpph80800 没有代码源就很难回答。
3 年多之前 回复
douguai6716
douguai6716 您必须显示的代码。
3 年多之前 回复

2个回答



您是否在服务器端脚本中将css文件夹标记为静态? 尝试从Go Web服务器运行此代码,看看是否可以访问这些CSS文件。</ p>

 程序包main 

import(
“ net / http”

func main(){
http.Handle(“ /”,http.FileServer(http.Dir(“ ./ web / content / css”)))
http.ListenAndServe(“:8080”,nil )
}
</ code> </ pre>

我不确定我的文件夹结构是否正确,您可能需要修改“ ./web/content/css”。< / p>
</ div>

展开原文

原文

Did you mark the css folder as static in your server side script? Try running this code from your go web server and see if you could access those css files.

package main

import (
    "net/http"
)

func main() {
    http.Handle("/", http.FileServer(http.Dir("./web/content/css")))
    http.ListenAndServe(":8080", nil)
}

I'm not sure if I got your folder structure right, you might have to modify "./web/content/css".



可能是由于-</ p>

1.Temp文件引起的,请尝试查找索引 .css〜文件。如果使用Ubuntu,请转到css文件夹,然后按 ctrl + H </ code>。 那么您将看到临时文件(如果有)。 </ p>

2。可能是路径不正确。</ p>

3。可能是文件损坏,请尝试删除并创建新的index.css </ p>

4。提供源代码以调试问题。 </ p>
</ div>

展开原文

原文

May be this problem is because of -

1.Temp file, try to find index.css~ file.If using Ubuntu then go to the css folder and press ctrl+H. then you will see the temp file if it is there.

2.May be path is not correct.

3.May be file got corrupted, try to delete and create new index.css

4.Provide your source code to debug your issue.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐