DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> HTML基礎知識 >> HTML和Xhtml
HTML head 頭部結構實戰:以 padding.me 為例
編輯:HTML和Xhtml     

本文以一絲的文章為基礎加以擴充,透過 padding.me 的實際 head 結構,逐項說明常用標籤的意義與使用時機。

參考範例

<!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,前端,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">
 <meta name="renderer" content="webkit">
 <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
 <meta http-equiv="Cache-Control" content="no-siteapp">
 <title>PaddingMe</title>
 <link rel="shortcut icon" type="image/x-icon" href="../favicon.ico">
 <link rel="author" href="https://plus.google.com/u/1/105241873904238310190/?rel=author">
 <link type="text/plain" rel="author" href="https://padding.me/humans.txt" />
 <link rel="stylesheet" href="/css/screen.css">
 <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="https://feeds.feedburner.com/paddingme" />
</head>

DOCTYPE

DOCTYPE 位於文件最前方、html 標籤之前,告知瀏覽器採用哪種規範。DTD 聲明以 <!DOCTYPE> 開頭、不分大小寫,前方不可有其他內容,否則 IE 會進入怪異模式。HTML5 的 <!doctype html> 最為簡潔且向前向後相容,推薦使用。doctype 的兩大目的:對文件進行有效性驗證,以及決定瀏覽器的解析模式(標準、怪異、部分怪異)。

charset 與 lang

<meta charset='utf-8'>  <!-- 與 http-equiv 舊寫法等效,較短好記 -->
<html lang="zh-cmn-Hans">  <!-- 簡體 -->
<html lang="zh-cmn-Hant">  <!-- 繁體 -->

較少需要加上地區碼,通常只用來強調各地漢語用詞差異,例如「菠蘿」與「鳳梨」其實是同一種水果。

瀏覽器內核控制

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="renderer" content="webkit">  <!-- 360 極速模式 -->
<meta http-equiv="Cache-Control" content="no-siteapp">  <!-- 百度禁止轉碼 -->

SEO 部分

<title>your title</title>
<meta name="keywords" content="your keywords">
<meta name="description" content="your description">
<meta name="author" content="author,email address">
<meta name="robots" content="index,follow">

viewport 與 iOS 裝置

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="apple-mobile-web-app-title" content="標題">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="format-detection" content="telephone=no" />

狀態欄樣式 content 值有 default、black、black-translucent;僅在 apple-mobile-web-app-capable 為 yes 時生效。iOS 圖示則依 iPhone/iTouch 57x57、iPad 72x72、Retina 機型 114x114 與 144x144 等尺寸分別設定,iPhone 6 Plus 為 180x180。

啟動畫面、Windows 8 與其他

啟動畫面透過 <link rel="apple-touch-startup-image"> 依各裝置解析度設定,iPad 不含狀態欄、iPhone/iPod touch 含狀態欄。此外還有 Windows 8 磁貼顏色與圖示、RSS 訂閱、favicon 等:

<meta name="msapplication-TileColor" content="#000"/>
<meta name="msapplication-TileImage" content="icon.png"/>
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml" />
<link rel="shortcut icon" type="image/ico" href="/favicon.ico" />

行動端 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="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="HandheldFriendly" content="true">
<meta name="MobileOptimized" content="320">
<meta name="screen-orientation" content="portrait">
<meta name="x5-orientation" content="portrait">
<meta name="full-screen" content="yes">
<meta name="x5-fullscreen" content="true">
<meta name="browsermode" content="application">
<meta name="x5-page-mode" content="app">
<meta name="msapplication-tap-highlight" content="no">

以上整理自 toobug 的分享,可作為撰寫 head 時的實用範本。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved