我正在使用这种格式链接到我的网站图标。
我的 favicon.ico
文件与我的 HTML 文件位于同一目录中,但由于某种原因,当我将它上传到我的网络服务器时它没有出现。我清除了我的缓存,关闭了我的浏览器,然后重新打开它,但仍然没有出现该图标。
如果有人能解释为什么这是我真的很感激。
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
编辑: 我也不知道这是否会影响它,但是我的网络服务器上出现了一个默认的图标。我不知道是否可以覆盖它。
编辑 2: 不确定这是否有所作为,但这是我头脑的基本结构。
<head>
<meta charset="utf-8">
<meta name="author" content="">
<meta name="description" content="Home">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
<title></title>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
</head>
原文由 user1730357 发布,翻译遵循 CC BY-SA 4.0 许可协议
根据这个 答案,它看起来应该是
rel="icon"
而不是rel="shortcut icon"
。Also, if your
favicon.ico
is at the root of your serverhttp://example.com/favicon.ico
and your page is in a subdirectoryhttp://example.com/blog/
, the browser will try searching forfavicon.ico
在当前目录中http://example.com/blog/favicon.ico
,这将导致 404 错误;为避免这种情况,您应该设置href="/favicon.ico"
以便它始终指向根目录,无论您在哪个子目录中。