html怎么在网页标题栏上添加图标

需求

像下图这样给网页标题栏加个图标
在这里插入图片描述

方法

需要先把图片格式转换为.ico类型
在这个网址在线转换很方便:https://www.easyicon.net/covert/
<head></head>加一行来显示图标(注意,如果加入了没有效果,检查一下路径是否正确,文件名是否正确)
在网页标题左侧显示:<link rel="icon" href="图标地址" type="image/x-icon">
在收藏夹显示图标:<link rel="shortcut icon" href="图标地址" type="image/x-icon">

示例


<head> 
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no"> 
  <title>
    MarioHome
  </title> 
  
  <link rel="icon" href="./mario.ico" type="image/x-icon">  //在网页标题左侧显示图标
  <link rel="shortcut icon" href="./mario.ico" type="image/x-icon">  //在收藏夹显示图标

  <script type="text/javascript" src="D:\\jQuery\\jquery.js"></script>
  <style>

.search { position: relative; width: 78%; margin: 0px auto; padding-left: 3.4em; font-size: 14px;}
.search:after{ clear:both;content:'.'; display:block;clear:both;height:0; visibility:hidden; overflow:hidden;}

.search_t { float: left; width: 78%; height: 60px;margin-left: 0px;  margin-top: 20%; padding-left: 20px; padding-right: 20px; font-size: 18px;/* border: 1px solid #cdcdcd; */border-top-left-radius: 15px; border-bottom-left-radius: 15px; border-top-right-radius: 15px; border-bottom-right-radius: 15px;}
.search_b { float: right;  width: 200px; height: 60px;margin-left: 0px;margin-top: 20%;padding-left: 0px; padding-right: 0px; font-size: 18px;/* border: 1px solid #cdcdcd; */border-top-left-radius: 15px; border-bottom-left-radius: 15px; border-top-right-radius: 15px; border-bottom-right-radius: 15px;}
.background_{ background:url("./background.jpg") no-repeat; background-size: 100%;}
  </style> 
</head> 

<body class="background_">

<form class="search" action="http://www.baidu.com/baidu" target="_blank">
 <input class="search_t" type=text name=word size=40 placeholder="Input Content">
 <input class="search_b" type="submit" value="搜索"/>
</form>

</body>

效果

在这里插入图片描述

  • 42
    点赞
  • 105
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
HTML中,可以通过给`<link>`标签的`rel`属性设置icon属性值来显示标题图标。通常,标题图标也称为网站图标,它会显示在浏览器的标签栏上,用户可以通过它来区分不同的网站。下面是一些步骤来在HTML中显示标题图标: 1. 创建一个图标文件,通常是一个小的16x16像素或32x32像素的图片文件。常见的图标文件格式包括ICO、PNG和GIF等。命名图标文件为`favicon.ico`是一种常见的命名约定。 2. 在HTML文件的`<head>`标签添加一个`<link>`标签,并设置`rel`属性为`icon`,`href`属性为图标文件的路径或URL,如: ```html <head> ... <link rel="icon" href="favicon.ico"> ... </head> ``` 3. 确保图标文件的路径或URL是正确的,可以通过在浏览器中刷新页面来检查是否显示了标题图标。如果图标未显示,可以检查文件路径或URL是否正确,并确保图标文件类型是支持的。 注意事项: - 某些浏览器可能只支持特定的图标文件格式,所以最好使用ICO格式的图标文件。 - 可以在网站的根目录下放置图标文件,并命名为`favicon.ico`,这样浏览器会自动识别并使用它。 - 如果网站有不同的页面,可以在每个页面都添加相同的`<link>`标签来确保所有页面都显示相同的标题图标。 这是在HTML中显示标题图标的简单步骤。通过这些步骤,可以让网站在浏览器标签栏中显示独特的图标,以增强用户体验和品牌识别。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值