nobr and wbr


<nobr> and <wbr>

The <nobr>...</nobr> element is the opposite of the <br> tag. The text inside the <nobr> tags always remains on one line, even if it would have wrapped to two more lines without the <nobr>. The <nobr> tag is used for words or phrases that must be kept together on one line, but be careful. Long unbreakable lines can look really strange on your page, and if they're longer than the page width, they might extend beyond the right edge of the screen.

The <wbr> tag (word break) indicates an appropriate breaking point within a line (typically inside a <nobr>...</nobr> sequence). Unlike <br>, which forces a break, <wbr> is used only where it's appropriate to do so. If the line will fit on the screen just fine, the <wbr> is ignored. In XHTML 1.0, add closure to the tag by using the syntax of <wbr />.

Neither <nobr> nor <wbr> is part of HTML 3.2 or HTML 4.01. They're extensions introduced by Netscape, and are currently supported by both Netscape and Internet Explorer.

Task: Exercise 6.1. Creating a Real HTML Page

Here's your chance to apply what you've learned and create a real web page. No more disjointed or overly silly examples. The web page you'll create in this section is a real one, suitable for use in the real world (or the real world of the Web, at least).

Your task for this example is to design and create a home page for a bookstore called The Bookworm, which specializes in old and rare books.

Planning the Page

In lesson 2, "Preparing to Publish on the Web," I mentioned that planning your web page before writing it usually makes building and maintaining the elements easier. First, consider the content you want to include on this page. The following are some ideas for topics for this page:

  • The address and phone number of the bookstore

  • A short description of the bookstore and why it's unique

  • Recent titles and authors

  • Upcoming events

Now come up with some ideas for the content you're going to link to from this page. Each title in a list of recently acquired books seems like a logical candidate. You also can create links to more information about each book, its author and publisher, its pricing, and maybe even its availability.

The Upcoming Events section might suggest a potential series of links, depending on how much you want to say about each event. If you have only a sentence or two about each one, describing them on this page might make more sense than linking them to another page. Why make your readers wait for each new page to load for just a couple of lines of text?

Other interesting links might arise in the text itself, but for now, starting with the basic link plan is enough.

Beginning with a Framework

Next, create the framework that all HTML files must include: the document structuring commands, a title, and some initial headings. Note that the title is descriptive but short; you can save the longer title for the <h1> element in the body of the text. The four <h2> subheadings help you define the four main sections you'll have on your web page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/transitional.dtd"> <html> <head> <title>The Bookworm Bookshop</title> </head> <body> <h1>The Bookworm: A Better Book Store</h1> <h2>Contents</h2> <h2>About the Bookworm Bookshop</h2> <h2>Recent Titles (as of 11-Jan-2003)</h2> <h2>Upcoming Events</h2> </body> </html>


Each of the headings you've placed on your page marks the beginning of a particular section. You'll create an anchor at each of the topic headings so that you can jump from section to section with ease. The anchor names are simple: top for the main heading; contents for the table of contents; and about, recent, and upcoming for the three subsections on the page. The revised code looks like the following with the anchors in place:

Input

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/transitional.dtd"> <html> <head> <title>The Bookworm Bookshop</title> </head> <body> <a name="top"><h1>The Bookworm: A Better Book Store</h1></a> <a name="contents"><h2>Contents</h2></a> <a name="about"><h2>About the Bookworm Bookshop</h2></a> <a name="recent"><h2>Recent Titles (as of 11-Jan-2003)</h2></a> <a name="upcoming"><h2>Upcoming Events</h2></a> </body> </html>


Adding Content

Now begin adding the content. You're undertaking a literary endeavor, so starting the page with a nice quote about old books would be a nice touch. Because you're adding a quote, you can use the <blockquote> tag to make it stand out as such. Also, the name of the poem is a citation, so use <cite> there, too.

Insert the following code on the line after the level 1 heading:

Input

<blockquote> "Old books are best---how tale and rhyme<br /> Float with us down the stream of time!"<br /> - Clarence Urmy, <cite>Old Songs are Best</cite> </blockquote>


Immediately following the quote, add the address for the bookstore. This is a simple paragraph with the lines separated by line breaks, like the following:

Input

<p>The Bookworm Bookshop<br /> 1345 Applewood Dr<br /> Springfield, CA 94325<br /> (415) 555-0034 </p>


Adding the Table of Contents

The page you're creating will require a lot of scrolling to get from the top to the bottom. One nice enhancement is to add a small table of contents at the beginning of the page, listing the sections in a bulleted list. If a reader clicks one of the links in the table of contents, he'll automatically jump to the section that's of most interest to him. Because you've created the anchors already, it's easy to see where the links will take you.

You already have the heading for the table of contents. You just need to add the bulleted list and a horizontal rule, and then create the links to the other sections on the page. The code looks like the following:

Input

<a name="contents"><h2>Contents</h2></a> <ul>  <li><a href="#about">About the Bookworm Bookshop</a></li>  <li><a href ="#recent">Recent Titles</a></li>  <li><a href ="#upcoming">Upcoming Events</a></li> </ul> <hr />


Figure 6.16 shows an example of the introductory portion of the Bookworm Bookshop page as it appears in a browser.

Output

Figure 6.16. The top section of the Bookworm Bookshop page.


Creating the Description of the Bookstore

Now you come to the first descriptive subheading on the page, which you've added already. This section gives a description of the bookstore. After the heading (shown in the first line of the following example), I've arranged the description to include a list of features to make them stand out from the text better:

Input

<a name="about"><h2>About the Bookworm Bookshop</h2></a> <p>Since 1933, The Bookworm Bookshop has offered rare and hard-to-find titles for the discerning reader. The Bookworm offers:</p> <ul> <li>Friendly, knowledgeable, and courteous help</li> <li>Free coffee and juice for our customers</li> <li>A well-lit reading room so you can "try before you buy"</li> <li>Four friendly cats: Esmerelda, Catherine, Dulcinea and Beatrice</li> </ul>


Add a note about the hours the store is open and emphasize the actual numbers:

Input

<p>Our hours are <strong>10am to 9pm</strong> weekdays, <strong>noon to 7</strong> on weekends.</p>


Then, end the section with links to the Table of Contents and the top of the page, followed by a horizontal rule to end the section:

Input

<p><a href="#contents">Back to Contents</a> | <a href="#top">Back to Top</a></p> <hr />


Figure 6.17 shows you what the About the Bookworm Bookshop section looks like in a browser. Fonts and Font Sizes

Output

Figure 6.17. The About the Bookworm Bookshop section.


Creating the Recent Titles Section

The Recent Titles section itself is a classic link menu, as I described earlier in this section. Here you can put the list of titles in an unordered list, with the titles themselves as citations, by using the <cite> tag. End the section with another horizontal rule.

After the Recent Titles heading (shown in the first line in the following example), enter the following code:

<a name="recent"><h2>Recent Titles (as of 11-Jan-2006)</h2></a> <ul> <li>Sandra Bellweather, <cite>Belladonna</cite></li> <li>Jonathan Tin, <cite>20-Minute Meals for One</cite></li> <li>Maxwell Burgess, <cite>Legion of Thunder</cite></li> <li>Alison Caine, <cite>Banquo's Ghost</cite></li> </ul> <hr />


Now add the anchor tags to create the links. How far should the link extend? Should it include the whole line (author and title) or just the title of the book? This decision is a matter of preference, but I like to link only as much as necessary to make sure that the link stands out from the text. I prefer this approach to overwhelming the text. Here, I linked only the titles of the books. At the same time, I also added links to the Table of Contents and the top of the page:

Input

<a name="recent"><h2>Recent Titles (as of 11-Jan-2006)</h2></a> <ul> <li>Sandra Bellweather, <a href="belladonna.html"> <cite>Belladonna</cite></a></li> <li>Johnathan Tin, <a href="20minmeals.html"> <cite>20-Minute Meals for One</cite></a></li> <li>Maxwell Burgess, <a href="legion.html"> <cite>Legion of Thunder</cite></a></li> <li>Alison Caine, <a href="banquo.html"> <cite>Banquo's Ghost</cite></a></li> </ul> <p><a href="#contents">Back to Contents</a> | <a href="#top">Back to Top</a></p> <hr />


Note that I put the <cite> tag inside the link tag <a>. I could have just as easily put it outside the anchor tag; character style tags can go just about anywhere. But as I mentioned once before, be careful not to overlap tags. Your browser might not be able to understand what's going on, and it's invalid. In other words, don't do the following:

<a href="banquo.html"><cite>Banquo's Ghost</a></cite>


Take a look at how the Recent Titles section appears. An example is shown in Figure 6.18.

Output

Figure 6.18. The Recent Titles section.


Completing the Upcoming Events Section

Next, move on to the Upcoming Events section. In the planning stages, you weren't sure whether this would be another link menu or whether the content would work better solely on this page. Again, this decision is a matter of preference. Here, because the amount of extra information is minimal, creating links for just a couple of sentences doesn't make much sense. So, for this section, create an unordered list using the <ul> tag. I've boldfaced a few phrases near the beginning of each paragraph. These phrases emphasize a summary of the event itself so that the text can be scanned quickly and ignored if the readers aren't interested.

As in the previous sections, you end the section with links to the top and to the contents, followed by a horizontal rule.

 <a name=upcoming"><h2>Upcoming Events</h2></a> <ul> <li><b>The Wednesday Evening Book Review</b> meets, appropriately, on Wednesday evenings at 7 pm for coffee and a round-table discussion. Call the Bookworm for information on joining the group.</li> <li><b>The Children's Hour</b> happens every Saturday at 1 pm and includes reading, games, and other activities. Cookies and milk are served.</li> <li><b>Carole Fenney</b> will be at the Bookworm on Sunday, January 19, to read from her book of poems <cite>Spiders in the Web.</cite></li> <li><b>The Bookworm will be closed</b> March 1st to remove a family of bats that has nested in the tower. We like the company, but not the mess they leave behind!</li> </ul> <p><a href="#contents">Back to Contents</a> | <a href="#top">Back to Top</a></p>


Signing the Page

To finish, sign what you have so that your readers know who did the work. Here, I've separated the signature from the text with a rule line. I've also included the most recent revision date, my name as the Webmaster, and a basic copyright (with a copyright symbol indicated by the numeric escape &#169;):

Input

<hr /> <address> Last Updated: 11-Jan-2006<br /> Webmaster: Laura Lemay <a href="mailto:lemay@bookworm.com">lemay@bookworm.com</a><br /> &#169; copyright 2006 the Bookworm<br /> </address>


Figure 6.19 shows the signature at the bottom portion of the page as well as the Upcoming Events section.

Output

Figure 6.19. The Upcoming Events section and the page signature.


Reviewing What You've Got

Here's the HTML code for the page so far:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/transitional.dtd"> <html> <head> <title>The Bookworm Bookshop</title> </head> <body> <a name="top"><h1>The Bookworm: A Better Book Store</h1></a> <blockquote> "Old books are best---how tale and rhyme<br /> Float with us down the stream of time!"<br /> - Clarence Urmy, <cite>Old Songs are Best</cite> </blockquote> <p>The Bookworm Bookshop<br /> 1345 Applewood Dr<br /> Springfield, CA 94325<br /> (415) 555-0034 </p> <a name="contents"><h2>Contents</h2></a> <ul>  <li><a href="#about">About the Bookworm Bookshop</a></li>  <li><a href="#recent">Recent Titles</a></li>  <li><a href="#upcoming">Upcoming Events</a></li> </ul> <hr /> <a name="about"><h2>About the Bookworm Bookshop</h2></a> <p>Since 1933, the Bookworm Bookshop has offered rare and hard-to-find titles for the discerning reader. The Bookworm offers:</p> <ul>  <li>Friendly, knowledgeable, and courteous help</li>  <li>Free coffee and juice for our customers</li>  <li>A well-lit reading room so you can "try before you buy"</li>  <li>Four friendly cats: Esmerelda, Catherine, Dulcinea and Beatrice</li> </ul> <p>Our hours are <strong>10am to 9pm</strong> weekdays, <strong>noon to 7</strong> on weekends.</p> <p><a href="#contents">Back to Contents</a> | <a href="#top">Back to Top</a></p> <hr /> <a name="recent"><h2>Recent Titles (as of 11-Jan-2003)</h2></a> <ul>  <li>Sandra Bellweather, <a href="belladonna.html">   <cite>Belladonna</cite></a></li>  <li>Johnathan Tin, <a href="20minmeals.html">   <cite>20-Minute Meals for One</cite></a></li>  <li>Maxwell Burgess, <a href="legion.html">   <cite>Legion of Thunder</cite></a></li>  <li>Alison Caine, <a href="banquo.html">   <cite>Banquo's Ghost</cite></a></li> </ul> <p><a href="#contents">Back to Contents</a> | <a href="#top">Back to Top</a></p> <hr /> <a name="upcoming"><h2>Upcoming Events</h2></a> <ul>  <li><b>The Wednesday Evening Book Review</b> meets, appropriately, on    Wednesday evenings at 7 pm for coffee and a round-table discussion.    Call the Bookworm for information on joining the group.</li>  <li><b>The Children's Hour</b> happens every Saturday at 1 pm and includes    reading, games, and other activities. Cookies and milk are served.</li>  <li><b>Carole Fenney</b> will be at the Bookworm on Sunday, January 19,    to read from her book of poems <cite>Spiders in the Web.</cite></li>  <li><b>The Bookworm will be closed</b> March 1 to remove a family    of bats that has nested in the tower. We like the company, but not    the mess they leave behind!</li> </ul> <p><a href="#contents">Back to Contents</a> | <a href="#top">Back to Top</a></p> <hr /> <address> Last Updated: 11-Jan-2006<br /> WebMaster: Laura Lemay lemay@bookworm.com<br /> &#169; copyright 2006 the Bookworm<br /> </address> </body> </html>


Now you have some headings, some text, some topics, and some links, which form the basis for an excellent web page. With most of the content in place, now you need to consider what other links you might want to create or what other features you might want to add to this page.

For example, the introductory section has a note about the four cats owned by the bookstore. Although you didn't plan for them in the original organization, you could easily create web pages describing each cat (and showing pictures) and then link them back to this page, one link (and one page) per cat.

Is describing the cats important? As the designer of the page, that's up to you to decide. You could link all kinds of things from this page if you have interesting reasons to link them (and something to link to). Link the bookstore's address to an online mapping service so that people can get driving directions. Link the quote to an online encyclopedia of quotes. Link the note about free coffee to the Coffee Home Page.

I'll talk more about good things to link (and how not to get carried away when you link) in Lesson 16, "Writing Good Web Pages: Do's and Don'ts." My reason for bringing up this point here is that after you have some content in place on your web pages, there might be opportunities for extending the pages and linking to other places that you didn't think of when you created your original plan. So, when you're just about finished with a page, stop and review what you have, both in the plan and in your web page.

For the purposes of this example, stop here and stick with the links you have. You're close enough to being done, and I don't want to make this lesson any longer than it already is!

Testing the Result

Now that all the code is in place, you can preview the results in a browser. Figures 6.16 through 6.19 show how it looks in a browser. Actually, these figures show what the page looks like after you fix the spelling errors, the forgotten closing tags, and all the other strange bugs that always seem to creep into an HTML file the first time you create it. These problems always seem to happen no matter how good you are at creating web pages. If you use an HTML editor or some other help tool, your job will be easier, but you'll always seem to find mistakes. That's what previewing is forso you can catch the problems before you actually make the document available to other people.

Getting Fancy

Everything I've included on the page up to this point has been plain-vanilla HTML 2.0, so it's readable and will look pretty much the same in all browsers. After you get the page to this point, however, you can add additional formatting tags and attributes that won't change the page for many readers, but might make it look a little fancier in browsers that do support these attributes.

So, what attributes do you want to use? I chose two:

  • Centering the title of the page, the quote, and the bookstore's address

  • Making a slight font size change to the address itself

To center the topmost part of the page, you can use the <div> tag around the heading, the quote, and the bookshop's address, as in the following:

Input

<div style="text-align: center"> <a name="top"><h1 style="font-variant: small-caps">The Bookworm: A Better Book Store</h1></a> <blockquote> "Old books are best---how tale and rhyme<br /> Float with us down the stream of time!"<br /> - Clarence Urmy, <cite>Old Songs are Best</cite> </blockquote> <p>The Bookworm Bookshop<br /> 1345 Applewood Dr<br /> Springfield, CA 94325<br /> (415) 555-0034 </p> </div>


I've also used the style attribute to change the text in the <h1> tag to small caps. To change the font size of the address, add a style attribute to the paragraph containing the address:

Input

<p style="font-size: 150%">The Bookworm Bookshop<br /> 1345 Applewood Dr<br /> Springfield, CA 94325<br /> (415) 555-0034 </p>


Figure 6.20 shows the final result, with attributes. Note that neither of these changes affects the readability of the page in browsers that don't support <div> or <font>; the page still works just fine without them. It just looks different.

Output

Figure 6.20. The final Bookworm home page, with additional attributes.


When should you use text-formatting attributes? The general rule that I like to follow is to use these tags only when they won't interfere with other browsers, generally older ones. Similarly, although HTML 4.01 officially encourages web page authors to use style sheets rather than text formatting tags such as font and attributes such as align, support for style sheets still isn't yet universal. So, for the time being, if you want to spiff up the appearance of your text, you must continue to use these tags and attributes.

You'll learn more about formatting tags and attributes, as well as how to design well with them, in Lesson 15, "Creating Applications with Dynamic HTML and AJAX."




Sams Teach Yourself Web Publishing with HTML and CSS in One Hour a Day
Sams Teach Yourself Web Publishing with HTML and CSS in One Hour a Day (5th Edition)
ISBN: 0672328860
EAN: 2147483647
Year: 2007
Pages: 305

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net