努力学习 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.mzph.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;可以使用完全二叉树的性质求父子节点的下标。 …