Html 内容 url 在 Firefox 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12262118/
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
content url is not working in Firefox
提问by selva_pollachi
My CSS file is:
我的 CSS 文件是:
#name_wrong_img
{
width:43px;
height:29px;
}
This is my HTML code:
这是我的 HTML 代码:
<img id="name_wrong_img" src="wrong.jpg" />
The above code is working well in both Firefox and Chrome.
上面的代码在 Firefox 和 Chrome 中运行良好。
#name_wrong_img
{
content:url(wrong.jpg);
width:43px;
height:29px;
}
<img id="name_wrong_img" />
This is working well in Chrome. But not in Firefox. What is the problem in this?
这在 Chrome 中运行良好。但不是在 Firefox 中。这有什么问题?
回答by Quentin
Firefox doesn't support the content
property in the same way as Chrome — on img
elements and/or when the source is an image.
Firefox 不content
以与 Chrome 相同的方式支持该属性——在img
元素上和/或当源是图像时。
<img>
represents a content image. If you use it, it should have a src
and an alt
.
<img>
表示内容图像。如果你使用它,它应该有一个src
和一个alt
。
From the specification:
从规范:
The src attribute must be present, and must contain a valid non-empty URL potentially surrounded by spaces referencing a non-interactive, optionally animated, image resource that is neither paged nor scripted.
src 属性必须存在,并且必须包含一个有效的非空 URL,该 URL 可能被空格包围,引用非交互式的、可选的动画图像资源,既不分页也不脚本化。