搜索
首页web前端H5教程HTML5几个设计和修改的页面范例分享_html5教程技巧

要了解和熟悉 HTML5 中的新的语义元素,最好的方式就是拿一经典的 HTML 文档作例子,然后把 HTML5 的一些新鲜营养充实进入。如下就是我们要改造的页面,该页面很简单,只包含一篇文章。

ApocalypsePage_Original.html,这是一个格式非常规范的页面,所有的样式均来自于外部样式表。

XML/HTML Code复制内容到剪贴板
  1. nbsp;html>  
  2. html lang="zh-CN">  
  3. head>  
  4.   meta charset="utf-8">  
  5.   title>Apocalypse Nowtitle>  
  6.   link rel="stylesheet" href="ApocalypsePage_Original.css">  
  7. head>  
  8.   
  9. body>  
  10. div class="Header">  
  11.   h1>How the World Could Endh1>  
  12.   p class="Teaser">Scenarios that spell the end of life as we knowp>  
  13.   p class="Byline">by Ray N. Carnationp>  
  14. div>  
  15.   
  16. div class="Content">  
  17.   p>span class="LeadIn">Right nowspan>, you're probably feeling pretty good. After all, life in the developed world is comfortablespan 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 Doomsdayh2>  
  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 Takeoverh2>  
  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 Singularityh2>  
  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 Changeh2>  
  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 Epidemich2>  
  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>  
  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 Usa>  
  41.     a href="Disclaimer.html">Disclaimera>  
  42.     a href="ContactUs.html">Contact Usa>  
  43.   p>  
  44.   p>Copyright © 2014p>  
  45. div>  
  46. body>  
  47. html>  

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

上面通过三个

将页面分成了三个部分,顶部的页眉,中部的内容和底部的页脚。

这个例子中的样式表很简单,整个页面最大宽度设置为 800 像素,避免文本在宽屏显示器上显示过长。页眉位于一个带有蓝色边框的盒子中,内容区的两侧都增加了内边距,而页脚在整个页面的底部居中。

ApocalypsePage_Original.css样式文件内容如下:

XML/HTML Code复制内容到剪贴板
  1. @charset "utf-8";   
  2. /* CSS Document */   
  3. body{   
  4.   /*font-family 要使用安全字体,按照先特殊后一般的原则,   
  5.   先给出你想要的字体,然后是保险一些的字体,   
  6.   最后以 sans-serif 字体结尾*/   
  7.   font-family: "Lucida sans Unicode", "Lucida Grande", Geneva, sans-serif;   
  8.   max-width: 800px; /*最大宽度不超过 800 像素*/   
  9. }   
  10. /*页面顶部的标题区样式*/   
  11. .Header {   
  12.   background-color: #7695FE; /*可接受任何颜色值*/   
  13.   border: thin #336699 solid; /*多合一的 border 属性*/   
  14.   padding: 10px; /* 10像素的内边距,边框与内容之间的距离*/   
  15.   margin: 10px; /* 10像素的外边距,边框与周围元素之间的距离*/   
  16.   text-align: center; /*头部文本居中*/   
  17. }   
  18. /*页眉中标题h1>样式*/   
  19. .Header h1{   
  20.   margin: 0px;   
  21.   color: white;   
  22.   font-size: xx-large; /*精确控制可以用像素或者em单位*/   
  23. }   
  24. /*页眉中子标题样式*/   
  25. .Header .Teaser{   
  26.   margin: 0px;   
  27.   font-weight: bold;   
  28. }   
  29. /*页眉中署名行样式*/   
  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.   /*左右内边距最大*/   
  39.   padding-top: 20px;   
  40.   padding-right: 50px;   
  41.   padding-bottom: 5px;   
  42.   padding-left: 50px;   
  43.   line-height: 120%; /*相邻两个文本行之间的距离*/   
  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. }  

这样我们的样式表就弯沉过了,现在去看看结果会怎样呢?如下图:

使用 HTML5 来构造页面

目前仍旧是 Web 设计的必备元素,它是一个直观、多用途的容器,可以通过它为页面中的任何区块应用样式。但
的问题在于,它本身不反映与页面相关的任何信息。

要通过 HTML5 改进这种情况,可以把

替换成更具有描述性语义的元素。

ApocalypsePage_Revised.html中已经将 class 属性为 Header 和 Footer 两个

替换为
, 部分代码如下:
XML/HTML Code复制内容到剪贴板
  1. header>  
  2.   h1>How the World Could Endh1>  
  3.   p class="Teaser">Scenarios that spell the end of life as we knowp>  
  4.   p class="Byline">by Ray N. Carnationp>  
  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 Usa>  
  11. ...   
  12.   p>  
  13.   p>Copyright © 2014p>  
  14. footer>  

当然,对应的 ApocalypsePage_Revised.css 文件也需要进行修改,将其中的 .Header 和 .Footer 替换为 header 和 footer 。部分代码如下:

XML/HTML Code复制内容到剪贴板
  1. /*页面顶部的标题区样式*/   
  2. header {   
  3.   background-color: #7695FE; /*可接受任何颜色值*/   
  4.   border: thin #336699 solid; /*多合一的 border 属性*/   
  5.   padding: 10px; /* 10像素的内边距,边框与内容之间的距离*/   
  6.   margin: 10px; /* 10像素的外边距,边框与周围元素之间的距离*/   
  7.   text-align: center; /*头部文本居中*/   
  8. }   
  9. /*页眉中标题h1>样式*/   
  10. header h1{   
  11.   margin: 0px;   
  12.   color: white;   
  13.   font-size: xx-large; /*精确控制可以用像素或者em单位*/   
  14. }  

最后还有一个元素需要用在示例文件中,就是

元素,表示一个完整的、自成一体的内容。

元素应该包含新闻报道或文章的内容,包括标题、署名和正文。因此添加了

元素后的结构如下:

XML/HTML Code复制内容到剪贴板
  1. article>  
  2.   header>  
  3.   h1>How the World Could Endh1>  
  4.   p class="Teaser">Scenarios that spell the end of life as we knowp>  
  5.   p class="Byline">by Ray N. Carnationp>  
  6.   header>  
  7.   div class="Content">  
  8.   p>span class="LeadIn">Right nowspan>, you're probably feeling pretty good. After all, life in the developed world is comfortablespan class="style1">span>probably more comfortable than it's been for the average human being throughout all of recorded history.p>  
  9. ...   
  10.   div>  
  11. article>  


重新设计后,页面结构如下:

添加插图

很多页面都是包含图片的。但是,插图 (figure) 与图片的概念还不完全一样。插图虽然独立于文本,但是文本中会提到它。

一般来说插图应该是浮动的,还会有浮动图题。下面是在文章中添加插图的 HTML 标记,在正文的第一段和第二段之间的位置,部分代码如下:

XML/HTML Code复制内容到剪贴板
  1. ...   
  2. div class="Content">  
  3. p>span class="LeadIn">Right nowspan>, 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. ...  


相应的 样式表规则如下:

XML/HTML Code复制内容到剪贴板
  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. }  


下图展示了这个示例的外观,插图恰好在第一段文本之后,浮动在后面文本的左侧,图题的文本的宽度我们限制住了,让图题显示很充实、很优雅。

HTML5 中提供了一个

元素,图题可以放在
中的
元素里,经过改造,代码如下:

XML/HTML Code复制内容到剪贴板
  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>  


当然样式表中的选择符,相应修改一下即可。

XML/HTML Code复制内容到剪贴板
  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. }  


最后还有就是 HTML5几个设计和修改的页面范例分享_html5教程技巧 元素中的 alt 属性可以删除掉,因为图题中包含了图片的完整说明。

新的

下面的示例中将用作醒目引文(pull quote),使用

元素可以创造这种效果,但是用
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
html5的div一行可以放两个吗html5的div一行可以放两个吗Apr 25, 2022 pm 05:32 PM

html5的div元素默认一行不可以放两个。div是一个块级元素,一个元素会独占一行,两个div默认无法在同一行显示;但可以通过给div元素添加“display:inline;”样式,将其转为行内元素,就可以实现多个div在同一行显示了。

html5中列表和表格的区别是什么html5中列表和表格的区别是什么Apr 28, 2022 pm 01:58 PM

html5中列表和表格的区别:1、表格主要是用于显示数据的,而列表主要是用于给数据进行布局;2、表格是使用table标签配合tr、td、th等标签进行定义的,列表是利用li标签配合ol、ul等标签进行定义的。

html5怎么让头和尾固定不动html5怎么让头和尾固定不动Apr 25, 2022 pm 02:30 PM

固定方法:1、使用header标签定义文档头部内容,并添加“position:fixed;top:0;”样式让其固定不动;2、使用footer标签定义尾部内容,并添加“position: fixed;bottom: 0;”样式让其固定不动。

html5中不支持的标签有哪些html5中不支持的标签有哪些Mar 17, 2022 pm 05:43 PM

html5中不支持的标签有:1、acronym,用于定义首字母缩写,可用abbr替代;2、basefont,可利用css样式替代;3、applet,可用object替代;4、dir,定义目录列表,可用ul替代;5、big,定义大号文本等等。

HTML5中画布标签是什么HTML5中画布标签是什么May 18, 2022 pm 04:55 PM

HTML5中画布标签是“<canvas>”。canvas标签用于图形的绘制,它只是一个矩形的图形容器,绘制图形必须通过脚本(通常是JavaScript)来完成;开发者可利用多种js方法来在canvas中绘制路径、盒、圆、字符以及添加图像等。

html5废弃了哪个列表标签html5废弃了哪个列表标签Jun 01, 2022 pm 06:32 PM

html5废弃了dir列表标签。dir标签被用来定义目录列表,一般和li标签配合使用,在dir标签对中通过li标签来设置列表项,语法“<dir><li>列表项值</li>...</dir>”。HTML5已经不支持dir,可使用ul标签取代。

Html5怎么取消td边框Html5怎么取消td边框May 18, 2022 pm 06:57 PM

3种取消方法:1、给td元素添加“border:none”无边框样式即可,语法“td{border:none}”。2、给td元素添加“border:0”样式,语法“td{border:0;}”,将td边框的宽度设置为0即可。3、给td元素添加“border:transparent”样式,语法“td{border:transparent;}”,将td边框的颜色设置为透明即可。

html5为什么只需要写doctypehtml5为什么只需要写doctypeJun 07, 2022 pm 05:15 PM

因为html5不基于SGML(标准通用置标语言),不需要对DTD进行引用,但是需要doctype来规范浏览器的行为,也即按照正常的方式来运行,因此html5只需要写doctype即可。“!DOCTYPE”是一种标准通用标记语言的文档类型声明,用于告诉浏览器编写页面所用的标记的版本。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具