佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > HTML5幾個(gè)設(shè)計(jì)和修改的頁(yè)面范例分享

HTML5幾個(gè)設(shè)計(jì)和修改的頁(yè)面范例分享

熱門標(biāo)簽:使用U盤裝系統(tǒng) 阿里云 網(wǎng)站建設(shè) 硅谷的囚徒呼叫中心 美圖手機(jī) 百度競(jìng)價(jià)點(diǎn)擊價(jià)格的計(jì)算公式 檢查注冊(cè)表項(xiàng) 智能手機(jī)

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

ApocalypsePage_Original.html,這是一個(gè)格式非常規(guī)范的頁(yè)面,所有的樣式均來(lái)自于外部樣式表。

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <!DOCTYPE html>  
  2. <html lang="zh-CN">  
  3. <head>  
  4.   <meta charset="utf-8">  
  5.   <title>Apocalypse Now</title>  
  6.   <link rel="stylesheet" href="ApocalypsePage_Original.css">  
  7. </head>  
  8.   
  9. <body>  
  10. <div class="Header">  
  11.   <h1>How the World Could End</h1>  
  12.   <p class="Teaser">Scenarios that spell the end of life as we know</p>  
  13.   <p class="Byline">by Ray N. Carnation</p>  
  14. </div><!-- end Header -->  
  15.   
  16. <div class="Content">  
  17.   <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>  
  18.   <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>  
  19.      
  20.   <h2>Mayan Doomsday</h2>  
  21.   <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>  
  22.      
  23.   <h2>Robot Takeover</h2>  
  24.   <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>  
  25.      
  26.   <h2>Unexplained Singularity</h2>  
  27.   <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>  
  28.      
  29.   <h2>Runaway Climate Change</h2>  
  30.   <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>  
  31.      
  32.   <h2>Global Epidemic</h2>  
  33.   <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>  
  34.   
  35. </div><!-- end Content -->  
  36.   
  37. <div class="Footer">  
  38.   <p class="Disclaimer">These apocalyptic predictions do not reflect the views of the author.</p>  
  39.   <p>  
  40.     <a href="AboutUs.html">About Us</a>  
  41.     <a href="Disclaimer.html">Disclaimer</a>  
  42.     <a href="ContactUs.html">Contact Us</a>  
  43.   </p>  
  44.   <p>Copyright © 2014</p>  
  45. </div><!-- end Footer -->  
  46. </body>  
  47. </html>  

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

上面通過(guò)三個(gè) <div> 將頁(yè)面分成了三個(gè)部分,頂部的頁(yè)眉,中部的內(nèi)容和底部的頁(yè)腳。

這個(gè)例子中的樣式表很簡(jiǎn)單,整個(gè)頁(yè)面最大寬度設(shè)置為 800 像素,避免文本在寬屏顯示器上顯示過(guò)長(zhǎng)。頁(yè)眉位于一個(gè)帶有藍(lán)色邊框的盒子中,內(nèi)容區(qū)的兩側(cè)都增加了內(nèi)邊距,而頁(yè)腳在整個(gè)頁(yè)面的底部居中。

ApocalypsePage_Original.css樣式文件內(nèi)容如下:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. @charset "utf-8";   
  2. /* CSS Document */   
  3. body{   
  4.   /*font-family 要使用安全字體,按照先特殊后一般的原則,   
  5.   先給出你想要的字體,然后是保險(xiǎn)一些的字體,   
  6.   最后以 sans-serif 字體結(jié)尾*/   
  7.   font-family: "Lucida sans Unicode", "Lucida Grande", Geneva, sans-serif;   
  8.   max-width: 800px; /*最大寬度不超過(guò) 800 像素*/   
  9. }   
  10. /*頁(yè)面頂部的標(biāo)題區(qū)樣式*/   
  11. .Header {   
  12.   background-color: #7695FE; /*可接受任何顏色值*/   
  13.   border: thin #336699 solid; /*多合一的 border 屬性*/   
  14.   padding: 10px; /* 10像素的內(nèi)邊距,邊框與內(nèi)容之間的距離*/   
  15.   margin: 10px; /* 10像素的外邊距,邊框與周圍元素之間的距離*/   
  16.   text-align: center; /*頭部文本居中*/   
  17. }   
  18. /*頁(yè)眉中標(biāo)題<h1>樣式*/   
  19. .Header h1{   
  20.   margin: 0px;   
  21.   color: white;   
  22.   font-size: xx-large; /*精確控制可以用像素或者em單位*/   
  23. }   
  24. /*頁(yè)眉中子標(biāo)題樣式*/   
  25. .Header .Teaser{   
  26.   margin: 0px;   
  27.   font-weight: bold;   
  28. }   
  29. /*頁(yè)眉中署名行樣式*/   
  30. .Header .Byline{   
  31.   font-style: italic;   
  32.   font-size: small;   
  33.   margin: 0px;   
  34. }   
  35. .Content{   
  36.   font-size: medium;   
  37.   font-family: Cambria, Cochin, Georgia, "Times New Roman", Times, serif;   
  38.   /*左右內(nèi)邊距最大*/   
  39.   padding-top: 20px;   
  40.   padding-right: 50px;   
  41.   padding-bottom: 5px;   
  42.   padding-left: 50px;   
  43.   line-height: 120%; /*相鄰兩個(gè)文本行之間的距離*/   
  44. }   
  45. .Content .LeadIn{   
  46.   font-weight: bold;   
  47.   font-size: large;   
  48.   font-variant: small-caps;   
  49. }   
  50. .Content .h2{   
  51.   color: #24486C;   
  52.   margin-bottom: 2px;   
  53.   font-size: medium;   
  54. }   
  55. .Content p{   
  56.   margin-top: 0px;   
  57. }   
  58. .Footer{   
  59.   text-align: center;   
  60.   font-size: x-small;   
  61. }   
  62. .Footer .Disclaimer{   
  63.   font-style: italic;   
  64. }   
  65. .Footer p{   
  66.   margin: 3px;   
  67. }  

這樣我們的樣式表就彎沉過(guò)了,現(xiàn)在去看看結(jié)果會(huì)怎樣呢?如下圖:

使用 HTML5 來(lái)構(gòu)造頁(yè)面

<div> 目前仍舊是 Web 設(shè)計(jì)的必備元素,它是一個(gè)直觀、多用途的容器,可以通過(guò)它為頁(yè)面中的任何區(qū)塊應(yīng)用樣式。但 <div> 的問(wèn)題在于,它本身不反映與頁(yè)面相關(guān)的任何信息。

要通過(guò) HTML5 改進(jìn)這種情況,可以把 <div> 替換成更具有描述性語(yǔ)義的元素。

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

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <header>  
  2.   <h1>How the World Could End</h1>  
  3.   <p class="Teaser">Scenarios that spell the end of life as we know</p>  
  4.   <p class="Byline">by Ray N. Carnation</p>  
  5. </header>  
  6. ...   
  7. <footer>  
  8.   <p class="Disclaimer">These apocalyptic predictions do not reflect the views of the author.</p>  
  9.   <p>  
  10.     <a href="AboutUs.html">About Us</a>  
  11. ...   
  12.   </p>  
  13.   <p>Copyright © 2014</p>  
  14. </footer>  

當(dāng)然,對(duì)應(yīng)的 ApocalypsePage_Revised.css 文件也需要進(jìn)行修改,將其中的 .Header 和 .Footer 替換為 header 和 footer 。部分代碼如下:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. /*頁(yè)面頂部的標(biāo)題區(qū)樣式*/   
  2. header {   
  3.   background-color: #7695FE; /*可接受任何顏色值*/   
  4.   border: thin #336699 solid; /*多合一的 border 屬性*/   
  5.   padding: 10px; /* 10像素的內(nèi)邊距,邊框與內(nèi)容之間的距離*/   
  6.   margin: 10px; /* 10像素的外邊距,邊框與周圍元素之間的距離*/   
  7.   text-align: center; /*頭部文本居中*/   
  8. }   
  9. /*頁(yè)眉中標(biāo)題<h1>樣式*/   
  10. header h1{   
  11.   margin: 0px;   
  12.   color: white;   
  13.   font-size: xx-large; /*精確控制可以用像素或者em單位*/   
  14. }  

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

<ariticle>元素應(yīng)該包含新聞報(bào)道或文章的內(nèi)容,包括標(biāo)題、署名和正文。因此添加了 <article> 元素后的結(jié)構(gòu)如下:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <article>  
  2.   <header>  
  3.   <h1>How the World Could End</h1>  
  4.   <p class="Teaser">Scenarios that spell the end of life as we know</p>  
  5.   <p class="Byline">by Ray N. Carnation</p>  
  6.   </header>  
  7.   <div class="Content">  
  8.   <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>  
  9. ...   
  10.   </div><!-- end Content -->  
  11. </article>  


重新設(shè)計(jì)后,頁(yè)面結(jié)構(gòu)如下:

用 <figure> 添加插圖

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

一般來(lái)說(shuō)插圖應(yīng)該是浮動(dòng)的,還會(huì)有浮動(dòng)圖題。下面是在文章中添加插圖的 HTML 標(biāo)記,在正文的第一段和第二段之間的位置,部分代碼如下:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. ...   
  2. <div class="Content">  
  3. <p><span class="LeadIn">Right now</span>, you're ...</p>  
  4. <div class="FloatFigure">  
  5. <img src="human_skull.jpg" alt="Human skull">  
  6. <p>Will you be the last person standing if one of these apocalyptic   
  7. scenarios plays out?</p>  
  8. </div>  
  9. <p>But don't get too smug. There's...</p>  
  10. ...  


相應(yīng)的 樣式表規(guī)則如下:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. .FloatFigure{   
  2.   float: left;   
  3.   margin: 0px 20px 0px 0px;   
  4. }   
  5. .FloatFigure p{   
  6.   max-width: 300px;   
  7.   font-size: small;   
  8.   font-style: italic;   
  9.   margin-bottom: 5px;   
  10. }  


下圖展示了這個(gè)示例的外觀,插圖恰好在第一段文本之后,浮動(dòng)在后面文本的左側(cè),圖題的文本的寬度我們限制住了,讓圖題顯示很充實(shí)、很優(yōu)雅。

HTML5 中提供了一個(gè) <figure> 元素,圖題可以放在 <figure> 中的 <figcaption> 元素里,經(jīng)過(guò)改造,代碼如下:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <figure class="FloatFigure">  
  2.   <img src="human_skull.jpg" alt="Human skull">  
  3.   <figcaption>Will you be the last person standing if one of these apocalyptic   
  4.    scenarios plays out?</figcaption>  
  5. </figure>  


當(dāng)然樣式表中的選擇符,相應(yīng)修改一下即可。

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. .FloatFigure{   
  2.   float: left;   
  3.   margin: 0px 20px 0px 0px;   
  4. }   
  5. .FloatFigure figcaption{   
  6.   max-width: 300px;   
  7.   font-size: small;   
  8.   font-style: italic;   
  9.   margin-bottom: 5px;   
  10. }  


最后還有就是 <img> 元素中的 alt 屬性可以刪除掉,因?yàn)閳D題中包含了圖片的完整說(shuō)明。

用 <aside> 添加附注

新的 <aside> 元素表示與它周圍的文本沒(méi)有密切關(guān)系的內(nèi)容??梢酝ㄟ^(guò)它介紹另一個(gè)相關(guān)的話題,或者對(duì)主文檔中提出的某個(gè)觀點(diǎn)進(jìn)行解釋。還可以用來(lái)放置廣告、相關(guān)內(nèi)容鏈接。

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

部分代碼如下:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1.   <p>... (in a suitably robotic voice) "Who's your daddy now?"</p>  
  2.   
  3. <aside class="PullQuote">  
  4.   <img src="quotes_start.png" alt="Quote">  
  5.   We don't know how the universe started, so we can't be sure it won't just end, maybe today.   
  6.   <img src="quotes_end.png" alt="End quote">  
  7. </aside>  
  8.   
  9. <h2>Unexplained Singularity</h2>  


對(duì)應(yīng)的樣式表內(nèi)容如下:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. .PullQuote{   
  2.   float: right;   
  3.   max-width: 300px;   
  4.   border-top: thin black solid;   
  5.   border-bottom: thick black solid;   
  6.   font-size: 30px;   
  7.   line-height: 130%;   
  8.   font-style: italic;   
  9.   padding-top: 5px;   
  10.   padding-bottom: 5px;   
  11.   margin-left: 15px;   
  12.   margin-bottom: 10px;   
  13. }   
  14. .PullQuote img{   
  15.   vertical-align: bottom;   
  16. }  

標(biāo)簽:湘潭 賀州 通遼 煙臺(tái) 湖北 山南 懷化 黃山

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《HTML5幾個(gè)設(shè)計(jì)和修改的頁(yè)面范例分享》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    定兴县| 安义县| 荥阳市| 博客| 东城区| 德化县| 英超| 沾益县| 湖南省| 绥棱县| 开远市| 泸定县| 沂南县| 广安市| 睢宁县| 贵阳市| 徐州市| 襄城县| 定安县| 比如县| 大石桥市| 象山县| 枣阳市| 宜宾市| 洛南县| 和龙市| 斗六市| 和硕县| 金塔县| 浠水县| 荆州市| 新竹市| 皋兰县| 蒲江县| 资兴市| 南投县| 来宾市| 偏关县| 鄄城县| 潼南县| 丰都县|