lt;title> - 定義了HTML文檔的標題
使用 <title> 標簽定義HTML文檔的標題
<base> - 定義了所有鏈接的URL
使用 <base> 定義頁面中所有鏈接默認的鏈接目標地址。
<meta> - 提供了HTML文檔的meta標記
使用 <meta> 元素來描述HTML文檔的描述,關鍵詞,作者,字符集等。
HTML <head> 元素
<head> 元素包含了所有的頭部標簽元素。在 <head>元素中你可以插入腳本(scripts), 樣式文件(CSS),及各種meta信息。
可以添加在頭部區域的元素標簽為: <title>, <style>, <meta>, <link>, <script>, <noscript>, and <base>.
HTML <title> 元素
<title> 標簽定義了不同文檔的標題。
<title> 在 HTML/XHTML 文檔中是必須的。
<title> 元素:
定義了瀏覽器工具欄的標題
當網頁添加到收藏夾時,顯示在收藏夾中的標題
顯示在搜索引擎結果頁面的標題
一個簡單的 HTML 文檔:
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>文檔標題</title></head><body>文檔內容......</body></html>
HTML <base> 元素
<base> 標簽描述了基本的鏈接地址/鏈接目標,該標簽作為HTML文檔中所有的鏈接標簽的默認鏈接:
<head>
<base target="_blank">
</head>
HTML <link> 元素
<link> 標簽定義了文檔與外部資源之間的關系。
<link> 標簽通常用于鏈接到樣式表:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
HTML <style> 元素
<style> 標簽定義了HTML文檔的樣式文件引用地址.
在<style> 元素中你需要指定樣式文件來渲染HTML文檔:
<head>
<style type="text/css">
body {background-color:yellow}
p {color:blue}
</style>
</head>
HTML <meta> 元素
meta標簽描述了一些基本的元數據。
<meta> 標簽提供了元數據.元數據也不顯示在頁面上,但會被瀏覽器解析。
META元素通常用于指定網頁的描述,關鍵詞,文件的最后修改時間,作者,和其他元數據。
元數據可以使用于瀏覽器(如何顯示內容或重新加載頁面),搜索引擎(關鍵詞),或其他Web服務。
<meta>一般放置于 <head>區域
<meta> 標簽- 使用實例
為搜索引擎定義關鍵詞:
<meta name="keywords" content="HTML, CSS, XML, XHTML, JavaScript">
為網頁定義描述內容:
<meta name="description" content="Free Web tutorials on HTML and CSS">
定義網頁作者:
<meta name="author" content="Hege Refsnes">
每30秒中刷新當前頁面:
<meta http-equiv="refresh" content="30">
HTML <script> 元素
<script>標簽用于加載腳本文件,如: JavaScript。
<script> 元素在以下章節會詳細描述。
HTML head 元素
標簽 | 描述 |
---|---|
<head> | 定義了文檔的信息 |
<title> | 定義了文檔的標題 |
<base> | 定義了頁面鏈接標簽的默認鏈接地址 |
<link> | 定義了一個文檔和外部資源之間的關系 |
<meta> | 定義了HTML文檔中的元數據 |
<script> | 定義了客戶端的腳本文件 |
<style> | 定義了HTML文檔的樣式文件 |
如您還有不明白的可以在下面與我留言或是與我探討QQ群308855039,我們一起飛!
來看下常用的標簽列表,后文會一一介紹:
<!DOCTYPE html> <!-- 使用 HTML5 doctype,不區分大小寫 -->
<html lang="zh-cmn-Hans"> <!-- 更加標準的 lang 屬性寫法 http://zhi.hu/XyIa -->
<head>
<meta charset='utf-8'> <!-- 聲明文檔使用的字符編碼 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <!-- 優先使用 IE 最新版本和 Chrome -->
<meta name="description" content="不超過150個字符" /> <!-- 頁面描述 -->
<meta name="keywords" content=""/> <!-- 頁面關鍵詞 -->
<meta name="author" content="name, email@gmail.com" /> <!-- 網頁作者 -->
<meta name="robots" content="index,follow" /> <!-- 搜索引擎抓取 -->
<!-- 為移動設備添加 viewport -->
<meta name ="viewport" content ="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no"> <!-- `width=device-width` 會導致 iPhone 5 添加到主屏后以 WebApp 全屏模式打開頁面時出現黑邊 http://bigc.at/ios-webapp-viewport-meta.orz -->
<!-- iOS 設備 begin -->
<meta name="apple-mobile-web-app-title" content="標題"> <!-- 添加到主屏后的標題(iOS 6 新增) -->
<meta name="apple-mobile-web-app-capable" content="yes" /> <!-- 是否啟用 WebApp 全屏模式 -->
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" /> <!-- 設置狀態欄的背景顏色,只有在 `"apple-mobile-web-app-capable" content="yes"` 時生效 -->
<meta name="format-detection" content="telephone=no" /> <!-- 禁止數字識自動別為電話號碼 -->
<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL"> <!-- 添加智能 App 廣告條 Smart App Banner(iOS 6+ Safari) -->
<!-- iOS 圖標 begin -->
<link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-57x57-precomposed.png" /> <!-- iPhone 和 iTouch,默認 57x57 像素,必須有 -->
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-114x114-precomposed.png" /> <!-- Retina iPhone 和 Retina iTouch,114x114 像素,可以沒有,但推薦有 -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144x144-precomposed.png" /> <!-- Retina iPad,144x144 像素,可以沒有,但推薦有 -->
<!-- iOS 圖標 end -->
<!-- iOS 啟動畫面 begin -->
<link rel="apple-touch-startup-image" sizes="768x1004" href="/splash-screen-768x1004.png" /> <!-- iPad 豎屏 768 x 1004(標準分辨率) -->
<link rel="apple-touch-startup-image" sizes="1536x2008" href="/splash-screen-1536x2008.png" /> <!-- iPad 豎屏 1536x2008(Retina) -->
<link rel="apple-touch-startup-image" sizes="1024x748" href="/Default-Portrait-1024x748.png" /> <!-- iPad 橫屏 1024x748(標準分辨率) -->
<link rel="apple-touch-startup-image" sizes="2048x1496" href="/splash-screen-2048x1496.png" /> <!-- iPad 橫屏 2048x1496(Retina) -->
<link rel="apple-touch-startup-image" href="/splash-screen-320x480.png" /> <!-- iPhone/iPod Touch 豎屏 320x480 (標準分辨率) -->
<link rel="apple-touch-startup-image" sizes="640x960" href="/splash-screen-640x960.png" /> <!-- iPhone/iPod Touch 豎屏 640x960 (Retina) -->
<link rel="apple-touch-startup-image" sizes="640x1136" href="/splash-screen-640x1136.png" /> <!-- iPhone 5/iPod Touch 5 豎屏 640x1136 (Retina) -->
<!-- iOS 啟動畫面 end -->
<!-- iOS 設備 end -->
<meta name="msapplication-TileColor" content="#000"/> <!-- Windows 8 磁貼顏色 -->
<meta name="msapplication-TileImage" content="icon.png"/> <!-- Windows 8 磁貼圖標 -->
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml" /> <!-- 添加 RSS 訂閱 -->
<link rel="shortcut icon" type="image/ico" href="/favicon.ico" /> <!-- 添加 favicon icon -->
<title>標題</title>
</head>
基本標簽
使用 HTML5 doctype,不區分大小寫。
<!DOCTYPE html> <!-- 使用 HTML5 doctype,不區分大小寫 -->
聲明文檔使用的字符編碼
<meta charset='utf-8'> <!-- 聲明文檔使用的字符編碼 -->
更加標準的 lang 屬性寫法 http://zhi.hu/XyIa
很少情況才需要加地區代碼,通常是為了強調不同地區漢語使用差異,例如:
<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>
優先使用 IE 最新版本和 Chrome
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <!-- 優先使用 IE 最新版本和 Chrome -->
SEO 優化
頁面描述
每個網頁都應有一個不超過 150 個字符且能準確反映網頁內容的描述標簽。文檔
<meta name="description" content="不超過150個字符" /> <!-- 頁面描述 -->
頁面關鍵詞
<meta name="keywords" content=""/> <!-- 頁面關鍵詞 -->
定義頁面標題
<title>標題</title>
定義網頁作者
<meta name="author" content="name, email@gmail.com" /> <!-- 網頁作者 -->
定義網頁搜索引擎索引方式,robotterms是一組使用英文逗號「,」分割的值,通常有如下幾種取值:none,noindex,nofollow,all,index和follow。文檔
<meta name="robots" content="index,follow" /> <!-- 搜索引擎抓取 -->
可選標簽
為移動設備添加 viewport
<meta name ="viewport" content ="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no"> <!-- `width=device-width` 會導致 iPhone 5 添加到主屏后以 WebApp 全屏模式打開頁面時出現黑邊 http://bigc.at/ios-webapp-viewport-meta.orz -->
content 參數:
iOS 設備
添加到主屏后的標題(iOS 6 新增)
<meta name="apple-mobile-web-app-title" content="標題"> <!-- 添加到主屏后的標題(iOS 6 新增) -->
是否啟用 WebApp 全屏模式
<meta name="apple-mobile-web-app-capable" content="yes" /> <!-- 是否啟用 WebApp 全屏模式 -->
設置狀態欄的背景顏色
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" /> <!-- 設置狀態欄的背景顏色,只有在 `"apple-mobile-web-app-capable" content="yes"` 時生效 -->
content 參數:
如果設置為 default 或 black ,網頁內容從狀態欄底部開始。
如果設置為 black-translucent ,網頁內容充滿整個屏幕,頂部會被狀態欄遮擋。
禁止數字識自動別為電話號碼
<meta name="format-detection" content="telephone=no" /> <!-- 禁止數字識自動別為電話號碼 -->
iOS 圖標
rel 參數:
apple-touch-icon 圖片自動處理成圓角和高光等效果。
apple-touch-icon-precomposed 禁止系統自動添加效果,直接顯示設計原圖。
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 的啟動畫面是不包括狀態欄區域的。
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 的啟動畫面是包含狀態欄區域的。
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) -->
Android
Android Lollipop 中的 Chrome 39 增加 theme-color meta 標簽,用來控制選項卡顏色。
http://updates.html5rocks.com/2014/11/Support-for-theme-color-in-Chrome-39-for-Android
<meta name="theme-color" content="#db5945">
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 -->
禁止 Chrome 瀏覽器中自動提示翻譯
檔的標題
[demo]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="zh-cn" />
<title>標題不會顯示在文檔區</title>
</head>
<body>
<p>這段文本會顯示出來。</p>
</body>
</html>
[/demo]
<title> 標題定義文檔的標題。
所有鏈接一個目標
[demo]
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html" />
<meta http-equiv="Content-Language" content="zh-cn" />
<base target="_blank" />
</head>
<body>
<p>
<a target="_blank">這個連接</a> 將在新窗口中加載,因為 target 屬性被設置為 "_blank"。
</p>
<p>
<a >這個連接</a> 也將在新窗口中加載,即使沒有 target 屬性。
</p>
</body>
</html>
[/demo]
如何使用 base 標簽使頁面中的所有標簽在新窗口中打開。
文檔描述
[demo]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="author"
content="w3school.com.cn">
<meta name="revised"
content="David Yang,8/1/07">
<meta name="generator"
content="Dreamweaver 8.0en">
</head>
<body>
<p>本文檔的 meta 屬性標識了創作者和編輯軟件。</p>
</body>
</html>
[/demo]
使用 <meta> 元素來描述文檔。
文檔關鍵詞
[demo]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description"
content="HTML examples">
<meta name="keywords"
content="HTML, DHTML, CSS, XML, XHTML, JavaScript, VBScript">
</head>
<body>
<p>本文檔的 meta 屬性描述了該文檔和它的關鍵詞。</p>
</body>
</html>
[/demo]
使用 <meta> 元素來定義文檔的關鍵詞。
重定向用戶
[demo]
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Refresh" content="5;url=http://www.w3school.com.cn" />
</head>
<body>
<p>
對不起。我們已經搬家了。您的 URL 是 <a >http://www.w3school.com.cn</a>
</p>
<p>您將在 5 秒內被重定向到新的地址。</p>
<p>如果超過 5 秒后您仍然看到本消息,請點擊上面的鏈接。</p>
</body>
</html>
[/demo]
如何把用戶重定向到新的網址。
HTML <head> 元素
<head> 元素是所有頭部元素的容器。<head> 內的元素可包含腳本,指示瀏覽器在何處可以找到樣式表,提供元信息,等等。
以下標簽都可以添加到 head 部分:<title>、<base>、<link>、<meta>、<script> 以及 <style>。
HTML <title> 元素
<title> 標簽定義文檔的標題。
title 元素在所有 HTML/XHTML 文檔中都是必需的。
title 元素能夠:
定義瀏覽器工具欄中的標題
提供頁面被添加到收藏夾時顯示的標題
顯示在搜索引擎結果中的頁面標題
一個簡化的 HTML 文檔:
[demo]
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
The content of the document......
</body>
</html>
[/demo]
HTML <base> 元素
<base> 標簽為頁面上的所有鏈接規定默認地址或默認目標(target):
<head>
<base />
<base target="_blank" />
</head>
HTML <link> 元素
<link> 標簽定義文檔與外部資源之間的關系。
<link> 標簽最常用于連接樣式表:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>
HTML <style> 元素
<style> 標簽用于為 HTML 文檔定義樣式信息。
您可以在 style 元素內規定 HTML 元素在瀏覽器中呈現的樣式:
<head>
<style type="text/css">
body {background-color:yellow}
p {color:blue}
</style>
</head>
HTML <meta> 元素
元數據(metadata)是關于數據的信息。
<meta> 標簽提供關于 HTML 文檔的元數據。元數據不會顯示在頁面上,但是對于機器是可讀的。
典型的情況是,meta 元素被用于規定頁面的描述、關鍵詞、文檔的作者、最后修改時間以及其他元數據。
<meta> 標簽始終位于 head 元素中。
元數據可用于瀏覽器(如何顯示內容或重新加載頁面),搜索引擎(關鍵詞),或其他 web 服務。
針對搜索引擎的關鍵詞
一些搜索引擎會利用 meta 元素的 name 和 content 屬性來索引您的頁面。
下面的 meta 元素定義頁面的描述:
<meta name="description" content="Free Web tutorials on HTML, CSS, XML" />
下面的 meta 元素定義頁面的關鍵詞:
<meta name="keywords" content="HTML, CSS, XML" />
name 和 content 屬性的作用是描述頁面的內容。
HTML <script> 元素
<script> 標簽用于定義客戶端腳本,比如 JavaScript。
我們會在稍后的章節講解 script 元素。
HTML 頭部元素
標簽 描述
<head> 定義關于文檔的信息。
<title> 定義文檔標題。
<base> 定義頁面上所有鏈接的默認地址或默認目標。
<link> 定義文檔與外部資源之間的關系。
<meta> 定義關于 HTML 文檔的元數據。
<script> 定義客戶端腳本。
<style> 定義文檔的樣式信息。
*請認真填寫需求信息,我們會在24小時內與您取得聯系。