網頁最根本的樣貌是純文字檔案。
HTML → 瀏覽器 → 畫面
瀏覽器看的懂文字檔案,然後瀏覽器會轉成我們平常看的網頁畫面。
HTML 全名: HyperText Markup Language
<html>
,<head>
,<body>
<html>
與 </html>
是start tag 與 end tag<head>
: 基本資訊
<meta charset="utf-8"/>
:<title>網頁標題</title>
:<body>
: 主要內容what is the meaning of chartset='utf-8'?
when you declare the "charset" as "UTF-8", you are telling your browser to use the UTF-8 character encoding, which is a method of converting your typed characters into machine-readable code.(More about Meta Charset)
<div>
: 把同一個區塊的東西包起來,看起來 <h2>
和 <p>
是同一組。優點就是以後的 CSS 可以對某一個標籤修改背景顏色、字體顏色。<span>
: 跨度。用在文字內比較:<div>
內前後會空行隔開,<span>
不會前後左右隔開。
舉例如下:
H3 title
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever
sincethe 1500s
說明:
<!-其中standard被 span 包起來,since 被 div 包起來-> <!-可以發現:div 內前後會空行隔開,span 不會前後左右隔開。->
<img></img>
<img>
alt
、title
、src
<alt>
: 當圖片無法顯示時,會顯示文字來替代,alt
就是替代文字的部分。<title>
: 當圖片滑鼠點上去的時候,會顯示圖的標題。<src>
: 圖片的來源(source)<li>
: 清單項目<ul>
: bullet 未排序圓點清單<ol>
: 有順序的清單<pre>
: 保留完整格式。<br>
: 換行<table>
: 表格<tr>
: table row<td>
: table cell<th>
: table header<a>
: anchor 錨點
href
: hypertext reference
功能: 超連結
1. 連到網頁外面的位置
(1) 屬性:
a. target='_self'
為預設,會直接從此頁面連到新的頁面。
b. target='_blank'
會打開新的分頁。
2. 連到網頁內的位置
take me to heading 1
<!-HackMD<a>
移動到 h1 失敗,不知道是 HackMD 的問題還是<a>
寫錯。->
語意化元素: semantic elements
<main>
:<nav>
: navigation 導覽列<footer>
: license copy right 網頁資訊等等。人或機器,一眼從 html 檔案或者機器裡,就可以從標籤判斷。
補充連結:
a. MDN Semantics
b. New Semantic Elements in HTML5
伺服器在裡面有設定X-Frame-Options
禁止不信任的人,存取網頁,因為有些人不想要讓別人有偷別人網頁的動作。所以iframe
不常使用,通常大網站都會擋住 iframe。
嵌入網頁的話,可以在網頁內做導覽。
注意事項:
以此為例:
<input type='text'>
text
: 輸入文字password
: 密碼不會顯示字母、數字email
: 有信箱格式的自動檢查date
: 選擇日期radio
: 圓圈勾選
<input>
加入 id
屬性(attribute) 搭配 <label for>
<input>
加入同一種 name
屬性(attribute),就可以將選單內 group 起來。checkbox
: 勾勾框
詳細舉例如下:
目標:幫助搜尋引擎理解網頁,搜尋引擎更理解網頁,可以讓網頁在搜尋引擎排名更前面。
<meta name='keywords'>
open Graph Protocal
: 另個協定,大多是 Facebook使用json-ld
: 通常是 google engine 在看(如下方圖r解說)。robots.txt
: 告訴網頁爬蟲哪些可以爬蟲,哪些不行Sitemap.xml
: 可以把網站中的每個網址放上去,搜尋引擎就知道需要爬蟲爬哪些網站。
6.<link ... hreflang='en'>
:<meta property='al:ios:app_name'>
:
補充:
SEO 全名:Search Engine Optimization 搜尋引擎優化。
目標:幫助搜尋引擎理解你的網頁
範例:trip adviser 鼎泰豐101店
<meta name='keywords'>
keywords
: 告訴搜尋引擎關鍵字有哪些,類似 hash tag。其中網頁的 title 也滿重要的。description
: 告訴搜尋引擎簡介容<meta property='og:title'>
og:title
og:description
og:image
important
給網頁爬蟲看的檔案,通常放到根目錄底下。如:https://www.tripadvisor.com.tw/robots.txt
<link ... hreflang='en'>
跟搜尋引擎說:這個網頁有分英文跟中文,利用這個 tag 跟搜尋引擎說這是同一個頁面,不同語言,所以在網頁裡面給的評分,就會加在一起,不會分開計算。
<meta property='al:ios:app_name'>
如果使用 iPhone safari 觀看 tripadvisor,可能看一看就會跳出「要不要下載 tripadvisor」的 app,
在 iPad 或 iPhone 瀏覽的話,使用 twitter 瀏覽的話,
補充:
想要在 html 上以純文字顯示標籤( <div>
),但是在瀏覽器上會被解析為標籤(即 escape 跳脫),就是字元不見。以其他顯示顯示字元,而不是當作標籤。
舉例:
<div></div>
要讓這個標籤以純文字的形式,顯示在 html呢?
MTR05
Lidemy 學習筆記