我有这个问题。Chrome继续返回此错误

资源解释为样式表,但以MIME类型text/html传输

受此错误影响的文件只有Style、chosen和jquery-gentleselect(以相同方式导入索引的其他CSS文件工作良好且没有错误)。我已经检查了我的MIME类型和文本/css已经在css上。

老实说,我想从理解问题开始(这似乎是我一个人做不到的事情)。


当前回答

对于任何可能有这种问题的人。 当我遇到这个问题时,我正在用PHP构建一个自定义MVC。

我能够通过将我的资产(css/js/images)文件设置为绝对路径来解决这个问题。 而不是使用url像href="css/style.css"使用整个当前url来加载它。例如,如果您在http://example.com/user/5,它将尝试在http://example.com/user/5/css/style.css加载。

为了解决这个问题,你可以在资产url的开头添加一个/(即href="/css/style.css")。这将告诉浏览器从url的根目录加载它。在本例中,它将尝试加载http://example.com/css/style.css。

希望这篇评论对你有所帮助。

其他回答

我在为一个用npm安装的React布局模块加载CSS时遇到了这个问题。你必须导入两个.css文件来让这个模块运行,所以我最初导入它们是这样的:

@import "../../../../node_modules/react-grid-layout/css/styles.css";

但发现文件扩展名必须被删除,所以这是有效的:

@import "../../../../node_modules/react-grid-layout/css/styles";

I faced the same issue while configuring Postfix Admin 3.2. According to the official documentation, the whole Postfix Admin content should be extracted into a separate directory, i.e. /srv/postfixadmin and not the document root. Only the /srv/postfixadmin/public directory should be symlinked into /var/www/html document root. I have just extracted the whole content into /var/www/html. Having played with Nginx server block settings, I managed example.com/postfixadmin resolving from /var/www/html/postfixadmin/public. Nevertheless, images and CSS were not available with 404 status code. The stylesheets were broken. I got the error message OP quoted with respective 404 entries in access log.

在我的情况下,我只是移动/var/www/html/postfixadmin到/srv/postfixadmin和ln -s /srv/postfixadmin/公共/var/www/html/postfixadmin。这完全解决了问题。 这是参考资料。

使用的反应

我在我的react profile应用程序中遇到了这个错误。我的应用程序表现得有点像它试图引用一个不存在的url。我相信这与webpack的行为有关。

如果你在公用文件夹中链接文件,你必须记住在资源之前使用%PUBLIC_URL%,就像这样:

<link type="text/css" rel="stylesheet" href="%PUBLIC_URL%/bootstrap.min.css" />

使用角?

这是一个需要记住的非常重要的警告。

基本标签不仅要在头部,而且要在正确的位置。

我有我的基础标签在错误的地方在头部,它应该来之前任何标签与url请求。基本上把它作为标题下面的第二个标签为我解决了这个问题。

<base href="/">

我在这里写了一篇小文章

我最近在chrome浏览器上也遇到了这个问题。我只是给我的CSS文件解决问题的绝对路径。

<link rel="stylesheet" href="<?=SS_URL?>arica/style.css" type="text/css" />