Html 如何使用CSS设置页面图标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17481295/
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
How to set icon of an page using CSS
提问by Mr. Alien
Is it possible to have this code:
是否有可能有这个代码:
<link rel="icon" href="icon.gif" />
Using css document?
使用css文件?
(I would rather not have to go through and add that to every pages) and is it possible to set title of page using css(I am not gonna use it as all pages have different title but just for general info)
(我宁愿不必通过并将其添加到每个页面)并且是否可以使用 css 设置页面标题(我不会使用它,因为所有页面都有不同的标题,但仅用于一般信息)
回答by Mr. Alien
You cannot set the favicon using CSS.... You need to use a link
tag with rel
value of shortcut icon
.
使用CSS,你不能设置图标....你需要使用link
标签与rel
价值shortcut icon
。
Inorder to set that, you need to put the below string in between the <head>
tags..
为了设置它,您需要将以下字符串放在<head>
标签之间..
<link rel="shortcut icon" href="favicon.ico" />
-----^-----
<!--Remember to have .ico as the extension else
some browsers fail to load other extensions -->
You need to also specify the type attribute here type="image/x-icon"
if IE fails to load your favicon, if it loads fine, you can just ignore the type
attribute.
type="image/x-icon"
如果 IE 无法加载您的收藏夹图标,您还需要在此处指定 type 属性,如果加载正常,您可以忽略该type
属性。
回答by Mr. Alien
You can't do it using CSS it can only be done by inserting
你不能使用 CSS 来完成它只能通过插入来完成
<link rel="icon" href="icon.gif" />
as you have described above.. CSS is used to format some text/images etc in the page and and there is nothing to format in icon let me guess if you are working on many pages you probably have either a blog or an script to generate pages just add this line of text in it.. And you can always change icon of each page at once by just changing the icon itself...:)
正如你上面所描述的.. CSS 用于格式化页面中的一些文本/图像等,并且图标中没有任何可格式化的内容让我猜你是否正在处理许多页面,你可能有一个博客或脚本来生成页面只需在其中添加这一行文本..您可以随时更改每个页面的图标,只需更改图标本身即可...:)
回答by Navneet Kumar
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
In href, you have to pass the image url.
在 href 中,您必须传递图片网址。
回答by Tredged
You can't set a favicon from CSS - if you want to do this explicitly you have to do it in the markup as you described.
您不能从 CSS 设置图标 - 如果您想明确地执行此操作,则必须按照您的描述在标记中执行此操作。
Most browsers will, however, look for a favicon.ico file on the root of the web site - so if you access http://example.commost browsers will look for http://example.com/favicon.icoautomatically.
但是,大多数浏览器会在网站根目录上查找 favicon.ico 文件 - 因此,如果您访问http://example.com,大多数浏览器会自动查找http://example.com/favicon.ico。
回答by Swarnamayee Mallia
Here is the combination of combination of .ico and .gif image
这是 .ico 和 .gif 图像的组合
<link rel="shortcut icon" href="favicon.ico">
<link rel="icon" type="image/gif" href="animated_favicon1.gif">