Firefox 3 外部 css 出现语法错误
当使用以下 html/css:
foo.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<link rel="stylesheet" href="foo.css"/>
</head>
<body>
Foo
</body>
</html>
foo.css: 时,我在 Firefox 3.0.10/Leopard 中遇到奇怪的语法错误: foo.html: foo.css:
div {
color: #FF0000;
}
我在控制台中得到的错误是:
Error: syntax error
Source File: file://path/to/foo.css
Line: 1, Column: 1
Source Code:
div {
It's not the CSS,because Paste it into the body内联 STYLE 标签的效果很好。 它不是链接标记,因为将 HREF 指向堆栈溢出的 css 文件不会给出错误。 感觉像是 Firefox 的 bug,但我找不到任何相关文档。 这是一个已知问题吗?有解决方法吗? 这使得调试或验证变得困难。
谢谢。
I get a strange syntax error in Firefox 3.0.10/Leopard when using the following html/css:
foo.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<link rel="stylesheet" href="foo.css"/>
</head>
<body>
Foo
</body>
</html>
foo.css:
div {
color: #FF0000;
}
and the error I get in the console is:
Error: syntax error
Source File: file://path/to/foo.css
Line: 1, Column: 1
Source Code:
div {
It's not the CSS, because pasting it into the body of an inline STYLE tag works fine.
It's not the link tag, because pointing the HREF to stack overflow's css file doesn't give an error.
Feels like a Firefox bug, but I can't find any documentation on it.
Is this a known issue, and is there a workaround? It makes it hard to debug or validate.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
它会在文件中的第一个字符(即“d”)上给您错误,这对我来说排除了诸如“隐藏”特殊字符之类的内容。 我猜想 Firefox 出于某种原因无法在本地打开该文件,或者该文件意外地使用某种编码保存,尽管该编码在对话框中显示良好,但无法正常解析。 也许它被错误地保存为 Unicode?
如果您可以将我们链接到实际文件,那将会有所帮助,因为您的语法(尽管标记并不完全有效,但我不认为就是这样)在您粘贴的 .css 文件中是完美的。
It's giving you the error on the first character in the file, which is a 'd', which rules out things like "hidden" special characters to me. I'd guess that firefox isn't able to open the file locally for whatever reason, or that the file was accidentally saved with an encoding that, although it displays fine in the dialog box, doesn't parse normally. Perhaps it's saved as Unicode by mistake?
If you could link us to the actual file it would help, since your syntax (despite the markup not being exactly valid, but I don't think that's it) is perfect in the .css file you pasted in.
正如评论中所建议的,答案是“关闭扩展(这是 YSlow)”。
The answer turned out to be "Turn off extensions (it was YSlow)" as suggested in the comments.
文件是在windows上写的吗? 也许您需要将回车/新行重新格式化为 mac os x。 尝试在命令行上通过类似 dos2unix 的方式运行该文件。 也可能是您没有看到的 bom。
Was the file written on windows? Maybe you need to reformat the carriage return/new line to mac os x. try running the file through something like dos2unix on the command line. Could also be a bom you're not seeing.
我的猜测是,文件中可能意外保存了一些隐藏字符。 尝试重新保存 CSS 文件,或重新键入第一行,然后重新保存。
My guess is that there's some hidden character that might have been accidentally saved in the file. Try re-saving the CSS file, or re-typing the first line and then re-saving it.
如果您来自 Google,并且使用本地 html,请注意,Firefox 会阻止对使用
file://
协议的外部 CSS 的请求,因为它在技术上是跨域请求。快速解决方法是通过
http://
将包含您站点的目录提供给本地主机。 如果您安装了 python 解释器,则可以非常轻松地执行此操作:然后通过浏览器访问 localhost:
您可以将
8080
替换为任何其他端口。If you're here from Google and working with local html, note that Firefox blocks requests for external CSS that use the
file://
protocol because it's technically a cross-origin request.A quick fix is to serve the directory that contains your site to localhost over
http://
. If you have the python interpreter installed, you can do this very easily:Then access localhost through your browser:
You can replace
8080
with any other port.