努力學習 HTML5 (3)—— 改造傳統的 HTML 頁面

要了解和熟悉 HTML5 中的新的語義元素,最好的方式就是拿一經典的 HTML 文檔作例子,然后把 HTML5 的一些新鮮營養充實進入。如下就是我們要改造的頁面,該頁面很簡單,只包含一篇文章。

ApocalypsePage_Original.html,這是一個格式非常規范的頁面,所有的樣式均來自于外部樣式表。

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="utf-8"><title>Apocalypse Now</title><link rel="stylesheet" href="ApocalypsePage_Original.css">
</head><body>
<div class="Header"><h1>How the World Could End</h1><p class="Teaser">Scenarios that spell the end of life as we know</p><p class="Byline">by Ray N. Carnation</p>
</div><!-- end Header --><div class="Content"><p><span class="LeadIn">Right now</span>, you're probably feeling pretty good. After all, life in the developed world is comfortable<span class="style1"></span>probably more comfortable than it's been for the average human being throughout all of recorded history.</p><p>But don't get too smug. There's still plenty of horrific ways it could all fall apart. In this article, you'll learn about a few of our favorites.</p><h2>Mayan Doomsday</h2><p>Skeptics suggest that the Mayan calendar simply rolls to a new 5,126-year era after 2012, and doesn't actually predict a life-ending apocalypse. But given that the long-dead Mayans were wrong about virtually everything else, why should we trust them on this?</p><h2>Robot Takeover</h2><p>Not quite as frightening as a Vampire Takeover or Living-Dead Takeover, a robot rebellion is still a disquieting thought. We are already outnumbered by our technological gadgets, and even Bill Gates fears the day his Japanese robot slave turns him over by the ankles and asks (in a suitably robotic voice) "Who's your daddy now?"</p><h2>Unexplained Singularity</h2><p>We don't know how the universe started, so we can't be sure it won't just end, maybe today, and maybe with nothing more exciting than a puff of anti-matter and a slight fizzing noise.</p><h2>Runaway Climate Change</h2><p>Dismissed by some, Al Gore's prophecy of doom may still come true. If it does, we may have to contend with vicious storms, widespread food shortages, and surly air conditioning repairmen.</p><h2>Global Epidemic</h2><p>Some time in the future, a lethal virus could strike. Predictions differ about the source of the disease, but candidates include monkeys in the African jungle, bioterrorists, birds and pigs with the flu, warriors from the future, an alien race, hospitals that use too many antibiotics, vampires, the CIA, and unwashed brussel sprouts. Whatever the source, it's clearly bad news.</p></div><!-- end Content --><div class="Footer"><p class="Disclaimer">These apocalyptic predictions do not reflect the views of the author.</p><p><a href="AboutUs.html">About Us</a><a href="Disclaimer.html">Disclaimer</a><a href="ContactUs.html">Contact Us</a></p><p>Copyright ? 2014</p>
</div><!-- end Footer -->
</body>
</html>

在不增加任何 CSS 樣式表之前,效果如下:

20150920008

上面通過三個 <div> 將頁面分成了三個部分,頂部的頁眉,中部的內容和底部的頁腳。

這個例子中的樣式表很簡單,整個頁面最大寬度設置為 800 像素,避免文本在寬屏顯示器上顯示過長。頁眉位于一個帶有藍色邊框的盒子中,內容區的兩側都增加了內邊距,而頁腳在整個頁面的底部居中。

ApocalypsePage_Original.css 樣式文件內容如下:

@charset "utf-8";
/* CSS Document */
body{/*font-family 要使用安全字體,按照先特殊后一般的原則,先給出你想要的字體,然后是保險一些的字體,最后以 sans-serif 字體結尾*/font-family: "Lucida sans Unicode", "Lucida Grande", Geneva, sans-serif;max-width: 800px; /*最大寬度不超過 800 像素*/
}/*頁面頂部的標題區樣式*/
.Header {background-color: #7695FE; /*可接受任何顏色值*/border: thin #336699 solid; /*多合一的 border 屬性*/padding: 10px; /* 10像素的內邊距,邊框與內容之間的距離*/margin: 10px; /* 10像素的外邊距,邊框與周圍元素之間的距離*/text-align: center; /*頭部文本居中*/
}/*頁眉中標題<h1>樣式*/
.Header h1{margin: 0px;color: white;font-size: xx-large; /*精確控制可以用像素或者em單位*/
}/*頁眉中子標題樣式*/
.Header .Teaser{margin: 0px;font-weight: bold;
}/*頁眉中署名行樣式*/
.Header .Byline{font-style: italic;font-size: small;margin: 0px;
}.Content{font-size: medium;font-family: Cambria, Cochin, Georgia, "Times New Roman", Times, serif;/*左右內邊距最大*/padding-top: 20px;padding-right: 50px;padding-bottom: 5px;padding-left: 50px;line-height: 120%; /*相鄰兩個文本行之間的距離*/
}.Content .LeadIn{font-weight: bold;font-size: large;font-variant: small-caps;
}.Content .h2{color: #24486C;margin-bottom: 2px;font-size: medium;
}.Content p{margin-top: 0px;
}.Footer{text-align: center;font-size: x-small;
}.Footer .Disclaimer{font-style: italic;
}.Footer p{margin: 3px;
}

這樣我們的樣式表就彎沉過了,現在去看看結果會怎樣呢?如下圖:

20150920009


使用 HTML5 來構造頁面

<div> 目前仍舊是 Web 設計的必備元素,它是一個直觀、多用途的容器,可以通過它為頁面中的任何區塊應用樣式。但 <div> 的問題在于,它本身不反映與頁面相關的任何信息。

要通過 HTML5 改進這種情況,可以把 <div> 替換成更具有描述性語義的元素。

ApocalypsePage_Revised.html 中已經將 class 屬性為 Header 和 Footer 兩個 <div> 替換為 <header><footer>,部分代碼如下:

<header><h1>How the World Could End</h1><p class="Teaser">Scenarios that spell the end of life as we know</p><p class="Byline">by Ray N. Carnation</p>
</header>
...
<footer><p class="Disclaimer">These apocalyptic predictions do not reflect the views of the author.</p><p><a href="AboutUs.html">About Us</a>
...</p><p>Copyright ? 2014</p>
</footer>

當然,對應的 ApocalypsePage_Revised.css 文件也需要進行修改,將其中的 .Header.Footer 替換為 headerfooter。部分代碼如下:

/*頁面頂部的標題區樣式*/
header {background-color: #7695FE; /*可接受任何顏色值*/border: thin #336699 solid; /*多合一的 border 屬性*/padding: 10px; /* 10像素的內邊距,邊框與內容之間的距離*/margin: 10px; /* 10像素的外邊距,邊框與周圍元素之間的距離*/text-align: center; /*頭部文本居中*/
}/*頁眉中標題<h1>樣式*/
header h1{margin: 0px;color: white;font-size: xx-large; /*精確控制可以用像素或者em單位*/
}

最后還有一個元素需要用在示例文件中,就是 <article> 元素,表示一個完整的、自成一體的內容。

<ariticle> 元素應該包含新聞報道或文章的內容,包括標題、署名和正文。因此添加了 <article> 元素后的結構如下:

<article>
  <header><h1>How the World Could End</h1><p class="Teaser">Scenarios that spell the end of life as we know</p><p class="Byline">by Ray N. Carnation</p>
  </header>  <div class="Content"><p><span class="LeadIn">Right now</span>, you're probably feeling pretty good. After all, life in the developed world is comfortable<span class="style1"></span>probably more comfortable than it's been for the average human being throughout all of recorded history.</p>
...
  </div><!-- end Content -->
</article>

重新設計后,頁面結構如下:

20150920010


用 <figure> 添加插圖

很多頁面都是包含圖片的。但是,插圖 (figure) 與圖片的概念還不完全一樣。插圖雖然獨立于文本,但是文本中會提到它。

一般來說插圖應該是浮動的,還會有浮動圖題。下面是在文章中添加插圖的 HTML 標記,在正文的第一段和第二段之間的位置,部分代碼如下:

...
<div class="Content"><p><span class="LeadIn">Right now</span>, you're ...</p>  <div class="FloatFigure"><img src="human_skull.jpg" alt="Human skull"><p>Will you be the last person standing if one of these apocalypticscenarios plays out?</p></div><p>But don't get too smug. There's...</p>
...

相應的 樣式表規則如下:

.FloatFigure{float: left;margin: 0px 20px 0px 0px;
}.FloatFigure p{max-width: 300px;font-size: small;font-style: italic;margin-bottom: 5px;
}

下圖展示了這個示例的外觀,插圖恰好在第一段文本之后,浮動在后面文本的左側,圖題的文本的寬度我們限制住了,讓圖題顯示很充實、很優雅。

20150920011

HTML5 中提供了一個 <figure> 元素,圖題可以放在 <figure> 中的 <figcaption> 元素里,經過改造,代碼如下:

<figure class="FloatFigure"><img src="human_skull.jpg" alt="Human skull"><figcaption>Will you be the last person standing if one of these apocalypticscenarios plays out?</figcaption>
</figure>

當然樣式表中的選擇符,相應修改一下即可。

.FloatFigure{float: left;margin: 0px 20px 0px 0px;
}.FloatFigure figcaption{max-width: 300px;font-size: small;font-style: italic;margin-bottom: 5px;
}

最后還有就是 <img> 元素中的 alt 屬性可以刪除掉,因為圖題中包含了圖片的完整說明。


用 <aside> 添加附注

新的 <aside> 元素表示與它周圍的文本沒有密切關系的內容。可以通過它介紹另一個相關的話題,或者對主文檔中提出的某個觀點進行解釋。還可以用來放置廣告、相關內容鏈接。

下面的示例中將用作醒目引文(pull quote),使用 <div> 元素可以創造這種效果,但是用 <aside> 元素讓標記更有意義:

20150920012

部分代碼如下:

  <p>... (in a suitably robotic voice) "Who's your daddy now?"</p><aside class="PullQuote"><img src="quotes_start.png" alt="Quote">We don't know how the universe started, so we can't be sure it won't just end, maybe today.<img src="quotes_end.png" alt="End quote"></aside><h2>Unexplained Singularity</h2>

對應的樣式表內容如下:

.PullQuote{float: right;max-width: 300px;border-top: thin black solid;border-bottom: thick black solid;font-size: 30px;line-height: 130%;font-style: italic;padding-top: 5px;padding-bottom: 5px;margin-left: 15px;margin-bottom: 10px;
}.PullQuote img{vertical-align: bottom;
}

示例代碼

ApocalypsePage.rar

轉載于:https://www.cnblogs.com/pchmonster/p/4824893.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/375513.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/375513.shtml
英文地址,請注明出處:http://en.pswp.cn/news/375513.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

判斷系統是大端還是小段

大端&#xff1a;高位內存存儲低序字節小端&#xff1a;高位內存存儲高序字節short a 0x0102&#xff0c;其中 01 高序字節&#xff0c; 02 低序字節 #include<stdio.h>int main() {union {short s;char c[sizeof(short)];} un;un.s 0x0102;if (sizeof(short) 2) {if…

手機頁面head中的meta元素

<meta http-equiv"Pragma" content"no-cache"> <meta http-equiv"expires" content"0"> <meta http-equiv"cache-control" content"no-cache"> 清除瀏覽器中的緩存&#xff0c;它和其它幾句合起…

Delphi 關鍵 重啟 注銷

//在初始化的時候獲取權限 varhToken: THandle;Tkp: TTokenPrivileges;Zero: DWORD;beginOpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES orTOKEN_QUERY, hToken);LookupPrivilegeValue(nil, SeShutdownPrivilege, Tkp.Privileges[0].Luid);Tkp.PrivilegeCou…

C語言判斷系統是32位還是64位

long 在 32 位系統中是 4 字節&#xff0c;與 int 表示范圍相同&#xff0c;在 64 位系統中是 8 字節。 #include <stdio.h> #include <stdlib.h> #include <limits.h>int main() {long a INT_MAX;if (a 1 < 0) {printf("32: %ld\n", a);} e…

使用Eclipse搭建Struts2框架

本文轉自http://blog.csdn.net/liaisuo/article/details/9064527 今天在Eclipse搭建了Struts2 框架&#xff0c;并完成了一個很簡單的例子程序。 搭建好的全局圖如下: 第一步:在http://struts.apache.org/download.cgi下載Struts2的最新版即下載Full Distribution&#xff0c;這…

打印到類陣列的給定序列的所有排列的n皇后問題

題目例如以下&#xff1a;Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. 分析&#xff1a;假設僅僅是求排列數非常好算&#xff0c;可是…

asp網絡編程:ASP如何獲取客戶端真實IP地址

要想透過代理服務器取得客戶端的真實IP地址&#xff0c;就要使用 Request.ServerVariables("HTTP_X_FORWARDED_FOR") 來讀取。不過要注意的事&#xff0c;并不是每個代理服務器都能用 Request.ServerVariables("HTTP_X_FORWARDED_FOR") 來讀取客戶端的真實…

autoLayout自動布局

autoLayout 有兩個核心概念&#xff1a; 約束&#xff1a;就是對控件進行高度&#xff0c;寬度&#xff0c;相對位置的控制 參照&#xff1a;多個控件時&#xff0c;一個或多個控件以其中的一個為基準進行高度&#xff0c;寬度&#xff0c;位置的設置 當選擇了 use auto layout…

C++11實現自旋鎖

參見 《深入理解C11》 #include <thread> #include <atoimic> #include <iostream> #include <unistd.h> using namespace std;std::atomic_flag lock ATOMIC_FLAG_INIT; void f(int n) {while (lock.test_and_set(std::memory_order_acquire)) { //…

JDBC連接(MySql)數據庫步驟,以及查詢、插入、刪除、更新等十一個處理數據庫信息的功能。...

主要內容&#xff1a; JDBC連接數據庫步驟。一個簡單詳細的查詢數據的例子。封裝連接數據庫&#xff0c;釋放數據庫連接方法。實現查詢&#xff0c;插入&#xff0c;刪除&#xff0c;更新等十一個處理數據庫信息的功能。&#xff08;包括事務處理&#xff0c;批量更新等&#x…

atitit.軟件gui按鈕and面板---os區-----軟鏈接,快捷方式

atitit.軟件gui按鈕and面板---os區-----軟鏈接,快捷方式 1. 硬鏈接 1 2. 二、軟鏈接&#xff08;符號鏈接&#xff09;LN 1 3. 三、刪除鏈接 2 4. 區別 2 5. 參考 3 1. 硬鏈接 系統中,內核為每一個新創建的文件分配一個Inode(索引結點),每個文件都有一個惟一的inode號。文件屬性…

前K個高頻元素

給定一個非空的整數數組&#xff0c;返回其中出現頻率前 k 高的元素。 示例 1: 輸入: nums [1,1,1,2,2,3], k 2 輸出: [1,2] 示例 2:輸入: nums [1], k 1 輸出: [1]提示&#xff1a; 你可以假設給定的 k 總是合理的&#xff0c;且 1 ≤ k ≤ 數組中不相同的元素的個數。…

重拾qt

最近公司又接了一個煤礦的項目&#xff0c;要寫個小程序摘取數據&#xff0c;我是公司唯一c程序員&#xff0c;本來搞ios搞好好的&#xff0c;現在又得重拾半年沒摸得qt了。呵呵。。。呵呵呵。 這里只記錄這次小程序的一些小的總結吧。。 1、中文字符&#xff1a; 函數&#xf…

前K個高頻單詞

給一非空的單詞列表&#xff0c;返回前 k 個出現次數最多的單詞。 返回的答案應該按單詞出現頻率由高到低排序。如果不同的單詞有相同出現頻率&#xff0c;按字母順序排序。 示例 1&#xff1a; 輸入: ["i", "love", "leetcode", "i&quo…

thinkphp 刪除該表的最后一行

問題敘述性說明&#xff1a; 文章連接動態連接表格&#xff0c;因為有被添加。有必須刪除。動態添加到表格這似乎有點不合理。它應該只被添加到表格行。而不是增加一個新表格。發布完整的代碼在這里&#xff0c;加入表格新行和刪除表格最后一行。<html><script src&qu…

hdu 1421 dp

搬寢室 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18191 Accepted Submission(s): 6170 Problem Description搬寢室是很累的,xhd深有體會.時間追述2006年7月9號,那天xhd迫于無奈要從27號樓搬到3號樓,因為1…

socket 編程:回射客戶/服務程序

參考 《Unix 網絡編程》 github 地址 unp.h #include <stdio.h> #include <unistd.h> #include <arpa/inet.h> #include <string.h> #include <sys/socket.h> #include <stdlib.h> #include <errno.h> #include <sys/wait.h&g…

C++學習筆記25,析構函數總是會宣布virtual

為了永遠記住析構函數聲明virtual----><<effective c>> 為這句話不一定對,但無需質疑的是這句話是非常實用的. 查看以下的樣例: #include <iostream> #include <string> using namespace std; class B{ public:~B(){cout<<"base is dest…

BZOJ-1019 漢諾塔

其實只要非常了解漢諾塔的原理&#xff0c;或者是能計算出對于隨機數據一定有解的證明&#xff0c;那么這道題就是水題了。 【Code】轉載于:https://www.cnblogs.com/NanoApe/p/4396718.html

C++ 構建最小堆、最大堆

堆的屬性 完全二叉樹每個節點的值都大于&#xff08;最大堆&#xff09;或都小于&#xff08;最小堆&#xff09;子節點的值 堆只是一種數據的組織形式&#xff0c;存儲結構可以用數組&#xff0c;在構建堆的過程中&#xff0c;可以使用完全二叉樹的性質求父子節點的下標。 …