Html 图标不显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11797094/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:02:34  来源:igfitidea点击:

favicon not showing

html

提问by user1548544

I'm trying to add a favicon to my url-bar. But it's not showing up, I'm sure the path is correct because when I use it as a normal image it does show up. Here is the html code:

我正在尝试向我的 url-bar 添加收藏夹图标。但它没有出现,我确定路径是正确的,因为当我将它用作普通图像时,它确实出现了。这是html代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title> title </title>
    <link href = "styles.css" rel="stylesheet" type="text/css" />

    <link rel="icon" type="image/png" href="../images/favicon.png">

回答by A_nto2

First, try to give the full URL istead. For example "http://localhost/mysite/images/favicon.png"(adapt it to your configuration, actually)

首先,尝试提供完整的 URL。例如"http://localhost/mysite/images/favicon.png"(实际上使其适应您的配置)

Otherwise, on my site, this works:

否则,在我的网站上,这有效:

<link rel="shortcut icon" href="images/favicon.ico" />

Try to:

尝试:

  1. convert your png to ico. There are free online tools, for example http://www.convertico.com/
  2. be sure of your folder path. Won't be ./imagesinstead of ../images? Try to give the full URL otherwise. For example "http://localhost/mysite/images/favicon.ico".
  3. after the above steps, try to clear the browser cache and reload the site.
  1. 将您的 png 转换为 ico。有免费的在线工具,例如http://www.convertico.com/
  2. 确保您的文件夹路径。不会./images代替../images吗?否则请尝试提供完整的 URL。例如"http://localhost/mysite/images/favicon.ico"
  3. 完成上述步骤后,尝试清除浏览器缓存并重新加载站点。

回答by Vodun

use <link rel="icon" type="image/png" href="../images/favicon.png">

<link rel="icon" type="image/png" href="../images/favicon.png">

See W3C howto.

请参阅W3C 操作方法

However, the format for the image you have chosen must be 16x16 pixels or 32x32 pixels, using either 8-bit or 24-bit colors.

但是,您选择的图像格式必须是 16x16 像素或 32x32 像素,使用 8 位或 24 位颜色。

回答by xbonez

Your relattribute needs to be iconand not shortcut icon.

您的rel属性必须是 ,icon而不是shortcut icon

There are several ways to set a Favicon, but this is what I use:

有几种方法可以设置 Favicon,但这是我使用的:

<link rel="icon" type="image/png" href="<?= base_url('assets/images/logos/favicon.png'); ?>" />