下面介紹下常用的head頭部結(jié)構(gòu),以及對各個標簽、元素的意義以及使用場景一一介紹(本篇以一絲大神的文章為基礎,進行擴展總結(jié))。
padding.me的head頭結(jié)構(gòu)
代碼如下:
<!DOCTYPE HTML>
<html lang="zh-cmn-Hans">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=yes">
<meta name="keywords" content="PaddingMe,front-end,前端,前端工程師,web開發(fā)工程師,HTML,CSS,JavaScript,HTML5,CSS3,git,Github">
<meta name="description" content="PaddingMe - he is a front-end developer.">
<meta name="robots" content="index,follow">
<meta name="author" content="PaddingMe,padding4me@gmail.com"></p> <p> <meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta></p> <p> <meta http-equiv="Cache-Control" content="no-siteapp"></p> <p> <title>PaddingMe</title>
<link rel="shortcut icon" type="image/x-icon" href="../favicon.ico"></p> <p> <link rel="author" href="<a href="
<link type="text/plain" rel="author" href="<a href="
<link rel="stylesheet" href="/css/font.css"> <link rel="stylesheet" href="/css/social.css"> <link rel="alternate" type="application/atom+xml" title="Atom 1.0" href="<a href="
</head> DOCTYPE DOCTYPE(Document Type),該聲明位于文檔中最前面的位置,處于html標簽之前,此標簽告知瀏覽器文檔使用哪種HTML或者XHTML規(guī)范。 DTD(Document Type Definition)聲明以<!DOCTYPE>開始,不區(qū)分大小寫,前面沒有任何內(nèi)容,如果有其他內(nèi)容(空格除外)會使瀏覽器在IE下開啟怪異模式(quirks mode)渲染網(wǎng)頁。公共DTD,名稱格式為“注冊//組織//類型 標簽//語言”,“注冊”指示組織是否由國際標準化組織(ISO)注冊,+表示是,-表示不是?!敖M織”即組織名稱,如:W3C;“類型”一般是DTD,“標簽”是指定公開文本描述,即對所引用的公開文本的唯一描述性名稱,后面可附帶版本號。最后“語言”是DTD語言的ISO 639語言標識符,如:EN表示英文,ZH表示中文。XHTML 1.0可聲明三種DTD類型。分別表示嚴格版本,過渡版本,以及基于框架的HTML文檔。 • HTML 4.01 strict <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" ""> • HTML 4.01 Transitional <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""> • HTML 4.01 Frameset <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" ""> • 而最新HTML5 推出更加簡潔的書寫,它向前向后兼容,推薦使用。 <!doctype html> HTML里的doctype有兩個主要目的。 •對文檔進行有效性驗證。 它告訴用戶代理和校驗器這個文檔是按照什么DTD寫的。這個動作是被動的,每次頁面加載時,瀏覽器并不會下載DTD并檢查合法性,只有當手動校驗頁面時才啟用。 •決定瀏覽器的呈現(xiàn)模式 對于實際操作,通知瀏覽器讀取文檔時用哪種解析算法。如果沒有寫,則瀏覽器則根據(jù)自身的規(guī)則對代碼進行解析,可能會嚴重影響html排版布局。瀏覽器有三種方式解析HTML文檔。 ◦非怪異(標準)模式 ◦怪異模式 ◦部分怪異(近乎標準)模式 關(guān)于IE瀏覽器的文檔模式,瀏覽器模式,嚴格模式,怪異模式,DOCTYPE標簽,可詳細閱讀模式?標準!,以及盒子模型。 charset 聲明文檔使用的字符編碼, 代碼如下: <meta charset='utf-8'> html5之前網(wǎng)頁中會這樣寫: 代碼如下: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 這兩個是等效的,具體可移步閱讀:http://stackoverflow.com/questions/4696499/meta-charset-utf-8-vs-meta-http-equiv-content-type,所以建議使用較短的,易于記憶。 lang屬性 簡體中文 <html lang="zh-cmn-Hans"> <!-- 更加標準的 lang 屬性寫法 <http://zhi.hu/XyIa> --> 繁體中文 <html lang="zh-cmn-Hant"> <!-- 更加標準的 lang 屬性寫法 <http://zhi.hu/XyIa> --> 很少情況才需要加地區(qū)代碼,通常是為了強調(diào)不同地區(qū)漢語使用差異,例如: 代碼如下: <p lang="zh-cmn-Hans"> <strong lang="zh-cmn-Hans-CN">菠蘿</strong>和<strong lang="zh-cmn-Hant-TW">鳳梨</strong>其實是同一種水果。只是大陸和臺灣稱謂不同,且新加坡、馬來西亞一帶的稱謂也是不同的,稱之為<strong lang="zh-cmn-Hans-SG">黃梨</strong>。 </p> 具體相關(guān)請移步http://zhi.hu/XyIa 優(yōu)先使用 IE 最新版本和 Chrome 代碼如下: <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> 360 使用Google Chrome Frame 代碼如下: <meta name="renderer" content="webkit"> 360瀏覽器就會在讀取到這個標簽后,立即切換對應的極速核。 另外為了保險起見再加入 代碼如下: <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> 這樣寫可以達到的效果是如果安裝了Google Chrome Frame,則使用GCF來渲染頁面,如果沒有安裝GCF,則使用最高版本的IE內(nèi)核進行渲染。 相關(guān)鏈接:瀏覽器內(nèi)核控制Meta標簽說明文檔 百度禁止轉(zhuǎn)碼 通過百度手機打開網(wǎng)頁時,百度可能會對你的網(wǎng)頁進行轉(zhuǎn)碼,脫下你的衣服,往你的身上貼狗皮膏藥的廣告,為此可在head內(nèi)添加 <meta http-equiv="Cache-Control" content="no-siteapp" /> 相關(guān)鏈接:SiteApp轉(zhuǎn)碼聲明 SEO優(yōu)化部分 • 頁面標題<title>標簽(head頭部必須) <title>your title</title> • 頁面關(guān)鍵詞keywords <meta name="keywords" content="your keywords"> • 頁面描述內(nèi)容description <meta name="description" content="your description"> • 定義網(wǎng)頁作者author <meta name="author" content="author,email address"> • 定義網(wǎng)頁搜索引擎索引方式,robotterms是一組使用英文逗號「,」分割的值,通常有如下幾種取值:none,noindex,nofollow,all,index和follow。 <meta name="robots" content="index,follow"> 相關(guān)鏈接:WEB1038 - 標記包含無效的值 viewport viewport 可以讓布局在移動瀏覽器上顯示的更好。 通常會寫 <meta name="viewport" content="width=device-width, initial-scale=1.0"> width=device-width 會導致 iPhone 5 添加到主屏后以 WebApp 全屏模式打開頁面時出現(xiàn)黑邊(http://bigc.at/ios-webapp-viewport-meta.orz) content 參數(shù): •width viewport 寬度(數(shù)值/device-width) •height viewport 高度(數(shù)值/device-height) •initial-scale 初始縮放比例 •maximum-scale 最大縮放比例 •minimum-scale 最小縮放比例 •user-scalable 是否允許用戶縮放(yes/no) • minimal-ui iOS 7.1 beta 2 中新增屬性,可以在頁面加載時最小化上下狀態(tài)欄。這是一個布爾值,可以直接這樣寫: <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui"> 而如果你的網(wǎng)站不是響應式的,請不要使用initial-scale或者禁用縮放。 <meta name="viewport" content="width=device-width,user-scalable=yes"> 相關(guān)鏈接:非響應式設計的viewport ios 設備 添加到主屏后的標題(iOS 6 新增) 代碼如下: <meta name="apple-mobile-web-app-title" content="標題"> <!-- 添加到主屏后的標題(iOS 6 新增) --> 是否啟用 WebApp 全屏模式 代碼如下: <meta name="apple-mobile-web-app-capable" content="yes" /> <!-- 是否啟用 WebApp 全屏模式 --> 設置狀態(tài)欄的背景顏色 代碼如下: <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" /> <!-- 設置狀態(tài)欄的背景顏色,只有在 `"apple-mobile-web-app-capable" content="yes"` 時生效 --> 只有在 "apple-mobile-web-app-capable" content="yes" 時生效 content 參數(shù): •default 默認值。 •black 狀態(tài)欄背景是黑色。 •black-translucent 狀態(tài)欄背景是黑色半透明。 如果設置為 default 或 black ,網(wǎng)頁內(nèi)容從狀態(tài)欄底部開始。 如果設置為 black-translucent ,網(wǎng)頁內(nèi)容充滿整個屏幕,頂部會被狀態(tài)欄遮擋。 禁止數(shù)字識自動別為電話號碼 <meta name="format-detection" content="telephone=no" /> <!-- 禁止數(shù)字識自動別為電話號碼 --> iOS 圖標 rel 參數(shù): apple-touch-icon 圖片自動處理成圓角和高光等效果。 apple-touch-icon-precomposed 禁止系統(tǒng)自動添加效果,直接顯示設計原圖。 iPhone 和 iTouch,默認 57x57 像素,必須有 <link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-57x57-precomposed.png" /> <!-- iPhone 和 iTouch,默認 57x57 像素,必須有 --> iPad,72x72 像素,可以沒有,但推薦有 <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/apple-touch-icon-72x72-precomposed.png" /> <!-- iPad,72x72 像素,可以沒有,但推薦有 --> Retina iPhone 和 Retina iTouch,114x114 像素,可以沒有,但推薦有 <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-114x114-precomposed.png" /> <!-- Retina iPhone 和 Retina iTouch,114x114 像素,可以沒有,但推薦有 --> Retina iPad,144x144 像素,可以沒有,但推薦有 <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144x144-precomposed.png" /> <!-- Retina iPad,144x144 像素,可以沒有,但推薦有 --> iOS 啟動畫面 官方文檔:https://developer.apple.com/library/ios/qa/qa1686/_index.html 參考文章:http://wxd.ctrip.com/blog/2013/09/ios7-hig-24/ iPad 的啟動畫面是不包括狀態(tài)欄區(qū)域的。 iPad 豎屏 768 x 1004(標準分辨率) 代碼如下: <link rel="apple-touch-startup-image" sizes="768x1004" href="/splash-screen-768x1004.png" /> <!-- iPad 豎屏 768 x 1004(標準分辨率) --> iPad 豎屏 1536x2008(Retina) 代碼如下: <link rel="apple-touch-startup-image" sizes="1536x2008" href="/splash-screen-1536x2008.png" /> <!-- iPad 豎屏 1536x2008(Retina) --> iPad 橫屏 1024x748(標準分辨率) 代碼如下: <link rel="apple-touch-startup-image" sizes="1024x748" href="/Default-Portrait-1024x748.png" /> <!-- iPad 橫屏 1024x748(標準分辨率) --> iPad 橫屏 2048x1496(Retina) 代碼如下: <link rel="apple-touch-startup-image" sizes="2048x1496" href="/splash-screen-2048x1496.png" /> <!-- iPad 橫屏 2048x1496(Retina) --> iPhone 和 iPod touch 的啟動畫面是包含狀態(tài)欄區(qū)域的。 iPhone/iPod Touch 豎屏 320x480 (標準分辨率) <link rel="apple-touch-startup-image" href="/splash-screen-320x480.png" /> <!-- iPhone/iPod Touch 豎屏 320x480 (標準分辨率) --> iPhone/iPod Touch 豎屏 640x960 (Retina) <link rel="apple-touch-startup-image" sizes="640x960" href="/splash-screen-640x960.png" /> <!-- iPhone/iPod Touch 豎屏 640x960 (Retina) --> iPhone 5/iPod Touch 5 豎屏 640x1136 (Retina) <link rel="apple-touch-startup-image" sizes="640x1136" href="/splash-screen-640x1136.png" /> <!-- iPhone 5/iPod Touch 5 豎屏 640x1136 (Retina) --> 添加智能 App 廣告條 Smart App Banner(iOS 6+ Safari) <meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL"> <!-- 添加智能 App 廣告條 Smart App Banner(iOS 6+ Safari) --> Windows 8 Windows 8 磁貼顏色 代碼如下: <meta name="msapplication-TileColor" content="#000"/> <!-- Windows 8 磁貼顏色 --> Windows 8 磁貼圖標 代碼如下: <meta name="msapplication-TileImage" content="icon.png"/> <!-- Windows 8 磁貼圖標 --> rss訂閱 <link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml" /> <!-- 添加 RSS 訂閱 --> favicon icon <link rel="shortcut icon" type="image/ico" href="/favicon.ico" /> <!-- 添加 favicon icon --> 比較詳細的favicon介紹可參考https://github.com/audreyr/favicon-cheat-sheet 移動端的meta 代碼如下: <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="black" /> <meta name="format-detection"content="telephone=no, email=no" /> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <meta name="apple-mobile-web-app-capable" content="yes" /><!-- 刪除蘋果默認的工具欄和菜單欄 --> <meta name="apple-mobile-web-app-status-bar-style" content="black" /><!-- 設置蘋果工具欄顏色 --> <meta name="format-detection" content="telphone=no, email=no" /><!-- 忽略頁面中的數(shù)字識別為電話,忽略email識別 --> <!-- 啟用360瀏覽器的極速模式(webkit) --> <meta name="renderer" content="webkit"> <!-- 避免IE使用兼容模式 --> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- 針對手持設備優(yōu)化,主要是針對一些老的不識別viewport的瀏覽器,比如黑莓 --> <meta name="HandheldFriendly" content="true"> <!-- 微軟的老式瀏覽器 --> <meta name="MobileOptimized" content="320"> <!-- uc強制豎屏 --> <meta name="screen-orientation" content="portrait"> <!-- QQ強制豎屏 --> <meta name="x5-orientation" content="portrait"> <!-- UC強制全屏 --> <meta name="full-screen" content="yes"> <!-- QQ強制全屏 --> <meta name="x5-fullscreen" content="true"> <!-- UC應用模式 --> <meta name="browsermode" content="application"> <!-- QQ應用模式 --> <meta name="x5-page-mode" content="app"> <!-- windows phone 點擊無高光 --> <meta name="msapplication-tap-highlight" content="no"> <!-- 適應移動端end --> 來自toobug的分享。 更多的meta 標簽參考 •COMPLETE LIST OF HTML META TAGS •18 Meta Tags Every Webpage Should Have in 2013 更多信息請查看IT技術(shù)專欄
2025國考·省考課程試聽報名