我一直在做一个网站,我想在浏览器标签中添加一个小图标。
如何在 HTML 中执行此操作,以及我需要将其放置在代码的什么位置(例如标题)?我有一个 .png
Logo 文件,我想将其转换为图标。
相关:HTML set image on browser tab .
最佳答案
实际上有两种方法可以将网站图标添加到网站。
<link rel="icon">
只需将以下代码添加到 <head>
元素:
<link rel="icon" href="http://example.com/favicon.png">
PNG 网站图标 are supported by most browsers, except IE <= 10 .为了向后兼容,您可以使用 ICO favicons。
请注意,您不必在 icon
之前在 rel
shortcut
的属性 了。来自 MDN Link types :
The
shortcut
link type is often seen beforeicon
, but this link type is non-conforming, ignored and web authors must not use it anymore.
favicon.ico
在根目录中来自 another SO answer (作者 @mercator ):
All modern browsers (tested with Chrome 4, Firefox 3.5, IE8, Opera 10 and Safari 4) will always request a
favicon.ico
unless you've specified a shortcut icon via<link>
.
所以你所要做的就是制作 /favicon.ico
请求您的网站返回您的网站图标。遗憾的是,此选项不允许您使用 PNG 图标。
另见 favicon.png vs favicon.ico - why should I use PNG instead of ICO?
https://stackoverflow.com/questions/4888377/