⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch20.htm

📁 《Perl 5 Unreleased》
💻 HTM
📖 第 1 页 / 共 5 页
字号:
24                        

Houston, Texas 77024. &lt;BR&gt;<BR>

25&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;713

827 1827&lt;BR&gt;<BR>

26 &lt;/CENTER&gt;<BR>

27 &lt;hr&gt;<BR>

28 &lt;/BODY&gt;<BR>

29 &lt;/HTML&gt;</FONT></TT>

</BLOCKQUOTE>

<HR>

<P>

Line 6 defines a centered line of text with the <TT><FONT FACE="Courier">&lt;Center&gt;</FONT></TT>

and <TT><FONT FACE="Courier">&lt;/Center&gt;</FONT></TT> tags.

Note how the <TT><FONT FACE="Courier">&lt;H1&gt;</FONT></TT> and

<TT><FONT FACE="Courier">&lt;/H1&gt;</FONT></TT> tags are enclosed

along with the text being centered. Line 7 draws a horizontal

line. (Remember that HR stands for Horizontal Rule.) The <TT><FONT FACE="Courier">&lt;b&gt;</FONT></TT>

and <TT><FONT FACE="Courier">&lt;/b&gt;</FONT></TT> tags are used

in lines 10 and 11 to embolden some text. Since HTML is case insensitive,

we could have used the tags <TT><FONT FACE="Courier">&lt;B&gt;</FONT></TT>

and <TT><FONT FACE="Courier">&lt;/B&gt;</FONT></TT> with no loss

of functionality. Use of the <TT><FONT FACE="Courier">&lt;EM&gt;</FONT></TT>

and <TT><FONT FACE="Courier">&lt;STRONG&gt;</FONT></TT> tags is

shown in lines 14 and 15, respectively. 

<P>

Note that the effect of <TT><FONT FACE="Courier">&lt;B&gt;</FONT></TT>

remains in effect until the <TT><FONT FACE="Courier">&lt;/B&gt;</FONT></TT>

is seen. So the text being set to a style can be typed in across

several lines. In lines 19 through 26, center several lines. 

<P>

In HTML documents you should use <TT><FONT FACE="Courier">&lt;STRONG&gt;</FONT></TT>

and <TT><FONT FACE="Courier">&lt;EM&gt;</FONT></TT> tags instead

of  <TT><FONT FACE="Courier">&lt;B&gt;</FONT></TT> and <TT><FONT FACE="Courier">&lt;I&gt;</FONT></TT>

tags, respectively. There are occasions where using even seemingly

innocent tags such as <TT><FONT FACE="Courier">&lt;B&gt;</FONT></TT>

for bolding text or <TT><FONT FACE="Courier">&lt;I&gt;</FONT></TT>

for italicizing text may not work. For example, if a browser is

using a font that does not have an italics character set, the

<TT><FONT FACE="Courier">&lt;I&gt;<I>text</I>&lt;/I&gt; </FONT></TT>will

be printed with its codes; that is, it will be  as <TT><FONT FACE="Courier">&lt;I&gt;<I>text</I>&lt;/I&gt;</FONT></TT>

and not as <TT><I><FONT FACE="Courier">text</FONT></I></TT>. To

take care of some of these issues, should they arise, HTML authors

prefer to use the <TT><FONT FACE="Courier">&lt;EM&gt;&lt;/EM&gt;</FONT></TT>

emphasis tags in place of the <TT><FONT FACE="Courier">&lt;I&gt;&lt;/I&gt;</FONT></TT>

tags and the <TT><FONT FACE="Courier">&lt;STRONG&gt;&lt;/STRONG&gt;</FONT></TT>

tags in place of the <TT><FONT FACE="Courier">&lt;B&gt;&lt;/B&gt;</FONT></TT>.

<P>

An HTML document defines only the display style with the use of

markup tags. How a Web browser chooses to display the information

is left to the implementation at the Web browser. So the client's

browser is responsible for rendering this text and may have a

completely different font than what you are using to create the

page. Therefore, what you see on your screen will be different

from what someone else using a different font may see. For best

results, try viewing your HTML page with different browsers. The

font on someone else's browser might be completely different.

For one thing, users can choose whatever font they desire for

their browser. Even if users don't explicitly choose a font, the

browser may default to a font that is different from the one you

use. For example, one user may use the Internet Explorer from

Microsoft with a 10-point font, and another user may use Netscape

Navigator with a 12-point font. Each user will  see different

lengths of paragraphs and text layout. 

<P>

Simple text formatting with the use of carriage returns in HTML

documents does not work. The client browser will implement word

wrapping when it sees text. You can force paragraph and line breaks

with the use of <TT><FONT FACE="Courier">&lt;P&gt;</FONT></TT>

or <TT><FONT FACE="Courier">&lt;BR&gt;</FONT></TT> tags. The <TT><FONT FACE="Courier">&lt;BR&gt;</FONT></TT>

tag creates a line break, and does not  start a new paragraph

like the <TT><FONT FACE="Courier">&lt;P&gt;</FONT></TT> tag. A

<TT><FONT FACE="Courier">&lt;P&gt;</FONT></TT> tag may be used

to lay out text differently using formats and text alignment on

different types of browsers. A <TT><FONT FACE="Courier">&lt;BR&gt;</FONT></TT>

tag simply starts a new line without changing the current paragraph

format. Not using these tags causes all white space (including

spaces, tabs, and blank lines) to be collapsed into one white

space. Listings 20.4 and 20.5 provide samples of two HTML files

that produce the same output.

<HR>

<BLOCKQUOTE>

<B>Listing 20.4. Headings in HTML files.<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">&nbsp;1 &lt;HTML&gt;&lt;HEAD&gt; <BR>

&nbsp;2 &lt;TITLE&gt;A simple HTML file&lt;/TITLE&gt;<BR>

&nbsp;3 &lt;/HEAD&gt;<BR>

&nbsp;4 &lt;BODY&gt;<BR>

&nbsp;5 &lt;H1&gt;This is Header Level 1&lt;/H1&gt;<BR>

&nbsp;6 &lt;H2&gt;This is Header Level 2&lt;/H2&gt;<BR>

&nbsp;7 &lt;H3&gt;This is Header Level 3&lt;/H3&gt;<BR>

&nbsp;8 &lt;H4&gt;This is Header Level 4&lt;/H4&gt;<BR>

&nbsp;9 &lt;H5&gt;This is Header Level 5&lt;/H5&gt;<BR>

10 &lt;H6&gt;This is Header Level 6&lt;/H6&gt;<BR>

11 This is line 1<BR>

12 This is line 2&lt;P&gt;<BR>

13 This is line 3&lt;P&gt;<BR>

14 This is a broken line with an &amp;ltBR&amp;gt&lt;BR&gt; sign.

<BR>

15 &lt;P&gt;<BR>

16 End of File Here.<BR>

17 &lt;/BODY&gt;<BR>

18 &lt;/HTML&gt;</FONT></TT>

</BLOCKQUOTE>

<HR>

<HR>

<BLOCKQUOTE>

<B>Listing 20.5. The second version of the HTML file shown in

Listing 20.4.<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">&nbsp;1 &lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;A

simple HTML file&lt;/TITLE&gt;<BR>

&nbsp;2 &lt;HEAD&gt;<BR>

&nbsp;3 &lt;BODY&gt;<BR>

&nbsp;4 &lt;H1&gt;This is Header Level 1&lt;/H1&gt; &lt;H2&gt;This

is Header Level 2&lt;/H2&gt;<BR>

&nbsp;5 &lt;H3&gt;This is Header Level 3&lt;/H3&gt; &lt;H4&gt;This

is Header Level 4&lt;/H4&gt;<BR>

&nbsp;6 &lt;H5&gt;This is Header Level 5&lt;/H5&gt; &lt;H6&gt;This

is Header Level 6&lt;/H6&gt;<BR>

&nbsp;7 This is line 1 This is line 2&lt;P&gt; This is line 3&lt;P&gt;

<BR>

&nbsp;8 This is a broken line with an &amp;ltoBR&amp;gt&lt;BR&gt;

sign. &lt;P&gt; End of File Here.<BR>

&nbsp;9 &lt;/BODY&gt;&lt;/HTML&gt;</FONT></TT>

</BLOCKQUOTE>

<HR>

<P>

Figure 20.3 shows the output from both listings. Note how heading-level

1 and heading-level 2 are shown in the same font style in this

figure. The example shown here uses Netscape as the browser. The

results on your browser might be different because each browser

displays HTML in the way it chooses. It's a bit like the contents

of a box shifting during transport but the weight of the contents

has not changed.

<P>

<A HREF="f20-3.gif" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/f20-3.gif" ><B>Figure 20.3: </B><I>Using different heading levels.</I></A>

<P>

For the sake of readability, it's best to place headings and paragraphs

on separate blank lines along with <TT><FONT FACE="Courier">&lt;P&gt;</FONT></TT>

tags.  You can also specify formatting options for paragraph alignment

in the <TT><FONT FACE="Courier">&lt;P&gt;</FONT></TT> tag, as

illustrated in Listing 20.5. The format specified for <TT><FONT FACE="Courier">&lt;P&gt;</FONT></TT>

will continue until the next <TT><FONT FACE="Courier">&lt;P&gt;</FONT></TT>

tag. To terminate a particular format you can use the <TT><FONT FACE="Courier">&lt;/P&gt;</FONT></TT>

tag.

<HR>

<BLOCKQUOTE>

<B>Listing 20.6. Aligning paragraphs.<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">&nbsp;1 &lt;html&gt;<BR>

&nbsp;2 &lt;body&gt;<BR>

&nbsp;3 &lt;TITLE&gt;Aligned Paragraphs&lt;/TITLE&gt;<BR>

&nbsp;4 &lt;H1&gt;This shows aligned paragraphs&lt;/H1&gt;<BR>

&nbsp;5 &lt;P ALIGN=CENTER&gt;

<BR>

&nbsp;6 This line is centered<BR>

&nbsp;7 &lt;P ALIGN=LEFT&gt;<BR>

&nbsp;8 This is aligned off the left margin<BR>

&nbsp;9 &lt;P ALIGN=RIGHT&gt;<BR>

10 This is line aligned off the right margin<BR>

11 &lt;P&gt;<BR>

12 End of File Here.<BR>

13 &lt;/body&gt;<BR>

14 &lt;/html&gt;</FONT></TT>

</BLOCKQUOTE>

<HR>

<P>

The output from this listing is shown in Figure 20.4.

<P>

<A HREF="f20-4.gif" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/f20-4.gif" ><B>Figure 20.4:</B> <I>Using aligned paragraphs.</I></A>

<H2><A NAME="PreformattedText"><FONT SIZE=5 COLOR=#FF0000>Preformatted

Text</FONT></A></H2>

<P>

Having the browser format text for you does keep you from a lot

of the hassle of tracking line breaks, paragraph formatting, and

so on. However, when displaying text that is already laid out

(such as source code), the default formatting can wreak havoc

on your source listings. For this reason, HTML documents have

the preformatted (<TT><FONT FACE="Courier">&lt;PRE&gt;</FONT></TT>)

tag. Using the <TT><FONT FACE="Courier">&lt;PRE&gt;</FONT></TT>

tag turns off the HTML formatting at the browser. Listing 20.8

contains an HTML file that illustrates using this tag. The output

is shown in Figure 20.5.

<P>

<A HREF="f20-5.gif" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/f20-5.gif" ><B>Figure 20.5:</B> <I>Preformatted text</I></A><I>.</I>

<HR>

<BLOCKQUOTE>

<B>Listing 20.7. Preformatted text.<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">&nbsp;1 &lt;html&gt;<BR>

&nbsp;2 &lt;body&gt;<BR>

&nbsp;3 &lt;TITLE&gt;Yet Another Example&lt;/TITLE&gt;<BR>

&nbsp;4 &lt;H1&gt;This shows Raw vs. Preformatted Text&lt;/H1&gt;

<BR>

&nbsp;5 &lt;H3&gt;Unformatted with the PRE tags &lt;/H3&gt;<BR>

&nbsp;6 &lt;PRE&gt;<BR>

&nbsp;7 main(int argc, char *argv[])<BR>

&nbsp;8 {<BR>

&nbsp;9 int command;<BR>

10 <BR>

11&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command = get_response();

<BR>

12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while (command != C_QUIT)

<BR>

13&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

{<BR>

14&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

process_command(command);<BR>

15&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

command = get_response();<BR>

16&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

}<BR>

17 <BR>

18 }<BR>

19 &lt;/PRE&gt;<BR>

20 &lt;HR&gt;<BR>

21 &lt;H3&gt; Without the PRE tags &lt;/H3&gt;<BR>

22 &lt;P&gt;<BR>

23 main(int argc, char *argv[])<BR>

24 {<BR>

25 int command;<BR>

26 <BR>

27&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command = get_response();

<BR>

28&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while (command != C_QUIT)

<BR>

29&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

{<BR>

30&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

process_command(command);<BR>

31&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

command = get_response();<BR>

32&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

}<BR>

33 <BR>

34 }<BR>

35 <BR>

36 &lt;/body&gt;<BR>

37 &lt;/html&gt;</FONT></TT>

</BLOCKQUOTE>

<HR>

<H2><FONT SIZE=5 COLOR=#FF0000><A NAME="SpecialCharactersinHTMLDocuments">Special Characters in HTML Documents</A></FONT>

</H2>

<P>

By now you have seen that the greater than symbol and the less

than symbol are used to encode documents. What if you wanted to

include them in text that was not in preformatted tags? There

are several special characters to encode these special symbols

in HTML. In order to include them in a file, you have to enter

their codes in the HTML file. Four of the most common special

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -