深入了解HTML中的<head>标签

大致分为三个方面:描述网页基本信息,指向渲染网页需要的其他文件的链接,各大厂商根据自己需要制定。

网页基本信息

  • 文档标题(浏览器标签中显示的文本):<title>深入了解 head 元素</title>
  • 编码格式:<meta charset="utf-8">(你可能还看到 gb2312格式,不过不建议使用),如果你的页面出现乱码,那一般就是编码格式不对
  • 视窗设置:<meta name="viewport" content="width=device-width, initial-scale=1.0">
  • 搜索引擎优化相关内容: <meta name="description" content=“帮助你深层次了解HTML文档结构”>
  • IE浏览器版本渲染设置:<meta http-equiv="X-UA-Compatible" content="ie=edge">

其他文件链接

一个完整的网页光有 HTML 结构是非常简陋的,就如一个毛坯房。有了结构之后,我们还需要加入样式与行为为网页增添色彩。

  • CSS 文件:<link rel="stylesheet" type="text/css" href="style.css">
  • JavaScript 文件:<script src=“script.js"></script>

厂商定制

比喻开启双核浏览器先河的360浏览器就定制了一个默认使用哪个内核来渲染页面,可以设置为webkit内核、IE标准,IE兼容三种模式。代码分别为:

<meta name="renderer" content="webkit"> <!-- 默认webkit内核 --> 
<meta name="renderer" content="ie-stand"> <!-- 默认IE标准模式 --> 
<meta name="renderer" content="ie-comp"> <!-- 默认IE兼容模式 --> 

同样分享页面到QQ的聊天窗口,有些页面直接就是一个链接,但是有些页面有标题,图片,还有文字介绍。为什么区别这么明显呢?其实就是看有没有设置下面这三个内容(具体参阅:腾讯移动WEB开发平台)。

<meta itemprop="name" content="这是分享的标题"/> <meta itemprop="image" content="http://imgcache.qq.com/qqshow/ac/v4/global/logo.png" /> <meta name="description" itemprop="description" content="这是要分享的内容" /> 

还有IOS也定制了一些移动开发设置如下:

<meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="black" /> <link rel="apple-touch-icon" href="touch-icon-iphone.png"> <link rel="apple-touch-startup-image" href="/startup.png"> 

参考资料

猜你喜欢

转载自www.cnblogs.com/Eric178/p/9100134.html
今日推荐