Javascript “样式表未加载,因为它的 MIME 类型,“text/html”不是“text/css”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2190459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"The stylesheet was not loaded because its MIME type, "text/html" is not "text/css"
提问by Suraj Chandran
I have a javascript application and when I run it on firefox I am getting the following erro on the console:
我有一个 javascript 应用程序,当我在 Firefox 上运行它时,我在控制台上收到以下错误:
"The stylesheet was not loaded because its MIME type, "text/html" is not "text/css".
“样式表未加载,因为它的 MIME 类型,“text/html”不是“text/css”。
DumbStuck!!
哑巴!!
EDIT: Note that it tells that "The stylesheet ABCD..." But ABCD is actually an HTML file.
编辑:请注意,它告诉“样式表 ABCD...”但 ABCD 实际上是一个 HTML 文件。
Edit (ANSWER) : Actually I had wrongly put href="", and hence the html file was refenecing itself as the CSS. Mozilla had the similar bug once, and it is from there I got the answer. But everyone's else answers helped me too. Thanks.
编辑(答案):实际上我放错了href="",因此 html 文件将自己作为 CSS 引用。Mozilla的过类似的错误一次,它是从那里我得到了答案。但其他人的答案也帮助了我。谢谢。
采纳答案by Suraj Chandran
回答by tfentonz
In the head section of your html document:
在 html 文档的 head 部分:
<link rel="stylesheet" type="text/css" href="/path/to/ABCD.css">
Your css file should be css only and not contain any markup.
您的 css 文件应该仅为 css 并且不包含任何标记。
回答by Anum Sheraz
This is more likely an issue at your server side. you request style sheet page "Styles/Site.css" from the server of type "text/css", but your server might be responding to this request with "test/html". I had this issue when my server was running in python and it was replying to requested css files with header text/html (as that of my index.html file). I re-arranged my server code and assigned the correct headers to its corresponding pages and my issue got resolved.
这更有可能是您服务器端的问题。您从“text/css”类型的服务器请求样式表页面“Styles/Site.css”,但您的服务器可能会使用“test/html”响应此请求。当我的服务器在 python 中运行时,我遇到了这个问题,它正在用标题文本/html(如我的 index.html 文件)回复请求的 css 文件。我重新安排了我的服务器代码并将正确的标题分配给其相应的页面,我的问题得到了解决。
回答by Ms2ger
You are trying to use it as a CSS file, probably by using
您正在尝试将其用作 CSS 文件,可能是通过使用
<link rel=stylesheet href=ABCD.html>
or
或者
<style>
@import url("ABCD.html");
</style>
回答by christian
Review any .htaccess. Maybe, a .htaccess rule is interfering with the right output. Try browsing your CSS resource directly in your address bar, it must be presented in text format.
查看任何 .htaccess。也许,.htaccess 规则干扰了正确的输出。尝试直接在地址栏中浏览您的 CSS 资源,它必须以文本格式呈现。
回答by Areeb Soo Yasir
This is what did it for me in .htaccess (it could be that you had a directive making all files load as MIME type text/html):
这就是在 .htaccess 中为我做的事情(可能是你有一个指令使所有文件加载为 MIME 类型文本/html):
In .htaccess
在.htaccess中
AddType text/css .css
回答by JC Lopez
In Ubuntu In the conf file: /etc/apache2/sites-enabled/your-file.conf
在 Ubuntu 中的 conf 文件中:/etc/apache2/sites-enabled/your-file.conf
change
改变
AddHandler application/x-httpd-php .js .xml .htc .css
to:
到:
AddHandler application/x-httpd-php .js .xml .htc

