This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
Beginning Web Programming with HTML, XHTML, and CSS
i
Beginning Web Programming with HTML, XHTML, and CSS Jon Duckett
Wiley Publishing, Inc.
Beginning Web Programming with HTML, XHTML, and CSS C 2004 by Wiley Publishing, Inc. All rights reserved. Copyright
Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8700. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, E-mail: [email protected]. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Trademarks: Wiley, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. eISBN: 0-7645-7813-8 Printed in the United States of America 10
9
8
7
6
5
4
3
2
1
About the Author Jon Duckett published his first Web site in 1996 while studying for a BSc (Hons) in Psychology at Brunel University, London. Since then he has helped create a wide variety of Web sites and has co-written more than ten programming-related books on topics from ASP to XML (via many other letters of the alphabet) covering diverse aspects of Web programming including design, architecture, and coding. After graduation, Jon worked for Wrox Press first in its Birmingham (UK) offices for three years and then in Sydney, Australia, for another year. He is now a freelance developer and consultant based in a leafy suburb of London, working for a range of clients spread across three continents. When not stuck in front of a computer screen, Jon enjoys listening to music and writing.
Credits Senior Acquisitions Editor
Editorial Manager
Jim Minatel
Mary Beth Wakefield
Development Editor
Vice President & Executive Group Publisher
James H. Russell
Richard Swadley
Production Editor
Vice President and Executive Publisher
Eric Newman
Bob Ipsen
Copy Editor
Vice President and Publisher
Nancy Rapoport
Joseph B. Wikert
Contents Introduction
xxiii
Chapter 1: Untangling the Web
1
A Web of Structured Documents How the Web Works Introducing Web Technologies
2 2 4
Introducing HTML Keeping Style Separate from Structure and Semantics Introducing CSS Introducing XHTML Differences Between Writing XHTML and Writing HTML A Few Words About JavaScript Tools for Writing Web Pages
4 10 10 12 13 16 16
Creating Your First Web Page Viewing the Source of Web Pages Summary Exercises
17 21 22 23
Chapter 2: The Structure of a Page
25
Understanding the Basic Document Structure The The The The
Element Element Element Element
Attribute Groups
26 26 27 27 28
29
Core Attributes Internationalization UI Events
29 31 33
Basic Text Formatting
33
Whitespace and Flow Creating Headings Using hn Elements Creating Paragraphs Using the
Element
34 35 38
Contents Creating Line Breaks Using the Element Creating Preformatted Text Using the <pre> Element
Presentational Elements The The The The The The The The The The
Element Element Element (deprecated) <s> and <strike> Elements (deprecated) Element <sup> Element <sub> Element Element <small> Element Element
Phrase Elements The The The The The The The The The The The The The
<em> Element Adds Emphasis <strong> Element Adds Strong Emphasis Element Is for Abbreviations Element Is for Acronym Use Element Is for Special Terms
Element Is for Quoting Text Element Is for Short Quotations Element Is for Citations Element Is for Code Element Is for Text Typed on a Keyboard Element Is for Programming Variables <samp> Element Is for a Program Output Element Is for Addresses
Lists Using the
Element to Create Unordered Lists Ordered Lists Definition Lists Nesting Lists How It Works
Editing Text Using to Indicate New Additions to Text Using <del> to Indicate Deleted Text
Using Character Entities for Special Characters Comments The Element (deprecated) Understanding Block and Inline Elements Grouping Elements with
and <span>
viii
38 39
43 43 43 44 44 44 44 45 45 45 46
46 47 47 48 48 49 49 50 51 51 52 52 53 53
53 54 55 57 57 60
62 63 63
64 64 65 65 66
Contents Summary Exercises
Chapter 3: Links and Navigation Basic Links Linking to Other Documents Linking to E-mail Addresses
Understanding Directories and Directory Structures What Are You Linking To? What a URL Is Made Up Of Absolute and Relative URLs The Element