Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
lt;marquee>...</marquee>普通卷動
<marquee behavior=slide>...</marquee>滑動
<marquee behavior=scroll>...</marquee>預設卷動
<marquee behavior=alternate>...</marquee>來回卷動
<marquee direction=down>...</marquee>向下卷動
<marquee direction=up>...</marquee>向上卷動
<marquee direction=right></marquee>向右卷動
<marquee direction=left></marquee>向左卷動
<marquee loop=2>...</marquee>卷動次數
<marquee width=180>...</marquee>設定寬度
<marquee height=30>...</marquee>設定高度
<marquee bgcolor=FF0000>...</marquee>設定背景顏色
<marquee scrollamount=30>...</marquee>設定卷動距離
<marquee scrolldelay=300>...</marquee>設定卷動時間
<!>字體效果
<h1>...</h1>標題字(最大)
<h6>...</h6>標題字(最小)
<b>...</b>粗體字
<strong>...</strong>粗體字(強調)
<i>...</i>斜體字
<em>...</em>斜體字(強調)
<dfn>...</dfn>斜體字(表示定義)
<u>...</u>底線
<ins>...</ins>底線(表示插入文字)
<strike>...</strike>橫線
<s>...</s>刪除線
<del>...</del>刪除線(表示刪除)
<kbd>...</kbd>鍵盤文字
<tt>...</tt> 打字體
<xmp>...</xmp>固定寬度字體(在文件中空白、換行、定位功能有效)
<plaintext>...</plaintext>固定寬度字體(不執行標記符號)
<listing>...</listing> 固定寬度小字體
<font color=00ff00>...</font>字體顏色
<font size=1>...</font>最小字體
<font style =font-size:100 px>...</font>無限增大
<!>區斷標記
<hr>水平線
<hr size=9>水平線(設定大小)
<hr width=80%>水平線(設定寬度)
<hr color=ff0000>水平線(設定顏色)
<br>(換行)
<nobr>...</nobr>水域(不換行)
<p>...</p>水域(段落)
<center>...</center>置中
<!>連結格式
<base href=位址>(預設好連結路徑)
<a href=位址></a>外部連結
<a href=位址 target=_blank></a>外部連結(另開新視窗)
<a href=位址 target=_top></a>外部連結(全視窗連結)
<a href=位址 target=頁框名></a>外部連結(在指定頁框連結)
<!>貼圖/音樂
<img src=圖片位址>貼圖
<img src=圖片位址 width=180>設定圖片寬度
<img src=圖片位址 height=30>設定圖片高度
<img src=圖片位址 alt=提示文字>設定圖片提示文字
<img src=圖片位址 border=1>設定圖片邊框
<bgsound src=MID音樂檔位址>背景音樂設定
<!>表格語法
<table aling=left>...</table>表格位置,置左
<table aling=center>...</table>表格位置,置中
<table background=圖片路徑>...</table>背景圖片的URL=就是路徑網址
<table border=邊框大小>...</table>設定表格邊框大小(使用數字)
<table bgcolor=顏色碼>...</table>設定表格的背景顏色
<table borderclor=顏色碼>...</table>設定表格邊框的顏色
<table borderclor=顏色碼>...</table>設定表格邊框的顏色
<table borderclordark=顏色碼>...</table>設定表格暗邊框的顏色
<table borderclorlight=顏色碼>...</table>設定表格亮邊框的顏色
<table cellpadding=參數>...</table>指定內容與格線之間的間距(使用數字)
<table cellspacing=參數>...</table>指定格線與格線之間的距離(使用數字)
<table cols=參數>...</table>指定表格的欄數
<table frame=參數>...</table>設定表格外框線的顯示方式
<table width=寬度>...</table>指定表格的寬度大小(使用數字)
<table height=高度>...</table>指定表格的高度大小(使用數字)
<td colspan=參數>...</td>指定儲存格合并欄的欄數(使用數字)
<td rowspan=參數>...</td>指定儲存格合并列的列數(使用數字)
<!>分割視窗
<frameset cols="20%,*">左右分割,將左邊框架分割大小為20%右邊框架的大小瀏覽器會自動調整
<frameset rows="20%,*">上下分割,將上面框架分割大小為20%下面框架的大小瀏覽器會自動調整
<frameset cols="20%,*">分割左右兩個框架
<frameset cols="20%,*,20%">分割左中右三個框架
<分割上下兩個框架
<frameset rows="20%,*,20%">分割上中下三個框架
<! - - ... - -> 注解
<a href target> 指定超連結的分割視窗
<a href=#錨的名稱> 指定錨名稱的超連結
<a href> 指定超連結
<a name=錨的名稱> 被連結點的名稱
<address>....</address> 用來顯示電子郵箱地址
<b> 粗體字
<base target> 指定超連結的分割視窗
<basefont size> 更改預設字形大小
<bgsound src> 加入背景音樂
<big> 顯示大字體
<blink> 閃爍的文字
<body text link vlink> 設定文字顏色
<body> 顯示本文
<br> 換行
<caption align> 設定表格標題位置
<caption>...</caption> 為表格加上標題
<center> 向中對齊
<cite>...<cite> 用於引經據典的文字
<code>...</code> 用於列出一段程式碼
<comment>...</comment> 加上注解
<dd> 設定定義列表的項目解說
<dfn>...</dfn> 顯示"定義"文字
<dir>...</dir> 列表文字標簽
<dl>...</dl> 設定定義列表的標簽
<dt> 設定定義列表的項目
<em> 強調之用
<font face> 任意指定所用的字形
<font face> 任意指定所用的字形
<font size> 設定字體大小
<form action> 設定戶動式表單的處理方式
<form method> 設定戶動式表單之資料傳送方式
<frame marginheight> 設定視窗的上下邊界
<frame marginwidth> 設定視窗的左右邊界
<frame name> 為分割視窗命名
<frame noresize> 鎖住分割視窗的大小
<frame scrolling> 設定分割視窗的卷軸
<frame src> 將html檔加入視窗
<frameset cols> 將視窗分割成左右的子視窗
<frameset rows> 將視窗分割成上下的子視窗
<frameset>...</frameset> 劃分分割視窗
<h1>~<h6> 設定文字大小
<head> 標示文件資訊
<hr> 加上分格線
<html> 文件的開始與結束
<i> 斜體字
<img align> 調整圖形影像的位置
<img alt> 為你的圖形影像加注
<img dynsrc loop> 加入影片
<img height width> 插入圖片并預設圖形大小
<img hspace> 插入圖片并預設圖形的左右邊界
<img lowsrc> 預載圖片功能
<img src border> 設定圖片邊界
<img src> 插入圖片
<img vspace> 插入圖片并預設圖形的上下邊界
<input type name value> 在表單中加入輸入欄位
<isindex> 定義查詢用表單
<kbd>...</kbd> 表示使用者輸入文字
<li type>...</li> 列表的項目 ( 可指定符號 )
<marquee> 跑馬燈效果
<menu>...</menu> 條列文字標簽
<meta name="refresh" content url> 自動更新文件內容
<multiple> 可同時選擇多項的列表欄
<noframe> 定義不出現分割視窗的文字
<ol>...</ol> 有序號的列表
<option> 定義表單中列表欄的項目
<p align> 設定對齊方向
<p> 分段
<person>...</person> 顯示人名
<pre> 使用原有排列
<samp>...</samp> 用於引用字
<select>...</select> 在表單中定義列表欄
<small> 顯示小字體
<strike> 文字加橫線
<strong> 用於加強語氣
<sub> 下標字
<sup> 上標字
<table border=n> 調整表格的寬線高度
<table cellpadding> 調整資料欄位之邊界
<table cellspacing> 調整表格線的寬度
<table height> 調整表格的高度
<table width> 調整表格的寬度
<table>...</table> 產生表格的標簽
<td align> 調整表格欄位之左右對齊
<td bgcolor> 設定表格欄位之背景顏色
<td colspan rowspan> 表格欄位的合并
<td nowrap> 設定表格欄位不換行
<td valign> 調整表格欄位之上下對齊
<td width> 調整表格欄位寬度
<td>...</td> 定義表格的資料欄位
<textarea name rows cols> 表單中加入多少列的文字輸入欄
<textarea wrap> 決定文字輸入欄是自動否換行
<th>...</th> 定義表格的標頭欄位
<title> 文件標題
<tr>...</tr> 定義表格美一行
<tt> 打字機字體
<u> 文字加底線
<ul type>...</ul> 無序號的列表 ( 可指定符號 )
<var>...</var> 用於顯示變數
譯自: https://medium.freecodecamp.org/for-your-first-html-code-lets-help-batman-write-a-love-letter-64c203b9360b
作者: Kunal Sarkar
譯者: MjSeven
在一個美好的夜晚,你的肚子拒絕消化你在晚餐吃的大塊披薩,所以你不得不在睡夢中沖進洗手間。
在浴室里,當你在思考為什么會發生這種情況時,你聽到一個來自通風口的低沉聲音:“嘿,我是蝙蝠俠。”
這時,你會怎么做呢?
在你恐慌并處于關鍵時刻之前,蝙蝠俠說:“我需要你的幫助。我是一個超級極客,但我不懂 HTML。我需要用 HTML 寫一封情書,你愿意幫助我嗎?”
誰會拒絕蝙蝠俠的請求呢,對吧?所以讓我們用 HTML 來寫一封蝙蝠俠的情書。
HTML 網頁與你電腦上的其它文件一樣。就同一個 .doc 文件以 MS Word 打開,.jpg 文件在圖像查看器中打開一樣,一個 .html 文件在瀏覽器中打開。
那么,讓我們來創建一個 .html 文件。你可以在 Notepad 或其它任何編輯器中完成此任務,但我建議使用 VS Code。 在這里下載并安裝 VS Code 。它是免費的,也是我唯一喜歡的微軟產品。
在系統中創建一個目錄,將其命名為 “HTML Practice”(不帶引號)。在這個目錄中,再創建一個名為 “Batman’s Love Letter”(不帶引號)的目錄,這將是我們的項目根目錄。這意味著我們所有與這個項目相關的文件都會在這里。
打開 VS Code,按下 ctrl+n 創建一個新文件,按下 ctrl+s 保存文件。切換到 “Batman’s Love Letter” 文件夾并將其命名為 “loveletter.html”,然后單擊保存。
現在,如果你在文件資源管理器中雙擊它,它將在你的默認瀏覽器中打開。我建議使用 Firefox 來進行 web 開發,但 Chrome 也可以。
讓我們將這個過程與我們已經熟悉的東西聯系起來。還記得你第一次拿到電腦嗎?我做的第一件事是打開 MS Paint 并繪制一些東西。你在 Paint 中繪制一些東西并將其另存為圖像,然后你可以在圖像查看器中查看該圖像。之后,如果要再次編輯該圖像,你在 Paint 中重新打開它,編輯并保存它。
我們目前的流程非常相似。正如我們使用 Paint 創建和編輯圖像一樣,我們使用 VS Code 來創建和編輯 HTML 文件。就像我們使用圖像查看器查看圖像一樣,我們使用瀏覽器來查看我們的 HTML 頁面。
我們有一個空的 HTML 文件,以下是蝙蝠俠想在他的情書中寫的第一段。
“After all the battles we fought together, after all the difficult times we saw together, and after all the good and bad moments we’ve been through, I think it’s time I let you know how I feel about you.”
復制這些到 VS Code 中的 loveletter.html。單擊 “View -> Toggle Word Wrap (alt+z)” 自動換行。
保存并在瀏覽器中打開它。如果它已經打開,單擊瀏覽器中的刷新按鈕。
瞧!那是你的第一個網頁!
我們的第一段已準備就緒,但這不是在 HTML 中編寫段落的推薦方法。我們有一種特定的方法讓瀏覽器知道一個文本是一個段落。
如果你用 <p> 和 </p> 來包裹文本,那么瀏覽器將識別 <p> 和 </p> 中的文本是一個段落。我們這樣做:
<p>After all the battles we fought together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.</p>
通過在 <p> 和 </p>中編寫段落,你創建了一個 HTML 元素。一個網頁就是 HTML 元素的集合。
讓我們首先來認識一些術語:<p> 是開始標簽,</p> 是結束標簽,“p” 是標簽名稱。元素開始和結束標簽之間的文本是元素的內容。
在上面,你將看到文本覆蓋屏幕的整個寬度。
我們不希望這樣。沒有人想要閱讀這么長的行。讓我們設定段落寬度為 550px。
我們可以通過使用元素的 style 屬性來實現。你可以在其 style 屬性中定義元素的樣式(例如,在我們的示例中為寬度)。以下行將在 p 元素上創建一個空樣式屬性:
<p style="">...</p>
你看到那個空的 "" 了嗎?這就是我們定義元素外觀的地方。現在我們要將寬度設置為 550px。我們這樣做:
<p style="width:550px;">
After all the battles we fought together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
我們將 width 屬性設置為 550px,用冒號 : 分隔,以分號 ; 結束。
另外,注意我們如何將 <p> 和 </p> 放在單獨的行中,文本內容用一個制表符縮進。像這樣設置代碼使其更具可讀性。
接下來,蝙蝠俠希望列出他所欽佩的人的一些優點,例如:
You complete my darkness with your light. I love:
- the way you see good in the worst things
- the way you handle emotionally difficult situations
- the way you look at Justice
I have learned a lot from you. You have occupied a special place in my heart over time.
這看起來很簡單。
讓我們繼續,在 </p> 下面復制所需的文本:
<p style="width:550px;">
After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
<p style="width:550px;">
You complete my darkness with your light. I love:
- the way you see good in the worse
- the way you handle emotionally difficult situations
- the way you look at Justice
I have learned a lot from you. You have occupied a special place in my heart over the time.
</p>
保存并刷新瀏覽器。
哇!這里發生了什么,我們的列表在哪里?
如果你仔細觀察,你會發現沒有顯示換行符。在代碼中我們在新的一行中編寫列表項,但這些項在瀏覽器中顯示在一行中。
如果你想在 HTML(新行)中插入換行符,你必須使用 <br>。讓我們來使用 <br>,看看它長什么樣:
<p style="width:550px;">
After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
<p style="width:550px;">
You complete my darkness with your light. I love: <br>
- the way you see good in the worse <br>
- the way you handle emotionally difficult situations <br>
- the way you look at Justice <br>
I have learned a lot from you. You have occupied a special place in my heart over the time.
</p>
保存并刷新:
好的,現在它看起來就像我們想要的那樣!
另外,注意我們沒有寫一個 </br>。有些標簽不需要結束標簽(它們被稱為自閉合標簽)。
還有一件事:我們沒有在兩個段落之間使用 <br>,但第二個段落仍然是從一個新行開始,這是因為 <p> 元素會自動插入換行符。
我們使用純文本編寫列表,但是有兩個標簽可以供我們使用來達到相同的目的:<ul> and <li>。
讓我們解釋一下名字的意思:ul 代表 無序列表(Unordered List),li 代表 列表項目(List Item)。讓我們使用它們來展示我們的列表:
<p style="width:550px;">
After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
<p style="width:550px;">
You complete my darkness with your light. I love:
<ul>
<li>the way you see good in the worse</li>
<li>the way you handle emotionally difficult situations</li>
<li>the way you look at Justice</li>
</ul>
I have learned a lot from you. You have occupied a special place in my heart over the time.
</p>
在復制代碼之前,注意差異部分:
讓我們保存文件并刷新瀏覽器以查看結果:
你會立即注意到在每個列表項之前顯示了重點標志。我們現在不需要在每個列表項之前寫 “-”。
經過仔細檢查,你會注意到最后一行超出 550px 寬度。這是為什么?因為 HTML 不允許 <ul> 元素出現在 <p> 元素中。讓我們將第一行和最后一行放在單獨的 <p> 元素中:
<p style="width:550px;">
After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
<p style="width:550px;">
You complete my darkness with your light. I love:
</p>
<ul style="width:550px;">
<li>the way you see good in the worse</li>
<li>the way you handle emotionally difficult situations</li>
<li>the way you look at Justice</li>
</ul>
<p style="width:550px;">
I have learned a lot from you. You have occupied a special place in my heart over the time.
</p>
保存并刷新。
注意,這次我們還定義了 <ul> 元素的寬度。那是因為我們現在已經將 <ul> 元素放在了 <p> 元素之外。
定義情書中所有元素的寬度會變得很麻煩。我們有一個特定的元素用于此目的:<div> 元素。一個 <div> 元素就是一個通用容器,用于對內容進行分組,以便輕松設置樣式。
讓我們用 <div> 元素包裝整個情書,并為其賦予寬度:550px 。
<div style="width:550px;">
<p>
After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
<p>
You complete my darkness with your light. I love:
</p>
<ul>
<li>the way you see good in the worse</li>
<li>the way you handle emotionally difficult situations</li>
<li>the way you look at Justice</li>
</ul>
<p>
I have learned a lot from you. You have occupied a special place in my heart over the time.
</p>
</div>
棒極了,我們的代碼現在看起來簡潔多了。
到目前為止,蝙蝠俠對結果很高興,他希望在情書上標題。他想寫一個標題: “Bat Letter”。當然,你已經看到這個名字了,不是嗎?:D
你可以使用 <h1>、<h2>、<h3>、<h4>、<h5> 和 <h6> 標簽來添加標題,<h1> 是最大的標題和最主要的標題,<h6> 是最小的標題。
讓我們在第二段之前使用 <h1> 做主標題和一個副標題:
<div style="width:550px;">
<h1>Bat Letter</h1>
<p>
After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
<h2>You are the light of my life</h2>
<p>
You complete my darkness with your light. I love:
</p>
<ul>
<li>the way you see good in the worse</li>
<li>the way you handle emotionally difficult situations</li>
<li>the way you look at Justice</li>
</ul>
<p>
I have learned a lot from you. You have occupied a special place in my heart over the time.
</p>
</div>
保存,刷新。
我們的情書尚未完成,但在繼續之前,缺少一件大事:蝙蝠俠標志。你見過是蝙蝠俠的東西但沒有蝙蝠俠的標志嗎?
并沒有。
所以,讓我們在情書中添加一個蝙蝠俠標志。
在 HTML 中包含圖像就像在一個 Word 文件中包含圖像一樣。在 MS Word 中,你到 “菜單 -> 插入 -> 圖像 -> 然后導航到圖像位置為止 -> 選擇圖像 -> 單擊插入”。
在 HTML 中,我們使用 <img> 標簽讓瀏覽器知道我們需要加載的圖像,而不是單擊菜單。我們在 src 屬性中寫入文件的位置和名稱。如果圖像在項目根目錄中,我們可以簡單地在 src 屬性中寫入圖像文件的名稱。
在我們深入編碼之前,從 這里 下載蝙蝠俠標志。你可能希望裁剪圖像中的額外空白區域。復制項目根目錄中的圖像并將其重命名為 “bat-logo.jpeg”。
<div style="width:550px;">
<h1>Bat Letter</h1>
<img src="bat-logo.jpeg">
<p>
After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
<h2>You are the light of my life</h2>
<p>
You complete my darkness with your light. I love:
</p>
<ul>
<li>the way you see good in the worse</li>
<li>the way you handle emotionally difficult situations</li>
<li>the way you look at Justice</li>
</ul>
<p>
I have learned a lot from you. You have occupied a special place in my heart over the time.
</p>
</div>
我們在第 3 行包含了 <img> 標簽。這個標簽也是一個自閉合的標簽,所以我們不需要寫 </img>。在 src 屬性中,我們給出了圖像文件的名稱。這個名稱應與圖像名稱完全相同,包括擴展名(.jpeg)及其大小寫。
保存并刷新,查看結果。
該死的!剛剛發生了什么?
當使用 <img> 標簽包含圖像時,默認情況下,圖像將以其原始分辨率顯示。在我們的例子中,圖像比 550px 寬得多。讓我們使用 style 屬性定義它的寬度:
<div style="width:550px;">
<h1>Bat Letter</h1>
<img src="bat-logo.jpeg" style="width:100%">
<p>
After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
<h2>You are the light of my life</h2>
<p>
You complete my darkness with your light. I love:
</p>
<ul>
<li>the way you see good in the worse</li>
<li>the way you handle emotionally difficult situations</li>
<li>the way you look at Justice</li>
</ul>
<p>
I have learned a lot from you. You have occupied a special place in my heart over the time.
</p>
</div>
你會注意到,這次我們定義寬度使用了 “%” 而不是 “px”。當我們在 “%” 中定義寬度時,它將占據父元素寬度的百分比。因此,100% 的 550px 將為我們提供 550px。
保存并刷新,查看結果。
太棒了!這讓蝙蝠俠的臉露出了羞澀的微笑 :)。
現在蝙蝠俠想在最后幾段中承認他的愛。他有以下文本供你用 HTML 編寫:
“I have a confession to make
It feels like my chest does have a heart. You make my heart beat. Your smile brings a smile to my face, your pain brings pain to my heart.
I don’t show my emotions, but I think this man behind the mask is falling for you.”
當閱讀到這里時,你會問蝙蝠俠:“等等,這是給誰的?”蝙蝠俠說:
“這是給超人的。”
你說:哦!我還以為是給神奇女俠的呢。
蝙蝠俠說:不,這是給超人的,請在最后寫上 “I love you Superman.”。
好的,我們來寫:
<div style="width:550px;">
<h1>Bat Letter</h1>
<img src="bat-logo.jpeg" style="width:100%">
<p>
After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
<h2>You are the light of my life</h2>
<p>
You complete my darkness with your light. I love:
</p>
<ul>
<li>the way you see good in the worse</li>
<li>the way you handle emotionally difficult situations</li>
<li>the way you look at Justice</li>
</ul>
<p>
I have learned a lot from you. You have occupied a special place in my heart over the time.
</p>
<h2>I have a confession to make</h2>
<p>
It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.
</p>
<p>
I don't show my emotions, but I think this man behind the mask is falling for you.
</p>
<p>I love you Superman.</p>
<p>
Your not-so-secret-lover, <br>
Batman
</p>
</div>
這封信差不多完成了,蝙蝠俠另外想再做兩次改變。蝙蝠俠希望在最后段落的第一句中的 “does” 一詞是斜體,而 “I love you Superman” 這句話是粗體的。
我們使用 <em> 和 <strong> 以斜體和粗體顯示文本。讓我們來更新這些更改:
<div style="width:550px;">
<h1>Bat Letter</h1>
<img src="bat-logo.jpeg" style="width:100%">
<p>
After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
<h2>You are the light of my life</h2>
<p>
You complete my darkness with your light. I love:
</p>
<ul>
<li>the way you see good in the worse</li>
<li>the way you handle emotionally difficult situations</li>
<li>the way you look at Justice</li>
</ul>
<p>
I have learned a lot from you. You have occupied a special place in my heart over the time.
</p>
<h2>I have a confession to make</h2>
<p>
It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.
</p>
<p>
I don't show my emotions, but I think this man behind the mask is falling for you.
</p>
<p><strong>I love you Superman.</strong></p>
<p>
Your not-so-secret-lover, <br>
Batman
</p>
</div>
你可以通過三種方式設置樣式或定義 HTML 元素的外觀:
讓我們來看看如何定義 <div> 的內聯樣式:
<div style="width:550px;">
我們可以在 <style> 和 </style> 里面寫同樣的樣式:
div{
width:550px;
}
在嵌入式樣式中,我們編寫的樣式是與元素分開的。所以我們需要一種方法來關聯元素及其樣式。第一個單詞 “div” 就做了這樣的活。它讓瀏覽器知道花括號 {...} 里面的所有樣式都屬于 “div” 元素。由于這種語法確定要應用樣式的元素,因此它稱為一個選擇器。
我們編寫樣式的方式保持不變:屬性(width)和值(550px)用冒號(:)分隔,以分號(;)結束。
讓我們從 <div> 和 <img> 元素中刪除內聯樣式,將其寫入 <style> 元素:
<style>
div{
width:550px;
}
img{
width:100%;
}
</style>
<div>
<h1>Bat Letter</h1>
<img src="bat-logo.jpeg">
<p>
After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
<h2>You are the light of my life</h2>
<p>
You complete my darkness with your light. I love:
</p>
<ul>
<li>the way you see good in the worse</li>
<li>the way you handle emotionally difficult situations</li>
<li>the way you look at Justice</li>
</ul>
<p>
I have learned a lot from you. You have occupied a special place in my heart over the time.
</p>
<h2>I have a confession to make</h2>
<p>
It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.
</p>
<p>
I don't show my emotions, but I think this man behind the mask is falling for you.
</p>
<p><strong>I love you Superman.</strong></p>
<p>
Your not-so-secret-lover, <br>
Batman
</p>
</div>
保存并刷新,結果應保持不變。
但是有一個大問題,如果我們的 HTML 文件中有多個 <div> 和 <img> 元素該怎么辦?這樣我們在 <style> 元素中為 div 和 img 定義的樣式就會應用于頁面上的每個 div 和 img。
如果你在以后的代碼中添加另一個 div,那么該 div 也將變為 550px 寬。我們并不希望這樣。
我們想要將我們的樣式應用于現在正在使用的特定 div 和 img。為此,我們需要為 div 和 img 元素提供唯一的 id。以下是使用 id 屬性為元素賦予 id 的方法:
<div id="letter-container">
以下是如何在嵌入式樣式中將此 id 用作選擇器:
#letter-container{
...
}
注意 # 符號。它表示它是一個 id,{...} 中的樣式應該只應用于具有該特定 id 的元素。
讓我們來應用它:
<style>
#letter-container{
width:550px;
}
#header-bat-logo{
width:100%;
}
</style>
<div id="letter-container">
<h1>Bat Letter</h1>
<img id="header-bat-logo" src="bat-logo.jpeg">
<p>
After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
<h2>You are the light of my life</h2>
<p>
You complete my darkness with your light. I love:
</p>
<ul>
<li>the way you see good in the worse</li>
<li>the way you handle emotionally difficult situations</li>
<li>the way you look at Justice</li>
</ul>
<p>
I have learned a lot from you. You have occupied a special place in my heart over the time.
</p>
<h2>I have a confession to make</h2>
<p>
It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.
</p>
<p>
I don't show my emotions, but I think this man behind the mask is falling for you.
</p>
<p><strong>I love you Superman.</strong></p>
<p>
Your not-so-secret-lover, <br>
Batman
</p>
</div>
HTML 已經準備好了嵌入式樣式。
但是,你可以看到,隨著我們包含越來越多的樣式,<style></style> 將變得很大。這可能很快會混亂我們的主 HTML 文件。
因此,讓我們更進一步,通過將 <style> 標簽內的內容復制到一個新文件來使用鏈接樣式。
在項目根目錄中創建一個新文件,將其另存為 “style.css”:
#letter-container{
width:550px;
}
#header-bat-logo{
width:100%;
}
我們不需要在 CSS 文件中寫 <style> 和 </style>。
我們需要使用 HTML 文件中的 <link> 標簽來將新創建的 CSS 文件鏈接到 HTML 文件。以下是我們如何做到這一點:
<link rel="stylesheet" type="text/css" href="style.css">
我們使用 <link> 元素在 HTML 文檔中包含外部資源,它主要用于鏈接樣式表。我們使用的三個屬性是:
link 元素的結尾沒有 </link>。因此,<link> 也是一個自閉合的標簽。
<link rel="gf" type="cute" href="girl.next.door">
如果只是得到一個女朋友,那么很容易:D
可惜沒有那么簡單,讓我們繼續前進。
這是我們 “loveletter.html” 的內容:
<link rel="stylesheet" type="text/css" href="style.css">
<div id="letter-container">
<h1>Bat Letter</h1>
<img id="header-bat-logo" src="bat-logo.jpeg">
<p>
After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
<h2>You are the light of my life</h2>
<p>
You complete my darkness with your light. I love:
</p>
<ul>
<li>the way you see good in the worse</li>
<li>the way you handle emotionally difficult situations</li>
<li>the way you look at Justice</li>
</ul>
<p>
I have learned a lot from you. You have occupied a special place in my heart over the time.
</p>
<h2>I have a confession to make</h2>
<p>
It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.
</p>
<p>
I don't show my emotions, but I think this man behind the mask is falling for you.
</p>
<p><strong>I love you Superman.</strong></p>
<p>
Your not-so-secret-lover, <br>
Batman
</p>
</div>
“style.css” 內容:
#letter-container{
width:550px;
}
#header-bat-logo{
width:100%;
}
保存文件并刷新,瀏覽器中的輸出應保持不變。
我們的情書已經準備好給蝙蝠俠,但還有一些正式的片段。
與其他任何編程語言一樣,HTML 自出生以來(1990 年)經歷過許多版本,當前版本是 HTML5。
那么,瀏覽器如何知道你使用哪個版本的 HTML 來編寫頁面呢?要告訴瀏覽器你正在使用 HTML5,你需要在頁面頂部包含 <!DOCTYPE html>。對于舊版本的 HTML,這行不同,但你不需要了解它們,因為我們不再使用它們了。
此外,在之前的 HTML 版本中,我們曾經將整個文檔封裝在 <html></html> 標簽內。整個文件分為兩個主要部分:頭部在 <head></head> 里面,主體在 <body></body> 里面。這在 HTML5 中不是必須的,但由于兼容性原因,我們仍然這樣做。讓我們用 <Doctype>, <html>、 <head> 和 <body> 更新我們的代碼:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="letter-container">
<h1>Bat Letter</h1>
<img id="header-bat-logo" src="bat-logo.jpeg">
<p>
After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
<h2>You are the light of my life</h2>
<p>
You complete my darkness with your light. I love:
</p>
<ul>
<li>the way you see good in the worse</li>
<li>the way you handle emotionally difficult situations</li>
<li>the way you look at Justice</li>
</ul>
<p>
I have learned a lot from you. You have occupied a special place in my heart over the time.
</p>
<h2>I have a confession to make</h2>
<p>
It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.
</p>
<p>
I don't show my emotions, but I think this man behind the mask is falling for you.
</p>
<p><strong>I love you Superman.</strong></p>
<p>
Your not-so-secret-lover, <br>
Batman
</p>
</div>
</body>
</html>
主要內容在 <body> 里面,元信息在 <head> 里面。所以我們把 <div> 保存在 <body> 里面并加載 <head> 里面的樣式表。
保存并刷新,你的 HTML 頁面應顯示與之前相同的內容。
我發誓,這是最后一次改變。
你可能已經注意到選項卡的標題正在顯示 HTML 文件的路徑:
我們可以使用 <title> 標簽來定義 HTML 文件的標題。標題標簽也像鏈接標簽一樣在 <head> 內部。讓我們我們在標題中加上 “Bat Letter”:
<!DOCTYPE html>
<html>
<head>
<title>Bat Letter</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="letter-container">
<h1>Bat Letter</h1>
<img id="header-bat-logo" src="bat-logo.jpeg">
<p>
After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
</p>
<h2>You are the light of my life</h2>
<p>
You complete my darkness with your light. I love:
</p>
<ul>
<li>the way you see good in the worse</li>
<li>the way you handle emotionally difficult situations</li>
<li>the way you look at Justice</li>
</ul>
<p>
I have learned a lot from you. You have occupied a special place in my heart over the time.
</p>
<h2>I have a confession to make</h2>
<p>
It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.
</p>
<p>
I don't show my emotions, but I think this man behind the mask is falling for you.
</p>
<p><strong>I love you Superman.</strong></p>
<p>
Your not-so-secret-lover, <br>
Batman
</p>
</div>
</body>
</html>
保存并刷新,你將看到在選項卡上顯示的是 “Bat Letter” 而不是文件路徑。
蝙蝠俠的情書現在已經完成。
恭喜!你用 HTML 制作了蝙蝠俠的情書。
我們學習了以下新概念:
我們學習了以下 HTML 標簽:
我們學習了以下 CSS 屬性:
朋友們,這就是今天的全部了,下一個教程中見。
作者簡介:開發者 + 作者 | supersarkar.com | twitter.com/supersarkar
via: https://medium.freecodecamp.org/for-your-first-html-code-lets-help-batman-write-a-love-letter-64c203b9360b
作者: Kunal Sarkar 譯者: MjSeven 校對: wxy
本文由 LCTT 原創編譯, Linux中國 榮譽推出
Low了,網頁居然還用這么老掉牙的特效!弄個粗體字,下劃線就是突出重點了?真是一股濃濃的鄉村風撲面而來;弄個圖在頁面飄來飄去就是動畫效果了,你要這么認為的話那我只能保持沉默了。在HTML5占領著整個互聯網之時,想透過網頁抓住所有人的眼球,因循守舊是行不通的。因此,有你不能不知道的HTML常用代碼。只有熟悉掌握了常用的HTML代碼,你才能在編寫網頁的時候做到行云流水,用處處流露著細膩和創意的動效細節打動所有人。
在這里還是要說一下我自己建的前端JavaScript學習交流群:574462090,不管你是小白還是大牛,小編我都挺歡迎,小白嘛,多問點問題也就學好了,不定期分享干貨,包括最新的2017年前端學習資料,歡迎初學和進階中的小伙伴。
html代碼大全:結構性定義
文件類型<HTML></HTML> (放在檔案的開頭與結尾)
文件主題<TITLE></TITLE> (必須放在「文頭」區塊內)
文頭<HEAD></HEAD> (描述性資料,像是「主題」)
文體<BODY></BODY> (文件本體)
標題<H?></H?> (從1到6,有六層選擇)
標題的對齊 <H?ALIGN=LEFT|CENTER|RIGHT></H?>
區分<DIV></DIV>
區分的對齊 <DIVALIGN=LEFT|RIGHT|CENTER|JUSTIFY></DIV>
引文區塊<BLOCKQUOTE></BLOCKQUOTE> (通常會內縮)
強調<EM></EM> (通常會以斜體顯示)
特別強調<STRONG></STRONG> (通常會以加粗顯示)
引文<CITE></CITE> (通常會以斜體顯示)
碼<CODE></CODE> (顯示原始碼之用)
樣本<SAMP></SAMP>
鍵盤輸入<KBD></KBD>
變數<VAR></VAR>
定義<DFN></DFN> (有些瀏覽器不提供)
地址 <ADDRESS></ADDRESS>
大字<BIG></BIG>
小字<SMALL></SMALL>
與外觀相關的標簽(作者自訂的表現方式)
加粗<B></B>
斜體<I></I>
底線<U></U> (尚有些瀏覽器不提供)
刪除線<S></S> (尚有些瀏覽器不提供)
下標<SUB></SUB>
上標<SUP></SUP>
打字機體<TT></TT> (用單空格字型顯示)
預定格式<PRE></PRE> (保留文件中空格的大小)
預定格式的寬度<PRE WIDTH=?></PRE>(以字元計算)
向中看齊<CENTER></CENTER> (文字與圖片都可以)
閃耀<BLINK></BLINK> (有史以來最被嘲弄的標簽)
字體大小 <FONTSIZE=?></FONT>(從1到7)
改變字體大小 <FONTSIZE=+|-?></FONT>
基本字體大小 <BASEFONTSIZE=?> (從1到7; 內定為3)
字體顏色 <FONTCOLOR="#$$"></FONT>($$為顏色代碼)
2
html代碼大全:修改頁面的實用性HTML代碼
1)貼圖:<img src="圖片地址">
2)加入連接:<a href="所要連接的相關地址">寫上你想寫的字</a>
3)在新窗口打開連接:<a href="相關地址" target="_blank">寫上要寫的字</a>
4)移動字體(走馬燈):<marquee>寫上你想寫的字</marquee>
5)字體加粗:<b>寫上你想寫的字</b>
6)字體斜體:<i>寫上你想寫的字</i>
7)字體下劃線: <u>寫上你想寫的字</u>
8)字體刪除線: <s>寫上你想寫的字</s>
9)字體加大: <big>寫上你想寫的字</big>
10)字體控制大小:<h1>寫上你想寫的字</h1> (其中字體大小可從h1-h5,h1最大,h5最小)
11)更改字體顏色:<font color="#value">寫上你想寫的字</font>(其中value值在000000與ffffff(16位進制)之間
12)消除連接的下劃線:<a href="相關地址" style="text-decoration:none">寫上你想寫的字</a>
13)貼音樂:<embed src="音樂地址" width="寬度" height="高度" autostart=false>
14)貼flash: <embed src="flash地址" width="寬度" height="高度">
15)貼影視文件:<img dynsrc="文件地址" width="寬度" height="高度" start=mouseover>
16)換行:<br>
17)段落:<p>段落</p>
18)原始文字樣式:<pre>正文</pre>
19)換帖子背景:<body background="背景圖片地址">
20)固定帖子背景不隨滾動條滾動:<body background="背景圖片地址" body
bgproperties=fixed>
21)定制帖子背景顏色:<body bgcolor="#value">(value值見10)
22)帖子背景音樂:<bgsound="背景音樂地址" loop=infinite>
23)貼網頁:<iframe. src="相關地址" width="寬度" height="高度"></iframe>
3
html代碼大全:常常會遇到的問題
點擊關閉窗口
<a href="javascript.:top.window.close();">點擊關閉窗口</a>!
請問如何去掉主頁右面的滾動條?
<body scroll="no">
<body style="overflow-y:hidden">
如何做到讓一個網頁自動關閉.
<html>
<head>
<OBJECT id=closes type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param name="Command" value="Close">
</object>
</head>
<body >
這個窗口會在10秒過后自動關閉,而且不會出現提示. </body>
如何在不刷新頁面的情況下刷新css?
<style>
button{ color:#000000;}
</style>
<button nclick=document.styleSheets[0].rules[0].style.color=‘‘‘‘red‘‘‘‘>點擊按鈕直接修改style標簽里button選擇符使按鈕改為 紅色</button>
請問如何讓網頁自動刷新?
在head部記入<META. HTTP-EQUIV="Refresh" c>其中20為20秒后自動刷新,你可以更改為任意值。
如何讓頁面自動刷新?
方法一,用refresh
HTML 代碼片段如下:
<head>
<meta. http-equiv="refresh" c>
</head>
5表示刷新時間
[Ctrl+A 全部選擇 提示:你可先修改部分代碼,再按運行]
方法二,使用setTimeout控制
<img src=/logo.gif>
<script>
function rl(){
document.location.reload()
}
setTimeout(rl,2000)
</SCRIPT>
如何讓超鏈接沒有下劃線
在源代碼中的<HEAD>…</HEAD>之間輸入如下代碼:
<style. type="text/css"> <!--
a { text-decoration: none}
--> </style>
請問如何去掉IE的上下滾動條?
<body style=‘‘‘‘overflow:scroll;overflow-y:hidden‘‘‘‘>
</body>
怎樣才能把RealPlayer文件在網頁做一個試聽連接?
<embed height=25 src=51js.rm type=audio/x-pn-realaudio-plugin width=50 autostart="false" c>
如何用html實現瀏覽器上后退按鈕的功能?
<a href="java script.:history.go(-1)">點擊后退</a>
或者
<script> history.back() </SCRIPT>
4
html代碼大全:你不一定知道的技巧
16. ncontextmenu="window.event.returnValue=false" 將徹底屏蔽鼠標右鍵
<table borderncontextmenu=return(false)><td>no</table> 可用于Table
17. <body nselectstart="return false"> 取消選取、防止復制
18.onpaste="return false" 不準粘貼
19.oncopy="return false;" ncut="return false;" 防止復制
20. <link rel="Shortcut Icon"href="favicon.ico"> IE地址欄前換成自己的圖標
21. <link rel="Bookmark"href="favicon.ico"> 可以在收藏夾中顯示出你的圖標
22. <inputstyle="ime-mode:disabled"> 關閉輸入法
23. 永遠都會帶著框架
<script. language="JavaScript"><!--
if (window == top)top.location.href = "frames.htm"; //frames.htm為框架網頁
// --></script>
24. 防止被人frame.
<SCRIPT. LANGUAGE=JAVASCRIPT><!--
if (top.location != self.location)top.location=self.location;
// --></SCRIPT>
25. 網頁將不能被另存為
<noscript><iframe.src=*.html></iframe></noscript>
26. 查看網頁源代碼
<input type=button value=查看網頁源代碼
onclick="window.location = "view-source:"+"http://www.pconline.com.cn"">
27.刪除時確認
<a href="javascript:if(confirm("確實要刪除嗎?"))location="boos.asp? &areyou=刪除&page=1"">刪除</a>
28.屏蔽功能鍵Shift,Alt,Ctrl
<script>
function look(){
if(event.shiftKey)
alert("禁止按Shift鍵!");//可以換成ALT CTRL
}
document.onkeydown=look;
</script>
29. 網頁不會被緩存
<META. HTTP-EQUIV="pragma" CONTENT="no-cache">
<META. HTTP-EQUIV="Cache-Control"CONTENT="no-cache, must-revalidate">
<META. HTTP-EQUIV="expires"CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
或者<META. HTTP-EQUIV="expires"CONTENT="0">
30.怎樣讓表單沒有凹凸感?
<input type=text style="border:1 solid #000000">
或 <input type=text style="border-left:none;border-right:none; border -top:none; border-bottom: 1 solid#000000"></textarea>
31.不要滾動條?
讓豎條沒有:
<body style="overflow:scroll;overflow-y:hidden">
</body>
讓橫條沒有:
<body style="overflow:scroll;overflow-x:hidden">
</body>
兩個都去掉?更簡單了
<body scroll="no">
</body>
32.怎樣去掉圖片鏈接點擊后,圖片周圍的虛線?
<a href="#"nFocus="this.blur()"><img src="logo.jpg"border=0></a>
33.電子郵件處理提交表單
<form. name="form1"method="post" action="mailt****@***.com"enctype="text/plain">
<input type=submit>
</form>
34.在打開的子窗口刷新父窗口的代碼里如何寫?
window.opener.location.reload()
35.如何設定打開頁面的大小
<body nload="top.resizeTo(300,200);">
打開頁面的位置<bodynload="top.moveBy(300,200);">
36.在頁面中如何加入不是滿鋪的背景圖片,拉動頁面時背景圖不動
<STYLE>
body
{background-image:url(logo.gif); background-repeat:no-repeat;
background-position:center;background-attachment: fixed}
</STYLE>
37. 檢查一段字符串是否全由數字組成
<script. language="Javascript"><!--
function checkNum(str){return str.match(//D/)==null}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
// --></script>
38. 獲得一個窗口的大小
document.body.clientWidth; document.body.clientHeight
39. 怎么判斷是否是字符
if (/[^/x00-/xff]/g.test(s)) alert("含有漢字");
else alert("全是字符");
40.TEXTAREA自適應文字行數的多少
<textarea rows=1 name=s1 cols=27npropertychange="this.style.posHeight=this.scrollHeight">
</textarea>
41. 日期減去天數等于第二個日期
<script. language=Javascript>
function cc(dd,dadd)
{
//可以加上錯誤處理
var a = new Date(dd)
a = a.valueOf()
a = a - dadd * 24 * 60 * 60 * 1000
a = new Date(a)
alert(a.getFullYear() + "年" + (a.getMonth() +1) + "月" + a.getDate() + "日")
} cc("12/23/2002",2)
</script>
42. 選擇了哪一個Radio
<HTML><script. language="vbscript">
function checkme()
for each ob in radio1
if ob.checked then window.alert ob.value
next
end function
</script><BODY>
<INPUT name="radio1" type="radio"value="style" checked>Style.
<INPUT name="radio1" type="radio"value="barcode">Barcode
<INPUT type="button" value="check"nclick="checkme()">
</BODY></HTML>
43.腳本永不出錯
<SCRIPT. LANGUAGE="JavaScript">
<!-- Hide function killErrors(){return true;} window.onerror = killErrors;// -->
</SCRIPT>
44.ENTER鍵可以讓光標移到下一個輸入框
<input nkeydown="if(event.keyCode==13)event.keyCode=9">
文末再提兩點建議吧:
剛學前端JavaScript的時候,一定不要追求速成,編程不比其他傳統行業,可以快速的上手,他需要一定的代碼量積累起來,不然你追求速成很可能會車毀人亡。
這個文章到這里就說完了,想要前端學習資料的進我的群自助領取,已經上傳到群文件里了:574462090,歡迎初學和進階中的小伙伴。
*請認真填寫需求信息,我們會在24小時內與您取得聯系。