没有合适的资源?快使用搜索试试~ 我知道了~
首页HTML&XHTML权威指南:第4版实例详解
"HTML & XHTML: The Definitive Guide" 是第四版由 Chuck Musciano 和 Bill Kennedy 合著的一本详尽指南,出版日期为 2000 年 8 月,ISBN 为 0-596-00026-X,共 677 页。该书旨在帮助读者深入理解和掌握网页制作技术,创建出功能强大、效果出色的网页,并能运用高级特性。
这本书首先介绍了互联网的基本概念,包括互联网、内联网(Intranets)和外联网(Extranets),以及网络语言的通用术语。作者解释了 HTML(HyperText Markup Language)和 XHTML(Extensible HyperText Markup Language)的本质区别,强调了两者之间的联系与区别,以及非标准扩展在实际应用中的注意事项。
对于初学者来说,书中提供了一个快速入门部分,涵盖了写作工具的选择,如何编写第一个 HTML 文档,嵌套标签的使用,以及构建一个基本的 HTML 或 XHTML 页面结构。内容详细到文本处理、超链接创建、图片的重要性、列表和搜索文档的制作,以及表格和框架的使用。
在这些基础知识之上,作者还探讨了 CSS(Cascading Style Sheets)和 JavaScript 在网页设计中的关键作用,如何利用它们来控制网页的外观和交互性。此外,书中还针对 HTML 4.01、Netscape 6.0 和 Internet Explorer 6.0 等不同浏览器的兼容性进行了讲解,确保读者的作品能在主流平台上正常运行。
《HTML & XHTML: The Definitive Guide》是一本实用的参考书籍,不仅适合初级开发者系统学习 HTML 和 XHTML 的基础,也为经验丰富的设计师提供了深入理解这两种语言和最新标准的平台。通过阅读这本书,读者将能够提升自己的网页开发技能,创建出既美观又功能强大的网站。
HTML & XHTML: The Definitive Guide
p
age 10
1.3.1 HTML Standards and Extensions
The basic syntax and semantics of HTML are defined in the HTML standard, currently Version 4.01. HTML has
matured in barely eight years, having gone through at least four iterations in as many years. At one time, a new
version would appear before you had a chance to finish reading this book. Today, the pace of change has slowed.
Now the wait is for browser manufacturers to implement the standards.
Browser developers rely upon the HTML standard to program the software that formats and displays common
HTML documents. Authors use the standard to make sure they are writing effective, correct HTML documents.
However, the standard is not always explicit; manufacturers have some leeway in how their browser might
display an element. And to complicate matters, commercial forces have pushed developers to add into their
browsers nonstandard extensions meant to improve the language.
In this book, we explore in detail the syntax, semantics, and idioms of HTML Version 4.01, along with the many
important extensions that are supported in the latest versions of the most popular browsers, so that any aspiring
HTML author can create fabulous documents with a minimum of effort.
1.4 XHTML: What It Is
You've certainly heard of HTML, but did you know that it is one of many other markup languages? Indeed, HTML
is the black sheep in the family of document markup languages. HTML is based on SGML, the Standard
Generalized Markup Language. The powers-that-be created SGML with the intent that it be the one and only
markup metalanguage from which all other document markup elements would be created. Everything from
hieroglyphics to HTML can be defined using SGML, negating any need for any other markup language.
The problem with SGML is that it is so broad and all-encompassing that mere mortals cannot use it. Using SGML
effectively requires very expensive and complex tools that are completely beyond the scope of regular people who
just want to bang out an HTML document in their spare time. As a result, HTML and other language standards
adhere to some, but not all SGML standards,
[2]
eliminating many of the more esoteric features so that HTML is
readily useable and used.
[2]
The HTML DTD in Appendix D uses a subset of SGML to define the HTML 4.01 standard.
Recognizing that SGML is unwieldy and not well-suited to describing the very popular HTML in a useful way, and
that there was a growing need to define other HTML-like markup languages to handle different network
documents, the W3C defined the Extensible Markup Language (XML). Like SGML, XML is a separate formal
markup metalanguage that uses select features of SGML to define markup languages. It eliminates many features
of SGML that aren't applicable to languages like HTML and simplifies other SGML elements in order to make
them easier to use and understand.
HTML Version 4.01 is not XML-compliant. Hence, the W3C offers XHTML, a reformulation of HTML to be
compliant under XML. XHTML attempts to support every last nit and feature of HTML 4.01 using the more rigid
rules of XML. It generally succeeds but has enough differences to make life difficult for the standards-conscious
HTML author.
Confused? Don't be. Learning HTML is still the way to go for most authors and Web developers. The native
language endures. Besides, by learning HTML, you learn the working bits of XHTML, effectively the same things.
There are some differences, which we explore in Chapter 16, XHTML. But the differences should not affect your
work in the foreseeable future.
1.5 HTML and XHTML: What They Aren't
With all their multimedia-enabling, new page layout features, and the hot technologies that give life to
HTML/XHTML documents over the Internet, it is also important to understand the languages' limitations. They
are not word-processing tools, desktop publishing solutions, or even programming languages. That's because
their fundamental purpose is to define the structure and appearance of documents and document families so that
they may be delivered quickly and easily to a user over a network for rendering on a variety of display devices.
Jack of all trades, but master of none, so to speak.
1.5.1 Content Versus Appearance
Before you can fully appreciate the power of the language and begin creating effective documents, you must yield
to one fundamental rule. These markup languages are designed to structure documents and make their content
more accessible, not to format documents for display purposes.
HTML & XHTML: The Definitive Guide
p
age 11
HTML and its progeny XHTML do provide many different ways to let you define the appearance of your
documents: font specifications, line breaks, and multicolumn text are all features of the language. And, of course,
appearance is important, since it can have either detrimental or beneficial effects on how users access and use the
information in your documents.
But with HTML and XHTML, content is paramount; appearance is secondary, particularly since it is less
predictable, given the variety of browser graphics and text-formatting capabilities. Besides, these markup
languages contain many more ways for structuring your document content without regard to the final
appearance: section headers, structured lists, paragraphs, rules, titles, and embedded images are all defined by
the standard languages without regard for how these elements might be rendered by a browser. Consider, for
example, a browser for the blind, wherein graphics on the page come with audio descriptions and alternative
rules for navigation. The HTML 4 standard defines such a thing: content over visual presentation.
If you treat HTML or XHTML as a document-generation tool, you will be sorely disappointed in your ability to
format your document in a specific way. There is simply not enough capability built into the languages to allow
you to create the kind of documents you might whip up with tools like FrameMaker or Microsoft Word. Attempts
to subvert the supplied structuring elements to achieve specific formatting tricks seldom work across all
browsers. In short, don't waste your time trying to force HTML and XHTML to do things they were never
designed to do.
Instead, use HTML and XHTML in the manner for which they were designed: indicating the structure of a
document so that the browser can then render its content appropriately. HTML and XHTML are rife with tags
that let you indicate the semantics of your document content, something that is missing from tools like Frame or
Word. Create your documents using these tags and you'll be happier, your documents will look better, and your
readers will benefit immensely.
1.6 Nonstandard Extensions
It doesn't take an advanced degree in the obvious to know that many people vie for distinction to draw the
attentions of others. So, too, with browsers. Extra whizbang features can give the edge in the otherwise
standardized market. That can be a nightmare for authors. A lot of people want you to use the latest and greatest
gimmick or even useful HTML extension. But it's not part of the standard, and not all browsers support it. In fact,
on occasion, the popular browsers support different ways of doing the same thing.
1.6.1 Extensions: Pro and Con
Every software vendor adheres to the technological standards; it's embarrassing to be incompatible and your
competitors will take every opportunity to remind buyers of your product's failure to comply, no matter how
arcane or useless that standard might be. At the same time, vendors seek to make their products different and
better than the competition's offerings. Netscape's and Internet Explorer's extensions to standard HTML are
perfect examples of these market pressures.
Many document authors feel safe using these extended browsers' nonstandard extensions because of their
combined and commanding share of users. For better or worse, extensions to HTML made by the folks at
Netscape or Microsoft instantly become part of the street version of the language, much like English slang
creeping into the vocabulary of most Frenchmen, despite all the best efforts of the Académie Française.
Fortunately, with HTML Version 4.0, the W3C standards caught up with the browser manufacturers. In fact, the
tables turned somewhat. The many extensions to HTML that originally appeared as extensions in Netscape
Navigator and Internet Explorer are now part of the HTML 4 and XHTML 1.0 standards, and there are other
parts of the new standard that are not yet features of the popular browsers.
1.6.2 Avoiding Extensions
In general, we urge you to resist using an extension unless you have a compelling and overriding reason to do so.
By using them, particularly in key portions of your documents, you run the risk of losing a substantial portion of
your potential readership. Sure, the Internet Explorer community is large enough to make this point moot now,
but even so, you are excluding several million people who use Netscape from your pages.
Of course, there are varying degrees of dependency on extensions. If you use some of the horizontal rule
extensions, for example, most other browsers will ignore the extended attributes and render a conventional
horizontal rule. On the other hand, reliance upon a number of font size changes and text alignment extensions to
control your document appearance will make your document look terrible on many alternative browsers. It might
not even display at all on browsers that don't support the extensions.
HTML & XHTML: The Definitive Guide
p
age 12
We admit that it is disingenuous of us to decry the use of extensions while presenting complete descriptions of
their use. In keeping with the general philosophy of the Internet, we'll err on the side of handing out rope and
guns to all interested parties while hoping you have enough smarts to keep from hanging yourself or shooting
yourself in the foot.
Our advice still holds, though: only use an extension where it is necessary or very advantageous, and do so with
the understanding that you are disenfranchising a portion of your audience. To that end, you might even consider
providing separate, standards-based versions of your documents to accommodate users of other browsers.
1.6.3 Beyond Extensions: Exploiting Bugs
It is one thing to take advantage of an extension, and it is quite another to exploit known bugs in a particular
version of a browser in order to achieve some unusual document effect.
A good example is the multiple-body bug in Version 1.1 of Netscape Navigator. The HTML standard insists that a
compliant document have exactly one
<body> tag, containing the body of the document. The now-obsolete
browser allowed any number of
<body> tags, processing and rendering each <body> in turn. By placing several
<body> tags in an HTML document, an author could achieve crude animation effects when the document was first
loaded into the browser. The most popular trick used several <body> tags, each with a slightly different
background color. This trick results in a document fade-in effect.
The party ended when Version 1.2 of Netscape fixed the bug. Suddenly, thousands of documents lost their fancy
fade-in effect. Although faced with some rather fierce complaints, to their credit, the people at Netscape stood by
their decision to adhere to the standard, placing compliance higher on their list of priorities than nifty rendering
hacks.
In that light, we can unequivocally offer this advice: never exploit a bug in a browser to achieve a particular effect
in your documents.
1.7 Tools for the Web Designer
While you can use the barest of barebones text editors to create HTML and XHTML documents, most authors
have a bit more elaborate toolbox of software utilities than a simple word processor. You also need a browser, so
you can test and refine your work. Beyond the essentials are some specialized software tools for HTML document
preparation and editing, and others for developing and preparing accessory multimedia files.
1.7.1 Essentials
At the very least, you'll need an editor, a browser to check your work, and ideally, a connection to the Internet.
1.7.1.1 Word processor or WYSIWYG editor?
Some authors use the word-processing capabilities of their specialized HTML/XHTML editing software. Others
use the WYSIWYG (what-you-see-is-what-you-get) composition tools that come with their browser or the latest
versions of the popular word processors. Others, such as ourselves, prefer to compose their work on a general
word processor and later insert the markup tags and their attributes. Still others include markup as they
compose.
We think the stepwise approach - compose, then mark up - is the better way. We find that once we've defined and
written the document's content, it's much easier to make a second pass to judiciously and effectively add the
HTML/XHTML tags to format the text. Otherwise, the markup can obscure the content. Note, too, that unless
specially trained (if they can be), spellcheckers and thesauruses typically choke on markup tags and their various
parameters. You can spend what seems to be a lifetime clicking the Ignore button on all those otherwise valid
markup tags when syntax- or spell-checking a document.
When and how you embed markup tags into your document dictates the tools you need. We recommend that you
use a good word processor, such as WordPerfect or Word, which comes with more and better writing tools than
simple text editors or the browser-based markup-language editors. You'll find, for instance, that an outliner,
spellchecker, and thesaurus will best help you craft the document's flow and content well, disregarding for the
moment its look. The latest word processors encode your documents with HTML, too, but don't expect miracles.
Except for boilerplate documents, you will probably need to nurse those automated HTML documents to full
health. And it'll be a while before you'll see XHTML-specific markup tools in the popular word processors.
Another word of caution about automated composition tools: they typically change or insert content, such as
replacing relative hyperlinks with full ones, and arrange your document in ways that will annoy you. Annoying, in
particular, since they rarely give you the opportunity to do things your own way.
HTML & XHTML: The Definitive Guide
p
age 13
So become fluent in native HTML/XHTML. Be prepared to reverse some of the things a composition tool will do
to your documents. And make sure you can wrest your document away from the tool so you can make it do your
bidding.
1.7.1.2 Browser software
Obviously, you should view your newly composed documents and test their functionality before you release them
for use by others. For serious authors, particularly those looking to push their documents beyond the
HTML/XHTML standards, we recommend that you have several browser products, perhaps with versions
running on different computers, just to be sure one's delightful display isn't another's nightmare.
The currently popular - and therefore most important - browsers are Netscape Navigator (the browser portion of
Netscape Communicator) and Microsoft's Internet Explorer. Download the latest versions from their web sites.
1.7.1.3 Internet connection
We think you should have bona fide access to the Internet if you are really serious about learning and honing your
document markup skills. Okay, it's not absolutely essential, since you can compose and view documents locally.
And for some, a connection is perhaps not even possible or practical, but make the effort: sometimes there's no
better way to learn than by example. Examples both good and bad abound on the Internet, and there are literally
millions of Web pages whose source HTML you can download and examine, albeit fewer XHTML ones.
Moreover, an Internet connection is essential for development and testing if you include hypertext links to
Internet services in your web documents. Most of all, an Internet connection gives you access to a wealth of tips
and ongoing updates to the language through special-interest newsgroups, as well as much of the essential and
accessory software you can use to prepare document collections.
1.7.2 An Extended Toolkit
If you're serious about creating documents, you'll soon find there are all sorts of nifty tools that make life easier.
The list of freeware, shareware, and commercial products grows daily, so it's not very useful to provide a list here.
This is, in fact, another good reason why you should get an Internet connection; various groups keep updated lists
of HTML and XHTML resources on the Web. If you are really dedicated to writing in HTML and XHTML, you
will visit those sites, and you will visit them regularly to keep abreast of the language, tools, and trends.
We think the following four web sites are the most useful for authors. Each contains dozens, sometimes
hundreds, of hyperlinks to detailed descriptions of products and other important information. Go at it:
http://www.stars.com
http://msdn.microsoft.com
http://search.netscape.com
http://www.w3.org/MarkUp
HTML & XHTML: The Definitive Guide
p
age 14
Chapter 2. Quick Start
We didn't spend hours studiously poring over some reference book before we wrote our first HTML document.
You probably shouldn't, either. HTML is simple to read and understand, and it's simple to write, too. And once
you've written an HTML document, you've nearly completed your first XHTML one, too. So let's get started
without first learning a lot of arcane rules.
To help you get that quick, satisfying start, we've included this chapter as a brief summary of the many elements
of HTML and its progeny, XHTML. Of course, we've left out a lot of details and some tricks that you should know.
Read the upcoming chapters to get the essentials for becoming fluent in HTML and XHTML.
Even if you are familiar with the languages, we recommend you work your way through this chapter before
tackling the rest of the book. It not only gives you a working grasp of basic HTML and its jargon, but you'll also be
more productive later, flush with the confidence that comes from creating attractive documents in such a short
time.
2.1 Writing Tools
Use any text editor to create an HTML or XHTML document, as long as it can save your work on disk in ASCII
text file format. That's because even though documents include elaborate text layout and pictures, they're all just
plain old ASCII documents themselves. A fancier WYSIWYG editor or a translator for your favorite word
processor are fine, too - although they may not support the many nonstandard features we discuss later in this
book. You'll probably end up touching up the source text they produce, as well.
While not needed to compose documents, you should have at least one version of a popular browser installed on
your computer to view your work, preferably Netscape Navigator or Microsoft's Internet Explorer. That's because
the source document you compose on your text editor doesn't look anything like what gets displayed by a
browser, even though it's the same document. Make sure what your readers actually see is what you intended by
viewing the document yourself with a browser. Besides, the popular ones are free over the Internet.
Also note that you don't need a connection to the Internet or the World Wide Web to write and view your HTML
or XHTML documents. You may compose and view your documents stored on a hard drive or floppy disk that's
attached to your computer. You can even navigate among your local documents with the languages' hyperlinking
capabilities without ever being connected to the Internet, or any other network, for that matter. In fact, we
recommend that you work locally to develop and thoroughly test your documents before you share them with
others.
We strongly recommend, however, that you do get a connection to the Internet if you are serious about
composing your own documents. You may download and view others' interesting web pages and see how they
accomplished some interesting feature - good or bad. Learning by example is fun, too. (Reusing others' work, on
the other hand, is often questionable, if not downright illegal.) An Internet connection is essential if you include
in your work hyperlinks to other documents on the Internet.
2.2 A First HTML Document
It seems every programming language book ever written starts off with a simple example on how to display the
message, "Hello, World!" Well, you won't see a "Hello, World!" example in this book. After all, this is a style guide
for the new millennium. Instead, ours sends greetings to the World Wide Web:
<html>
<head>
<title>My first HTML document</title>
</head>
<body>
<h2>My first HTML document</h2>
Hello, <i>World Wide Web!</i>
<!-- No "Hello, World" for us -->
<p>
Greetings from<br>
<a href="http://www.ora.com">O'Reilly & Associates</a>
<p>
Composed with care by:
<cite>(insert your name here)</cite>
<br>©2000 and beyond
</body>
</html>
Go ahead: type in the example HTML source on a fresh word-processing page and save it on your local disk as
myfirst.html. Make sure you select to save it in ASCII format; word processor-specific file formats like Microsoft
Word's .doc files save hidden characters that can confuse the browser software and disrupt your HTML
document's display.
剩余448页未读,继续阅读
2024-11-03 上传
2024-11-03 上传
2024-11-03 上传
2023-05-31 上传
2023-07-15 上传
2023-05-02 上传
puyran
- 粉丝: 2
- 资源: 36
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功