272 36 6MB
English Pages 740 Year 2000
HTM L 4 Bible, 2nd Edition
HTM L 4 Bible, 2nd Edition Bryan Pfaffenberger and Bill Karow
IDG Bo o ks Wo rldwide, Inc . An Internatio nal Data Gro up Co mpany Fo ster City, CA ✦ Chic ago , IL ✦ Indianapo lis, IN ✦ New Yo rk, NY
HTML 4 Bible, 2nd Edition Published by
IDG Books Worldwide, Inc. An Internatio nal Data Gro up Co mpany 919 E. Hillsdale Blvd., Suite 400 Fo ster City, CA 94404 www.idgbooks.com (IDG Bo o ks Wo rldwide Web site) Co pyright © 2000 IDG Bo o ks Wo rldwide, Inc . All rights reserved. No part o f this bo o k, inc luding interio r design, c o ver design, and ic o ns, may be repro duc ed o r transmitted in any fo rm, by any means (elec tro nic , pho to c o pying, rec o rding, o r o therwise) witho ut the prio r written permissio n o f the publisher. ISBN: 0-7645-3473-4 Printed in the United States o f Americ a 10 9 8 7 6 5 4 3 2 1 1B/ RX/ QY/ QQ/ FC Distributed in the United States by IDG Bo o ks Wo rldwide, Inc . Distributed by CDG Bo o ks Canada Inc . fo r Canada; by Transwo rld Publishers Limited in the United Kingdo m; by IDG No rge Bo o ks fo r No rway; by IDG Sweden Bo o ks fo r Sweden; by IDG Bo o ks Australia Publishing Co rpo ratio n Pty. Ltd. fo r Australia and New Zealand; by TransQuest Publishers Pte Ltd. fo r Singapo re, Malaysia, Thailand, Indo nesia, and Ho ng Ko ng; by Go to p Info rmatio n Inc . fo r Taiwan; by ICG Muse, Inc . fo r Japan; by Interso ft fo r So uth Afric a; by Eyro lles fo r Franc e; by Internatio nal Tho mso n Publishing fo r Germany, Austria, and Switzerland; by Distribuido ra Cuspide fo r Argentina; by LR Internatio nal fo r Brazil; by Galileo Libro s fo r Chile; by Edic io nes ZETA S.C.R. Ltda. fo r Peru; by WS Co mputer Publishing Co rpo ratio n, Inc ., fo r the Philippines; by Co ntempo ranea de Edic io nes fo r Venezuela; by Express Co mputer Distributo rs fo r the Caribbean and West Indies; by Mic ro nesia Media Distributo r, Inc . fo r Mic ro nesia; by Chips Co mputado ras S.A. de C.V. fo r Mexic o ; by Edito rial No rma de Panama S.A. fo r Panama; by Americ an Bo o ksho ps fo r Finland.
Fo r general info rmatio n o n IDG Bo o ks Wo rldwide’s bo o ks in the U.S., please c all o ur Co nsumer Custo mer Servic e department at 800-762-2974. Fo r reseller info rmatio n, inc luding disc o unts and premium sales, please c all o ur Reseller Custo mer Servic e department at 800-434-3422. Fo r info rmatio n o n where to purc hase IDG Bo o ks Wo rldwide’s bo o ks o utside the U.S., please c o ntac t o ur Internatio nal Sales department at 317-596-5530 o r fax 317-572-4002. Fo r c o nsumer info rmatio n o n fo reign language translatio ns, please c o ntac t o ur Custo mer Servic e department at 800-434-3422, fax 317-572-4002, o r e-mail rights@idgbo o ks.c o m. Fo r info rmatio n o n lic ensing fo reign o r do mestic rights, please pho ne +1-650-653-7098. Fo r sales inquiries and spec ial pric es fo r bulk quantities, please c o ntac t o ur Order Servic es department at 800-434-3422 o r write to the address abo ve. Fo r info rmatio n o n using IDG Bo o ks Wo rldwide’s bo o ks in the c lassro o m o r fo r o rdering examinatio n c o pies, please c o ntac t o ur Educ atio nal Sales department at 800-434-2086 o r fax 317-572-4005. Fo r press review c o pies, autho r interviews, o r o ther public ity info rmatio n, please c o ntac t o ur Public Relatio ns department at 650-653-7000 o r fax 650-653-7500. Fo r autho rizatio n to pho to c o py items fo r c o rpo rate, perso nal, o r educ atio nal use, please c o ntac t Co pyright Clearanc e Center, 222 Ro sewo o d Drive, Danvers, MA 01923, o r fax 978-750-4470.
Library of Congress Cataloging-in-Publication Data Pfaffenberger, Bryan, 1949HTML 4 Bible / Bryan Pfaffenberger and Bill Karo w.--2nd ed. p. c m. ISBN 0-7645-3473-4 (alk. paper) 1. HTML (Do c ument markup language) I. Karo w, Bill. II. Title. QA76.76.H94 P494 2000 005.7'2--dc 21 00-040993
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND AUTHOR HAVE USED THEIR BEST EFFORTS IN PREPARING THIS BOOK. THE PUBLISHER AND AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. THERE ARE NO WARRANTIES WHICH EXTEND BEYOND THE DESCRIPTIONS CONTAINED IN THIS PARAGRAPH. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS. THE ACCURACY AND COMPLETENESS OF THE INFORMATION PROVIDED HEREIN AND THE OPINIONS STATED HEREIN ARE NOT GUARANTEED OR WARRANTED TO PRODUCE ANY PARTICULAR RESULTS, AND THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY INDIVIDUAL. NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR OTHER DAMAGES. FULFILLMENT OF EACH COUPON OFFER IS THE RESPONSIBILITY OF THE OFFEROR. Trademarks: All brand names and pro duc t names used in this bo o k are trade names, servic e marks, trademarks, o r registered trademarks o f their respec tive o wners. IDG Bo o ks Wo rldwide is no t asso c iated with any pro duc t o r vendo r mentio ned in this bo o k. is a registered trademark o r trademark under exc lusive lic ense to IDG Bo o ks Wo rldwide, Inc . fro m Internatio nal Data Gro up, Inc . in the United States and/ o r o ther c o untries.
Welcome to the world of IDG Books Worldwide. IDG Books Worldwide, Inc., is a subsidiary of International Data Group, the world’s largest publisher of computer-related information and the leading global provider of information services on information technology. IDG was founded more than 30 years ago by Patrick J. McGovern and now employs more than 9,000 people worldwide. IDG publishes more than 290 computer publications in over 75 countries. More than 90 million people read one or more IDG publications each month. Launched in 1990, IDG Books Worldwide is today the #1 publisher of best-selling computer books in the United States. We are proud to have received eight awards from the Computer Press Association in recognition of editorial excellence and three from Computer Currents’ First Annual Readers’ Choice Awards. Our bestselling ...For Dummies® series has more than 50 million copies in print with translations in 31 languages. IDG Books Worldwide, through a joint venture with IDG’s Hi-Tech Beijing, became the first U.S. publisher to publish a computer book in the People’s Republic of China. In record time, IDG Books Worldwide has become the first choice for millions of readers around the world who want to learn how to better manage their businesses. Our mission is simple: Every one of our books is designed to bring extra value and skill-building instructions to the reader. Our books are written by experts who understand and care about our readers. The knowledge base of our editorial staff comes from years of experience in publishing, education, and journalism — experience we use to produce books to carry us into the new millennium. In short, we care about books, so we attract the best people. We devote special attention to details such as audience, interior design, use of icons, and illustrations. And because we use an efficient process of authoring, editing, and desktop publishing our books electronically, we can spend more time ensuring superior content and less time on the technicalities of making books. You can count on our commitment to deliver high-quality books at competitive prices on topics you want to read about. At IDG Books Worldwide, we continue in the IDG tradition of delivering quality for more than 30 years. You’ll find no better book on a subject than one from IDG Books Worldwide.
John Kilcullen Chairman and CEO IDG Books Worldwide, Inc.
Eighth Annual Computer Press Awards 1992
Ninth Annual Computer Press Awards 1993
Tenth Annual Computer Press Awards 1994
Eleventh Annual Computer Press Awards 1995
IDG is the world’s leading IT media, research and exposition company. Founded in 1964, IDG had 1997 revenues of $2.05 billion and has more than 9,000 employees worldwide. IDG offers the widest range of media options that reach IT buyers in 75 countries representing 95% of worldwide IT spending. IDG’s diverse product and services portfolio spans six key areas including print publishing, online publishing, expositions and conferences, market research, education and training, and global marketing services. More than 90 million people read one or more of IDG’s 290 magazines and newspapers, including IDG’s leading global brands — Computerworld, PC World, Network World, Macworld and the Channel World family of publications. IDG Books Worldwide is one of the fastest-growing computer book publishers in the world, with more than 700 titles in 36 languages. The “...For Dummies® ” series alone has more than 50 million copies in print. IDG offers online users the largest network of technology-specific Web sites around the world through IDG.net (http://www.idg.net), which comprises more than 225 targeted Web sites in 55 countries worldwide. International Data Corporation (IDC) is the world’s largest provider of information technology data, analysis and consulting, with research centers in over 41 countries and more than 400 research analysts worldwide. IDG World Expo is a leading producer of more than 168 globally branded conferences and expositions in 35 countries including E3 (Electronic Entertainment Expo), Macworld Expo, ComNet, Windows World Expo, ICE (Internet Commerce Expo), Agenda, DEMO, and Spotlight. IDG’s training subsidiary, ExecuTrain, is the world’s largest computer training company, with more than 230 locations worldwide and 785 training courses. IDG Marketing Services helps industry-leading IT companies build international brand recognition by developing global integrated marketing programs via IDG’s print, online and exposition products worldwide. Further information about the company can be found at www.idg.com. 1/26/00
Credits Acquisitions Editors
Quality Control Technician
David Mayhew Jo hn Gravener
Din F Quan
Permissions Editor Project Editor
Carmen Kriko rian
Sharo n Eames
Technical Editor
Associate Media Development Specialist
Greg Guntle
Jamie Smith
Copy Editor
Media Development Assistant
Laura J. Hester
Marisa Pearman
Proof Editor
Media Development Managers
Patsy Owens
Stephen No etzel Laura Carpenter
Project Coordinators Danette Nurse Lo uigene A. Santo s
Book Designer
Graphics and Production Specialists
Illustrator
Bo b Bihlmayer Darren Cutlip Jude Levinso n Vic to r Pérez-Varela Ramses Ramirez
Gabriele Mc Cann
Drew R. Mo o re
Proofreading and Indexing Yo rk Pro duc tio n Servic es
Cover Illustration Larry S. Wilso n
About the Authors Bryan Pfaffenberger is the autho r o f mo re than 75 bo o ks o n c o mputers and the Internet, inc luding the best-selling Disco ve r the Inte rne t, fro m IDG Bo o ks Wo rldwide. He teac hes advanc ed pro fessio nal c o mmunic atio n and the so c io lo gy o f c o mputing in the University o f Virginia’s Divisio n o f Tec hno lo gy, Culture, and Co mmunic atio n. Bryan lives in Charlo ttesville, Virginia, with his family and an extremely spo iled c at. In additio n to writing several c o mputer bo o ks, Bill Karow has served as a c o ntributo r o r tec hnic al edito r o n mo re than 30 o ther bo o ks. Fo rmerly in c harge o f systems develo pment fo r Walt Disney Entertainment, Bill no w serves as a c o mputer c o nsultant in the Orlando area when he’s no t o ut riding his bic yc le. He also has the distinc tio n o f having sto o d ato p many o f the buildings at Walt Disney Wo rld, fanfare trumpet in hand (with their permissio n, o f c o urse).
To Suz anne and Farris
Preface
R
emember all that late-1980s talk abo ut the Info rmatio n Superhighway? Yo u learned yo u’d get 500 c able c hannels, no t just 50 (o r, as c o medians put it, 500 terrible c hannels instead o f 50 terrible c hannels). Like mo st predic tio ns invo lving tec hno lo gy, this o ne was way o ff the mark. (Add this o ne to the gro wing c atalo g o f predic tio ns go ne awry, suc h as the famed remark by a 1950s IBM exec utive that the wo rld wo uld need, at mo st, a do zen o r so c o mputers.) The Info rmatio n Superhighway didn’t happen at the TV; instead, it happened at the perso nal c o mputer, c o nnec ted to the Internet and the Wo rld Wide Web. Far mo re impo rtant, tho ugh, the Info rmatio n Superhighway that has develo ped isn’t like TV at all. TV is a bro adc ast medium, in whic h c o rpo rate c o ntent pro viders determine what yo u’re go ing to see. The Web, fro m the beginning, was designed to transfo rm c o uc h po tato es into c o ntent pro duc ers. Yo u c an do no thing but c o nsume Web c o ntent, to be sure, and millio ns o f Web surfers are o ut there who are happy to flit fro m site to site witho ut making their o wn c o ntributio n. And WebTV, o f c o urse, brings the Web-as-TV to the TV — and in so do ing, ro bs the Web o f part o f its po wer. What makes the Web suc h a po werful medium is, unlike all o ther mass media, it’s inherently a two -way street, c o ntent-wise. Anyo ne who c an c o nsume c o ntent o n the Web c an also pro duc e it, using HTML, the easy-to -learn page definitio n language that underlies the Web’s appearanc e. It’s as if yo u go t a mo rning paper, but by afterno o n, yo u c o uld publish yo ur o wn take o n the news — and make it available, po tentially, to millio ns o f peo ple. The Web is pro bably the mo st impo rtant develo pment in suppo rt o f free speec h sinc e the inventio n o f the printing press, in that it enables virtually anyo ne to o riginate c o ntent c heaply and make this c o ntent available to a po tentially massive audienc e. Unquestio nably, the Web is go o d fo r the enviro nment: millio ns o f tree-killing public atio ns are mo ving to the Web. Within c o rpo ratio ns, fo r example, vo lumino us public atio ns — direc to ries, emplo yee manuals, pro c edure manuals, agendas, repo rts, and meeting minutes — appear in Web-based internal netwo rks c alled intranets; the enviro nmental plusses, c o upled with signific ant c o st savings, make this inno vatio n a no -brainer. Fo r even the smallest business, the Web pro vides a way to get yo ur message o ut, stay in to uc h with c usto mers, and pro vide needed info rmatio n, but witho ut running up a huge bill at the printer. And the best part o f all is no o ne c an tell ho w big o r
x
Preface
small yo u are. No reaso n exists fo r them ever to kno w o nly o ne little sc ientist is behind the c urtain in the Emerald City. The list o f Web impac ts c o uld go o n fo r do zens o f pages, but the pattern’s c lear: the Web is fast bec o ming an indispensable new way to make info rmatio n available to o thers. This do esn’t mean the Web is go ing to replac e o ther media anytime so o n. If yo u’re running a retail business, yo u’d be wise to advertise in the lo c al newspaper as well as set up a Web page, but it do es mean the Web is no lo nger so mething yo u c an prudently igno re. No matter what yo ur message might be, yo u want to get it o ut o n the Web.
Who Should Read This Book? What all this means fo r yo u is simple: Whatever yo ur walk o f life — whether yo u’re a businessperso n, a manager, a student at any level, a retired perso n, a ho memaker, o r the vic e president o f the United States (a c o nfessed Web junkie) — yo u o we it to yo urself to learn ho w to o riginate Web c o ntent. And this means learning HTML. To do this, yo u need a bo o k — a c o mprehensive bo o k, and what’s mo re, a bo o k that teac hes yo u ho w to take full advantage o f this exc iting new versio n o f HTML, Versio n 4.01. Whether yo u’re a c o mplete beginner o r so meo ne who ’s already delved into previo us versio ns o f HTML, yo u’ll find this bo o k is abso lutely the right o ne fo r learning and mastering HTML 4.01 — and in so do ing, assure yo ur plac e in the Web’s future.
What’s So Special About This Book? The HTML 4 Bible , 2nd Editio n is yo ur tic ket to mastery o f the newest versio n o f HTML, Versio n 4.01. As yo u learn in the next sec tio n, HTML 4 is the mo st signific ant revisio n o f the Web’s publishing language to appear sinc e the language’s inventio n. Yo u need a bo o k that rec o gnizes these no vel features and takes a no vel appro ac h. Fo r the first time, HTML pro vides Web publishers with the po wer and flexibility to c reate page layo uts rivaling tho se fo und in pro fessio nally designed magazines and newsletters. HTML 4 requires a new appro ac h to HTML, ho wever. If yo u’ve learned previo us versio ns o f HTML, yo u need to unlearn so me o ld habits — a lo t o f o ld habits. If yo u’re learning HTML fo r the first time, yo u need to learn it the right way,by reading a bo o k that’s no t just a quic kie rehash o f a bo o k o n so me previo us versio n o f HTML. Fro m the first sentenc e to the last item in the final appendix, this bo o k was written fro m sc ratc h to emphasize the HTML 4 Way, the radic ally new appro ac h to Web publishing made po ssible by this exc iting new versio n o f HTML. No t a single wo rd o f this bo o k appeared in any previo us editio n that fo c used o n an earlier, flawed versio n o f HTML. This bo o k teac hes a new appro ac h to learning and using HTML 4, o ne that fully enables yo u to realize HTML 4’s inc redible layo ut po tential. Onc e yo u
Preface
learn what HTML is and understand the impo rtant implic atio ns o f HTML Versio n 4, yo u’ll understand why yo u need a bo o k that’s been written fro m the gro und up to emphasize HTML 4’s inc redible new c apabilities.
How This Book Is Organized This bo o k has seven parts. All o f them adhere stric tly to the HTML 4 Way.
Part I fo c uses o n getting yo u up to speed o n Web publishing: what’s in it fo r yo u, and what’s invo lved. Part II helps yo u understand HTML — where it is to day, and where it’s heading in the future with XML and XHTML. Part II inc ludes a review o f the latest HTML-editing so ftware o n the market with spec ial attentio n to whether it suppo rts the HTML 4 Way (and all o f it is inc luded o n the CD-ROM in the bac k o f the bo o k). Part III teac hes do c ument struc ture with HTML. Part IV helps yo u design the lo o k o f yo ur site with graphic s and c asc ading style sheets.
Part V teac hes advanc ed page layo ut and c asc ading style sheets — so mething no t c o vered in any o ther bo o k o f this type abo ut HTML 4.
Part VI explains ho w to add bells and whistles to yo ur site with multimedia and interac tivity.
Part VII explains what has bec o me kno wn as dynamic HTML and its animatio n with JavaSc ript.
Using This Book’s Special Features Bec ause this bo o k c an’t make use o f hypertext, it implements several spec ial c o nventio ns to draw yo ur attentio n to things yo u might want to kno w o r need to kno w o utside the text. Definition
To help you becom e fam iliar w ith new term s, w e introduce new term s and acronym s (and, boy, are a lot of acronym s associated w ith HTML!) in special vocabulary boxes. You’ll know them w hen you com e across them by looking for this Vocabulary icon.
In Depth
This book addresses the needs of a num ber of audiences, each of w hich desires a different level of technical detail. To accom m odate all levels, the m ain text covers w hat you need to know to publish your pages successfully. When there is m ore you m ight w ant to know, the topic is covered in-depth because w e set it apart from the text w ith this icon.
xi
xii
Preface
Tip
If w e suggest a particularly useful w ay to achieve som ething, a m arvelous shortcut, or a clever alternative, w e identify it w ith this icon to save you both tim e and frustration . . . at no extra charge!
Caution
Many of you are already fam iliar w ith HTML 4.0 and earlier versions. For you, know ing both how HTML 4.01 does it and w hen doing it the pre-HTML 4.01 Way m ight get you into trouble w ith subsequent versions of brow sers is im portant. The W3C calls certain uses of elem ents and attributes deprecated. Rather than ignoring deprecated elem ents and attributes, in w hich case you m ight go ahead and use them , this book flags them w ith an icon, along w ith any other special inform ation you should know.
On the CD-ROM
Content you find included on this book’s CD-ROM is flagged w ith a CD icon for your convenience.
CrossReference
Som etim es you are directed to other sections of the chapter or other chapters in the book for m ore inform ation on a topic. In addition, each chapter ends w ith a section telling you w here you go next in the book —a particularly useful feature if you’re not follow ing the book sequentially.
We didn’t inc lude anything unimpo rtant. If yo u read a c hapter every night, yo u c an be as kno wledgeable as the pro s in less than two mo nths! In what o ther c areer c o uld yo u kno w what the experts kno w this quic kly? What are yo u waiting fo r? Begin!
Acknowledgments
W
riting this bo o k has been a real adventure. So many peo ple have helped us alo ng the way. With the breadth o f material this bo o k c o vers, we o c c asio nally turned to spec ialists to make sure everything we said was up-to -the-mo ment c o rrec t. Many thanks to Peter Dalianis fo r his pro fessio nal and tho ughtful c o mments o n defining the message. Thanks also to Ric k Pro vine fo r his invaluable assistanc e with digital audio . Mic hael Tuite pro vided tho ughtful assistanc e with digital video and a ho st o f o ther issues, fo r whic h we are grateful. We are indebted to Chuc k Mo ran and Debra Weiss, who genero usly assisted with pro fessio nal design advic e fo r the sec tio n o n site design. Thanks also to Tim O’Brien fo r his help with Java rapid develo pment enviro nments. Thank yo u to Caro le Mc Clendo n and Chris Van Buren at Waterside Pro duc tio ns fo r pulling this o ppo rtunity to gether and making it happen. Thanks to e ve ryo ne at IDG Bo o ks Wo rldwide; a mo re pro fessio nal gro up has never been assembled. Thanks to pro jec t edito r Sharo n Eames, ac quisitio ns edito rs David Mayhew and Jo hn Gravener, tec hnic al edito r Greg Guntle, c o py edito r Laura Hester, and pro o f edito r Patsy Owens. Also wo rking behind the sc enes were permissio ns edito r Jessic a Mo ntgo mery, graphic s c o o rdinato r Danette Nurse, layo ut superviso r Chris Pimentel, pro jec t c o o rdinato r Lo uigene Santo s, and a multitude o f o thers at IDG Bo o ks, to o numero us to mentio n here. Extra spec ial thanks also sho uld go to Ric k Darnell fo r his assistanc e with the last part o f this bo o k, and to Mic hele Davis, fo r jumping in to ensure this bo o k wo uld make it o ut to yo u, the reader. Thanks! Finally, Bill wo uld like to thank Suzanne and Farris fo r their patienc e and suppo rt while he disappeared fo r many ho urs at a time. This wo uldn’t have been po ssible witho ut yo u bo th.
Contents at a Glance Prefac e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix Ac kno wledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Part I: HTM L 4 Quick Start . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Chapter 1: HTML 4 Basic s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Chapter 2: The HTML 4 Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Chapter 3: Creating Yo ur First Web Page . . . . . . . . . . . . . . . . . . . . . . . . 29 Chapter 4: Go ing Public ! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Part II: Understanding HTM L 4 . . . . . . . . . . . . . . . . . . . . . . . 69 Chapter 5: Intro duc ing HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Chapter 6: What Abo ut XML/ XSL? . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Chapter 7: Intro duc ing XHTML: HTML’s Future . . . . . . . . . . . . . . . . . . . . 95 Chapter 8: Cho o sing an HTML Edito r . . . . . . . . . . . . . . . . . . . . . . . . . 101 Chapter 9: Writing fo r the Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Chapter 10: Co nsidering Spec ial Needs — Web Ac c essibility . . . . . . . . . . . 135 Chapter 11: Understanding Server Optio ns . . . . . . . . . . . . . . . . . . . . . 139
Part III: Developing Document Structure with HTM L 4 . . . . . . . . 155 Chapter 12: Understanding HTML 4 Do c ument Arc hitec ture . . . . . . . . Chapter 13: Spec ifying the HTML Versio n and Do c ument Title . . . . . . . Chapter 14: Spec ifying Metadata . . . . . . . . . . . . . . . . . . . . . . . . Chapter 15: Struc turing Lines and Paragraphs with Blo c k-Level Elements Chapter 16: Creating Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 17: Using Inline Elements and Spec ial Charac ters . . . . . . . . . . Chapter 18: Adding Hyperlinks . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 19: Inserting Graphic s and Other Objec ts . . . . . . . . . . . . . . Chapter 20: Adding Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 21: Creating Fo rms and Inserting Sc ripts . . . . . . . . . . . . . . . Chapter 22: Creating Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 23: Gro uping Elements with DIV and SPAN . . . . . . . . . . . . . . Chapter 24: Testing and Validating Yo ur HTML . . . . . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
157 169 173 179 187 195 205 215 223 239 263 275 279
Part IV: Enhancing Presentation with Cascading Style Sheets . . . . 287 Chapter 25: Intro duc ing Casc ading Style Sheets Chapter 26: Learning CSS Syntax . . . . . . . . Chapter 27: Adding Styles to Yo ur Web Pages . Chapter 28: Adding Co lo rs and Bac kgro unds . Chapter 29: Fo rmatting Paragraphs . . . . . . . Chapter 30: Fo rmatting Tables . . . . . . . . . . Chapter 31: Adding Fo nts . . . . . . . . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
289 297 309 319 327 337 349
Part V: Lay It Out Like the Pros . . . . . . . . . . . . . . . . . . . . . . 359 Chapter 32: Essentials o f Web Page Design . . . . . Chapter 33: Understanding CSS Po sitio ning Optio ns Chapter 34: Po sitio ning Graphic s and Text . . . . . . Chapter 35: Co o l CSS Po sitio ning Tips and Tric ks . . Chapter 36: Struc turing Multipage Sites . . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
361 381 391 403 411
Part VI: Adding Sensory Excitement and Interactivity . . . . . . . . . 431 Chapter 37: Creating Still Graphic s fo r the Web . . . . . . . . . . . . . . . . . . . Chapter 38: Creating Animated Graphic s fo r the Web . . . . . . . . . . . . . . . Chapter 39: Designing and Implementing Imagemaps . . . . . . . . . . . . . . . Chapter 40: Pro duc ing and Adding So unds . . . . . . . . . . . . . . . . . . . . . Chapter 41: Pro duc ing and Adding Video . . . . . . . . . . . . . . . . . . . . . . Chapter 42: Inc o rpo rating Plug-Ins and Ac tiveX Co ntro ls . . . . . . . . . . . . . Chapter 43: Adding Java Applets . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating 44: Subsc riptio ns with the Channel Definitio n Fo rmat . . . . . . . . . . Chapter 45: Ac c essing External Databases . . . . . . . . . . . . . . . . . . . . . . Chapter 46: Building a Co mmunity: Inc o rpo rating Disc ussio n Gro ups and Chat
433 445 453 461 471 479 495 503 511 519
Part VII: Using Cross-Browser Dynamic HTM L . . . . . . . . . . . . . 525 Chapter 47: Intro duc ing Dynamic HTML and the Do c ument Objec t Mo del Chapter 48: Cro ss-Bro wser Basic s with JavaSc ript . . . . . . . . . . . . . . Chapter 49: Frames, Layers, and the Shell Game . . . . . . . . . . . . . . . Chapter 50: Do ing Windo ws with JavaSc ript . . . . . . . . . . . . . . . . . .
. . . .
. . . .
. . . .
527 539 557 571
Appendix Appendix Appendix Appendix Appendix Appendix Appendix Appendix
A: HTML 4 Data Types . . . . . . . . . . B: HTML 4 Elements Referenc e . . . . . C: HTML 4 Attributes Referenc e . . . . . D: HTML 4 Charac ter Entities Referenc e E: Casc ading Style Sheets Referenc e . . F: Language Co des Referenc e . . . . . . G: Hex No tatio ns Referenc e . . . . . . . H: Abo ut the CD-ROM . . . . . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
579 583 653 665 669 713 719 723
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725 End-User Lic ense . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 744 CD-Ro m Installatio n Instruc tio ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . 750
Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix Acknow ledgm ents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Part I: HTM L 4 Quick Start
1
Chapter 1: HTM L 4 Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Intro duc ing the Basic Building Blo c ks: Elements . . . . . . . . . . . . . . . . 3 Elements versus tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Even elements have parts . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Understanding Yo ur Optio ns: Attributes . . . . . . . . . . . . . . . . . . . . . 5 Co uples o nly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Always sho p fro m a list . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Please take a number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 The c o lo rs o f the wo rld . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Creativity c o unts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Using Spec ial Charac ters: Entities . . . . . . . . . . . . . . . . . . . . . . . . . 8 Adding Co mments to Yo ur HTML . . . . . . . . . . . . . . . . . . . . . . . . 10 Making Yo ur HTML Readable . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Avo iding Co mmo n Syntax Erro rs . . . . . . . . . . . . . . . . . . . . . . . . . 12 Understanding Nesting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 The Basic Struc ture o f an HTML Do c ument: HEAD and BODY . . . . . . . . 14 Fro m Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Chapter 2: The HTM L 4 Way . . . . . . . . . . . . . . . . . . . . . . . . . 17 The Extensio n Pro blem . . . . . . . . . . . . . . . . Co mpatibility ac ro ss bro wsers . . . . . . . . The Wo rld Wide Web Co nso rtium . . . . . . . The Ideal: Separating Struc ture fro m Presentatio n Cluttered HTML (the pre-HTML-4 universe) . The maintenanc e nightmare . . . . . . . . . . HTML 4 defines struc ture . . . . . . . . . . . . Intro duc ing Casc ading Style Sheets . . . . . . . . . The HTML 4 Way . . . . . . . . . . . . . . . . . . . . The Future: XML . . . . . . . . . . . . . . . . . . . . The Ideal Versus the Reality . . . . . . . . . . . . . Where’s All This Go ing? . . . . . . . . . . . . . . . . What Sho uld Yo u Do No w? . . . . . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
17 18 19 20 20 22 23 24 26 26 27 27 28 28
xviii
Contents
Chapter 3: Creating Your First Web Page . . . . . . . . . . . . . . . . . 29 Fire Up Yo ur Edito r . . . . . . . . . . . . . . . Titling Yo ur Page . . . . . . . . . . . . . . . . First things first . . . . . . . . . . . . . Identifying the Autho r . . . . . . . . . . . . . Defining key wo rds fo r better retrieval Beginning the BODY . . . . . . . . . . . . . . Adding an Apparent Title . . . . . . . . . . . Typing and Editing Text . . . . . . . . . . . . Paragraphs . . . . . . . . . . . . . . . . Blo c kquo tes . . . . . . . . . . . . . . . Breaking Lines and Starting New Paragraphs Preventing line breaks . . . . . . . . . Adding ho rizo ntal lines . . . . . . . . . Creating a List . . . . . . . . . . . . . . . . . Bulleted lists . . . . . . . . . . . . . . . Numbered lists . . . . . . . . . . . . . . Adding a Link . . . . . . . . . . . . . . . . . . Adding an internal link . . . . . . . . . Adding an external link . . . . . . . . . Preview Yo ur Page . . . . . . . . . . . . . . . Finishing To uc hes . . . . . . . . . . . . . . . Lo ading yo ur style sheets . . . . . . . Linking to style sheets . . . . . . . . . Change yo ur style . . . . . . . . . . . . HTML Elements in Sho rthand . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
29 31 31 32 32 34 34 36 36 36 37 37 38 39 39 40 41 41 42 42 43 43 43 44 45 46
Chapter 4: Going Public! . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Getting Yo ur Fac ts Straight . . . . . . . . . . . . . . . . . . . . . Deskto p Web Servers . . . . . . . . . . . . . . . . . . . . . . . . Enterprise Web Servers . . . . . . . . . . . . . . . . . . . . . . . Publishing o n Yo ur Own Server . . . . . . . . . . . . . . . . . . Publishing o n Yo ur Servic e Pro vider’s Server . . . . . . . . . . Platfo rm Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . Extra: Publishing to a Windo ws NT/ 2000 server . . . . . . . . . . . . . . . . . . . . Fro m Windo ws 98 . . . . . . . . . . . . . . . . . . . . . . . Fro m Windo ws NT/ 2000 . . . . . . . . . . . . . . . . . . . Fro m a Mac . . . . . . . . . . . . . . . . . . . . . . . . . . . Intro duc ing FTP . . . . . . . . . . . . . . . . . . . . . . . . . . . Intro duc ing FTP c lients: CuteFTP, WS_FTP, Fetc h . . . . . . . . Develo ping Direc to ries to Sto re Yo ur Pages and Graphic s . . . Direc to ry struc ture to matc h yo ur pages . . . . . . . . . . Direc to ry struc ture by file type (generally a better idea)
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
47 49 51 51 52 52
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
53 53 56 57 59 60 62 62 63
Uplo ading Yo ur Pages and Graphic s DNS . . . . . . . . . . . . . . . . . . . Permissio ns . . . . . . . . . . . . . . Testing Yo ur Wo rk . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
Part II: Understanding HTM L 4
. . . . .
64 65 65 65 67
69
Chapter 5: Introducing HTM L . . . . . . . . . . . . . . . . . . . . . . . . 71 What’s Yo ur Purpo se? . . . . . . . . . . . . . Transit po int . . . . . . . . . . . . . . . Destinatio n . . . . . . . . . . . . . . . . Educ atio nal . . . . . . . . . . . . . . . . Mo tivatio nal . . . . . . . . . . . . . . . Info rmatio nal . . . . . . . . . . . . . . . Persuasive . . . . . . . . . . . . . . . . Sales . . . . . . . . . . . . . . . . . . . . Understanding Yo ur To o ls . . . . . . . . . . SGML . . . . . . . . . . . . . . . . . . . HTML . . . . . . . . . . . . . . . . . . . The HTML Standardizatio n Pro c ess . . . . . Buzz and sc rambling . . . . . . . . . . Co mmittees and wo rking drafts . . . . Vo ting pro c ess . . . . . . . . . . . . . . HTML edito rs . . . . . . . . . . . . . . . Writing HTML . . . . . . . . . . . . . . . . . . Fo rmat yo ur text . . . . . . . . . . . . . Struc ture yo ur do c ument . . . . . . . . Inc luding Multimedia . . . . . . . . . . . . . Inline . . . . . . . . . . . . . . . . . . . Out-o f-line . . . . . . . . . . . . . . . . . Objec ts . . . . . . . . . . . . . . . . . . Standardizatio n . . . . . . . . . . . . . . . . . Understanding the Standardizatio n Pro c ess Ac tivities . . . . . . . . . . . . . . . . . Gro ups . . . . . . . . . . . . . . . . . . Co nsensus . . . . . . . . . . . . . . . . Pro po sed rec o mmendatio ns . . . . . . Vo ting . . . . . . . . . . . . . . . . . . . Rec o mmendatio ns . . . . . . . . . . . . Players in the Standardizatio n Pro c ess . . . The Extensio ns Game . . . . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
72 72 72 73 73 74 74 75 75 76 77 77 77 78 78 80 81 82 82 83 83 84 84 84 85 85 86 86 86 86 87 87 88 89
xx
Introduction
Chapter 6: What About XM L/ XSL? . . . . . . . . . . . . . . . . . . . . . 91 What Is XML? . . . . . . . . . . . Do c ument type definitio n . XML namespac e . . . . . . What Is XSL . . . . . . . . . . . . Transfo rmatio ns . . . . . . Fo rmatting . . . . . . . . . Fro m Here . . . . . . . . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
91 92 92 92 93 93 93
Chapter 7: Introducing XHTM L: HTM L’s Future . . . . . . . . . . . . . 95 What Is XHTML? . . . . . . . . . . . . . . . . Extensibility . . . . . . . . . . . . . . . Po rtability . . . . . . . . . . . . . . . . Differenc es Between HTML and XHTML . . . Required tags . . . . . . . . . . . . . . Tags must be pro perly nested . . . . . Lo werc ase tag and attribute names . . Empty elements are no t allo wed . . . . No nempty elements have to be c lo sed Attribute values must be quo ted . . . Attribute values must be expanded . . Fro m Here . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
95 95 96 96 96 96 98 98 98 99 99 99
Chapter 8: Choosing an HTM L Editor . . . . . . . . . . . . . . . . . . 101 To WYSIWYG o r No t to WYSIWYG? . . . . . . . . . . WYSIWYG edito rs: Easy to use, but hands-o ff Getting serio us: Tag-based pro grams . . . . . What’s the differenc e? . . . . . . . . . . . . . . Explo ring HTML Edito r Features . . . . . . . . . . . Co nsideratio ns . . . . . . . . . . . . . . . . . . HTML 4 suppo rt . . . . . . . . . . . . . . . . . Suppo rt fo r advanc ed tags . . . . . . . . . . . Lo o king at HTML Edito rs . . . . . . . . . . . . . . . TextPad 4.2.1 . . . . . . . . . . . . . . . . . . . Ho tDo g Pro fessio nal 6.0 . . . . . . . . . . . . . Ho meSite 4.5 . . . . . . . . . . . . . . . . . . . Ho TMetaL PRO 6.0 . . . . . . . . . . . . . . . . Co ffeeCup 8.2 . . . . . . . . . . . . . . . . . . . Dreamweaver . . . . . . . . . . . . . . . . . . . Fro ntPage 2000 . . . . . . . . . . . . . . . . . . HTML-Kit 1.0 . . . . . . . . . . . . . . . . . . . PageMill 3.0 . . . . . . . . . . . . . . . . . . . . NetObjec ts Fusio n 5.0 . . . . . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
102 102 102 103 105 105 106 111 117 117 117 119 120 121 123 124 124 125 126 127
Introduction
Chapter 9: Writing for the Web . . . . . . . . . . . . . . . . . . . . . . 129 Designing fo r Quic k Sc anning . . Writing Co nc isely . . . . . . . . . Ac tive verbs . . . . . . . . . Subo rdinatio n . . . . . . . . Expletives . . . . . . . . . . Sentenc e length . . . . . . . Write Vividly . . . . . . . . . . . . Chec k Spelling and Pro o freading Fro m Here . . . . . . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
129 131 131 132 132 133 133 134 134
Chapter 10: Considering Special Needs —Web Accessibility . . . . . 135 Ac c essible Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Ac c essibility Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 Fro m Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Chapter 11: Understanding Server Options . . . . . . . . . . . . . . . 139 The Client-Server Mo del . . . . . . . . . . The c lient-server mo del . . . . . . . Pro c essing: The c rux o f the issue . Client Pro c essing . . . . . . . . . . . . . . Intro duc ing Web Servers . . . . . . . . . . Permissio ns . . . . . . . . . . . . . . NT: Hidden permissio n . . . . . . . Server Pro c essing . . . . . . . . . . . . . . What the Web server c an’t pro c ess Co nverting sc ripts to HTML . . . . The Histo ry o f Middleware . . . . . . . . Built-in middleware . . . . . . . . . Stand-alo ne middleware . . . . . . . Rapid applic atio n develo pment . . Co o kies . . . . . . . . . . . . . . . . . . . . Sec ure Servers . . . . . . . . . . . . . . . Lo o king at UNIX Servers . . . . . . . . . . Lo o king at Windo ws NT Servers . . . . . Fro m Here . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
139 140 141 142 143 144 144 145 146 146 146 148 149 149 150 150 152 153 153
xxi
xxii
Introduction
Part III: Developing Document Structure with HTM L 4
155
Chapter 12: Understanding HTM L 4 Document Architecture . . . . 157 What’s New in HTML 4? . . . . . . . . . . . . Frames . . . . . . . . . . . . . . . . . . . Fo rms . . . . . . . . . . . . . . . . . . . Anno tatio n . . . . . . . . . . . . . . . . Tables . . . . . . . . . . . . . . . . . . . Fac ilitating CSS . . . . . . . . . . . . . . What’s go ne fro m HTML 4.0? . . . . . . Co mpo nents o f HTML . . . . . . . . . . . . . Elements . . . . . . . . . . . . . . . . . . Attributes . . . . . . . . . . . . . . . . . Entities . . . . . . . . . . . . . . . . . . . Blo c k Versus Inline Elements . . . . . . . . . Understanding Nesting . . . . . . . . . . . . . The HTML Element . . . . . . . . . . . . . . . The HEAD Element . . . . . . . . . . . . . . . Additio nal HEAD Elements . . . . . . . . . . . The BODY Element . . . . . . . . . . . . . . . Struc ture Versus Presentatio n, Again . . . . Making Yo ur HTML as Readable as Po ssible Fro m Here . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
157 157 158 158 158 159 159 159 159 160 160 160 161 162 163 163 166 166 167 167
Chapter 13: Specifying the HTM L Version and Document Title . . . 169 Versio n Info rmatio n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 Do c ument Title . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 Fro m Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Chapter 14: Specifying M etadata . . . . . . . . . . . . . . . . . . . . . 173 The META Element . . . . . . Name attributes . . . . The http-equiv attribute Ro bo ts.txt . . . . . . . . . . . Fro m Here . . . . . . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
173 174 175 176 177
Chapter 15: Structuring Lines and Paragraphs with Block-Level Elements . . . . . . . . . . . . . . . . . . . . 179 Intro duc ing Blo c k-Level Elements . . . . . . . . . . . . . . . . . . . . . . . 179 Dic tating presentatio n . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Introduction
Creating Paragraphs: The P Element . . . . . . . . . . . . . . Co ntro lling Line Breaks and Spac ing . . . . . . . . . . . . . . Breaking up yo ur page . . . . . . . . . . . . . . . . . . . Preventing a line break . . . . . . . . . . . . . . . . . . Adding Headings . . . . . . . . . . . . . . . . . . . . . . . . . Creating Indented Quo tatio ns: The BLOCKQUOTE Element Adding Prefo rmatted Text . . . . . . . . . . . . . . . . . . . . Gro uping Blo c k Elements: The DIV Element . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
180 181 181 182 182 183 184 185 186
Chapter 16: Creating Lists . . . . . . . . . . . . . . . . . . . . . . . . . 187 Intro duc ing Lists . . . . . . . . . . . . . . . . . Creating bulleted lists: The UL element . Creating numbered lists: The OL element Creating definitio n lists: The DL element Nesting Blo c k Elements . . . . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
187 187 189 190 192 192
Chapter 17: Using Inline Elements and Special Characters . . . . . 195 Intro duc ing Inline Elements . . . . . . . . . . Lo gic al Versus Physic al Styles . . . . . . . . Understanding Web Charac ter Sets . . . . . . Adding Spec ial Charac ters . . . . . . . . . . . Spec ial Charac ters fo r Spec ific Jo bs . . . . . Handling Fo reign Languages . . . . . . . . . . Adding Quo tes: The Q Element . . . . . . . . Gro uping Inline Elements: The SPAN Element Fro m Here . . . . . . . . . . . . . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
195 197 198 198 199 202 203 203 204
Chapter 18: Adding Hyperlinks . . . . . . . . . . . . . . . . . . . . . . 205 Understanding Links . . . . . . . . . . . . . . . . URLs Dissec ted . . . . . . . . . . . . . . . . . . . Linking Lo c al Pages with Relative File Names . . Qualifying the URL . . . . . . . . . . . . . . The A element . . . . . . . . . . . . . . . . Linking to Pages in Other Direc to ries . . . Linking to External Pages . . . . . . . . . . . . . Linking to Lo c atio ns o n the Same Page . . . . . Link to Pages fro m Images . . . . . . . . . . . . . Linking to No n-Web Data . . . . . . . . . . . . . . The BASE Element . . . . . . . . . . . . . . . . . Adding a mailto Link . . . . . . . . . . . . . . . . Bo nus: Create a Link Witho ut Leaving Yo ur Page Fro m Here . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
205 206 207 207 207 208 208 209 210 211 211 212 212 213
xxiii
xxiv
Contents
Chapter 19: Inserting Graphics and Other Objects . . . . . . . . . . 215 A Quic k Intro duc tio n to Graphic s File Fo rmats . . . JPEG . . . . . . . . . . . . . . . . . . . . . . . . GIF . . . . . . . . . . . . . . . . . . . . . . . . . PNG . . . . . . . . . . . . . . . . . . . . . . . . Creating a graphic image . . . . . . . . . . . . Adding Inline Images with the IMG Element . . . . . Multimedia . . . . . . . . . . . . . . . . . . . . . . . . Adding Inline Multimedia with the OBJECT Element Tips o n Using Images Effec tively . . . . . . . . . . . Pro viding Alternatives fo r Text-Only Bro wsers . . . Fro m Here . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
215 215 216 216 216 216 218 218 220 221 222
Chapter 20: Adding Tables . . . . . . . . . . . . . . . . . . . . . . . . . 223 Intro duc ing the HTML Table Mo del Defining the Table . . . . . . . . . . . Adding Table Data . . . . . . . . . . Gro uping Ro ws . . . . . . . . . . . . Defining Co lumns . . . . . . . . . . . Gro uping Co lumns . . . . . . . . . . Spanning Ro ws and Co lumns . . . . Adding Finishing To uc hes to a Table Nesting Tables . . . . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
223 224 226 231 234 235 236 237 238 238
Chapter 21: Creating Forms and Inserting Scripts . . . . . . . . . . . 239 Intro duc ing Fo rms . . . . . . . . . . . . . . . Understanding Fo rm Pro c essing . . . . . . . Saving the data fo r further pro c essing Returning info rmatio n to the visito r . . Taking o ther ac tio n . . . . . . . . . . . Inserting the FORM . . . . . . . . . . . . . . . Ac tio n . . . . . . . . . . . . . . . . . . . Metho d . . . . . . . . . . . . . . . . . . Adding Co ntro ls . . . . . . . . . . . . . . . . . INPUT Element . . . . . . . . . . . . . . . . . Type attribute . . . . . . . . . . . . . . BUTTON Element . . . . . . . . . . . . . . . . SELECT, OPTION, and OPTGROUP Elements SELECT element . . . . . . . . . . . . . OPTION element . . . . . . . . . . . . . TEXTAREA Element . . . . . . . . . . . . . . . LABEL Element . . . . . . . . . . . . . . . . . FIELDSET and LEGEND Elements . . . . . . . Fo rm Pro c essing Optio ns . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
239 240 240 240 241 241 242 242 243 245 246 251 252 253 254 256 257 258 259
Contents
Dealing with Fo rm Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 Mailto : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 Fro m Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Chapter 22: Creating Frames . . . . . . . . . . . . . . . . . . . . . . . 263 Intro duc ing Frames . . . . . . . . . . . . . Develo ping the Master Frame Do c ument Ro ws o nly . . . . . . . . . . . . . . . Co lumns o nly . . . . . . . . . . . . . Bo th ro ws and c o lumns . . . . . . . Nested FRAMESETs . . . . . . . . . Targets . . . . . . . . . . . . . . . . . . . . Creating FRAMEs . . . . . . . . . . . . . . Enhanc ing Navigability . . . . . . . . . . . NOFRAMES . . . . . . . . . . . . . . . . . . Adding Inline Frames (IFRAMEs) . . . . . Fro m Here . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
Chapter 23: Grouping Elements with DIV and SPAN What Is CLASS? . Intro duc ing DIV . Intro duc ing SPAN Fro m Here . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
263 264 265 265 266 266 267 268 269 271 271 273
. . . . . . . . . 275 . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
275 276 277 278
Chapter 24: Testing and Validating Your HTM L . . . . . . . . . . . . . 279 Watc h fo r These Co mmo n HTML Mistakes Testing Yo ur HTML . . . . . . . . . . . . . . Why Yo u Sho uld Validate . . . . . . . . . . What is validating? . . . . . . . . . . . Why validate? . . . . . . . . . . . . . . Validating Yo ur HTML . . . . . . . . . . . . Validating Yo ur CSS . . . . . . . . . . . . . . Different ways o f validating yo ur CSS Assessing Usability . . . . . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
Part IV: Enhancing Presentation with Cascading Style Sheets
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
279 280 281 281 281 282 283 284 284 285
287
Chapter 25: Introducing Cascading Style Sheets . . . . . . . . . . . . 289 Why Style Sheets Are Needed . . . . . . . . . . . . . . . . . . . . . . . . . . 289 What Style Sheets Can Do . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 Gro uping elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
xxv
xxvi
Contents
Site fac e-lift . . . . . . . . Delegating page assembly The Casc ading Mo del . . . . . . Style Sheet Examples . . . . . . Bro wser Co mpatibility Issues . Fro m Here . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . witho ut sac rific ing design c o ntro l . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
291 291 291 292 295 295
Chapter 26: Learning CSS Syntax . . . . . . . . . . . . . . . . . . . . . 297 Anato my o f a Style Sheet . . . . . . . . . . . Differenc es Between CSS and HTML Syntax Defining Pro perties . . . . . . . . . . . . . . Gro uping Pro perties . . . . . . . . . . . . . Pro perty Definitio n Sho rtc uts . . . . . . . . Bo x Fo rmatting: The CSS Fo rmatting Mo del Bo x dimensio ns . . . . . . . . . . . . . Padding . . . . . . . . . . . . . . . . . Bo rder . . . . . . . . . . . . . . . . . . Margins . . . . . . . . . . . . . . . . . Understanding Inheritanc e . . . . . . . . . Defining Classes . . . . . . . . . . . . . . . . Pseudo -Classes . . . . . . . . . . . . . . . . Defining IDs . . . . . . . . . . . . . . . . . . Gro uping Elements with DIV and SPAN . . Co mments in Style Sheets . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
297 298 299 300 301 301 301 302 303 304 304 305 305 306 306 307 307
Chapter 27: Adding Styles to Your Web Pages . . . . . . . . . . . . . 309 Using an External Style Sheet . . . . . . . Using a STYLE Element within the HEAD Adding Inline Styles . . . . . . . . . . . . . Using a Standardized Style Sheet . . . . . Mixing the Appro ac hes: An Example . . . Fro m Here . . . . . . . . . . . . . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
309 310 312 312 315 317
Chapter 28: Adding Colors and Backgrounds . . . . . . . . . . . . . . 319 Ho w Yo ur Mo nito r Creates Co lo r . . Intro duc ing Co lo r Co des . . . . . . . Using English . . . . . . . . . . Mo nito r-to -mo nito r variatio ns Co lo r Palettes . . . . . . . . . . . . . Co lo r-Co mpatibility Co nsideratio ns Defining a Bac kgro und Co lo r . . . . Changing Default Text Co lo rs . . . . Adding a Bac kgro und Graphic . . . Fro m Here . . . . . . . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
319 320 320 321 321 322 322 323 323 325
Contents
Chapter 29: Formatting Paragraphs . . . . . . . . . . . . . . . . . . . 327 Reviewing the CSS Bo x Fo rmatting Mo del Padding summary . . . . . . . . . . Margins summary . . . . . . . . . . Units o f length . . . . . . . . . . . . Adding Indentatio ns . . . . . . . . . . . . Co ntro lling Alignment . . . . . . . . . . . Cho o sing Line Height . . . . . . . . . . . . Co ntro lling Lists with Styles . . . . . . . . List style type . . . . . . . . . . . . . List style image . . . . . . . . . . . . List style po sitio n . . . . . . . . . . List style sho rthand . . . . . . . . . Adding Bo rders . . . . . . . . . . . . . . . Bo rder width . . . . . . . . . . . . . Bo rder c o lo r . . . . . . . . . . . . . Bo rder style . . . . . . . . . . . . . . Sho rthand tec hniques . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
327 328 328 329 329 329 330 330 330 331 331 332 332 332 333 333 334 334
Chapter 30: Formatting Tables . . . . . . . . . . . . . . . . . . . . . . 337 Co ntro lling Table Alignment . . . . . . . . . . Setting Ho rizo ntal Cell Alignment . . . . . . . At the c ell level . . . . . . . . . . . . . . At the ro w level . . . . . . . . . . . . . . At the c o lumn level . . . . . . . . . . . At the ro w gro up level o r c o lumn gro up Setting Vertic al Cell Alignment . . . . . . . . Spec ifying Table and Cell Widths . . . . . . . Abso lute values . . . . . . . . . . . . . . Relative values . . . . . . . . . . . . . . Spec ifying width in style sheets . . . . Adding Cell Spac ing . . . . . . . . . . . . . . . Defining Cell Padding . . . . . . . . . . . . . . Using Co lo rs in Tables . . . . . . . . . . . . . Defining Rules and Bo rders . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
337 338 338 339 340 341 341 342 342 343 343 344 345 346 346 347
Chapter 31: Adding Fonts . . . . . . . . . . . . . . . . . . . . . . . . . 349 Intro duc ing Fo nts . . . . . . . . . . . . Fo nt families . . . . . . . . . . . Fo nts versus the image o f fo nts Using Lo c al Fo nts . . . . . . . . . . . . Fo nt-Selec tio n Co nsideratio ns . . . . The aesthetic s o f fo nt selec tio n Availability o f lo c al fo nts . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
349 349 351 351 351 352 352
xxvii
xxviii
Contents
Co ntro lling Fo nt Selec tio n . . . . . . . . . . . . Cho o sing Fo nt Sizes . . . . . . . . . . . . . . . Using Co ndensed and Expanded Fo nts . . . . Co ndensing and expanding ho rizo ntally Co ndensing and expanding vertic ally . . Adding Small Caps and Other Dec o ratio ns . . Changing the first line . . . . . . . . . . . Changing the first letter . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
Part V: Lay It Out Like the Pros
. . . . . . . . .
352 353 353 354 355 355 356 356 357
359
Chapter 32: Essentials of Web Page Design . . . . . . . . . . . . . . 361 What’s in a Page? . . . . . . . . . . . . . . . . Fo c using o n Yo ur Message . . . . . . . . . . . Keeping it to the po int (yo ur left brain) Go with the feeling (yo ur right brain) . When to ask fo r help . . . . . . . . . . . Lead me no t into temptatio n . . . . . . The Shell Game . . . . . . . . . . . . . . . . . Co nsistenc y . . . . . . . . . . . . . . . . . . . Predic tability . . . . . . . . . . . . . . . . . . Navigability . . . . . . . . . . . . . . . . . . . Navigatio n bar o r navigatio n butto ns . Table o f c o ntents . . . . . . . . . . . . . Site map . . . . . . . . . . . . . . . . . . Site searc h . . . . . . . . . . . . . . . . . Site dro p-do wn list . . . . . . . . . . . . Visual Appeal . . . . . . . . . . . . . . . . . . Interac tivity . . . . . . . . . . . . . . . . . . . Speed . . . . . . . . . . . . . . . . . . . . . . . Design Guidelines . . . . . . . . . . . . . . . . Effec tive Use o f White Spac e . . . . . . . . . Optimum Page Length . . . . . . . . . . . . . Future Expandability . . . . . . . . . . . . . . Designing an Effec tive Welc o me Page . . . . Splash Sc reens . . . . . . . . . . . . . . . . . Testing . . . . . . . . . . . . . . . . . . . . . . The Myth o f Co mpleteness . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
361 362 362 363 364 364 365 367 368 368 368 370 371 372 372 373 373 373 374 378 378 379 379 379 379 380 380
Chapter 33: Understanding CSS Positioning Options . . . . . . . . . 381 The display Pro perty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381 The flo at Pro perty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 The c lear Pro perty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
Contents
The po sitio n Pro perty . . . . . . . . . . . . . . The z-index Pro perty . . . . . . . . . . . . . . . Understanding Relative Po sitio ning . . . . . . Understanding Abso lute Po sitio ning . . . . . . Co mbining Relative and Abso lute Po sitio ning Fro m Here . . . . . . . . . . . . . . . . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
388 389 389 390 390 390
Chapter 34: Positioning Graphics and Text . . . . . . . . . . . . . . . 391 Spec ifying Image Lo c atio n . . . . . . . . . . . . Using frames . . . . . . . . . . . . . . . . Using CSS with abso lute po sitio ning . . . Using CSS with relative po sitio ning . . . Using CSS to flo at the image . . . . . . . Defining Text Po sitio ns . . . . . . . . . . . . . . Changing the BODY element . . . . . . . Po sitio ning text with relative po sitio ning Flo ating an Image Next to Text . . . . . . . . . Flo ating bo th the text and the image . . Flo ating o nly the text . . . . . . . . . . . The o rder o f the HTML matters . . . . . Fro m Here . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
391 391 392 392 394 395 396 396 397 398 399 399 402
Chapter 35: Cool CSS Positioning Tips and Tricks . . . . . . . . . . . 403 Creating Co lumns o f Text . . . . . Superimpo sing Text and Graphic s Creating Pull Quo tes . . . . . . . . Fro m Here . . . . . . . . . . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
403 405 407 409
Chapter 36: Structuring M ultipage Sites . . . . . . . . . . . . . . . . . 411 Po ssibilities and Pro blems o f Multipage Sites . . . . The Pro s o f multipage sites fo r yo ur visito rs . The Co ns o f multipage sites fo r yo ur visito rs The Pro s o f develo ping a multipage site . . . The Co ns o f develo ping a multipage site . . . Dividing the Site . . . . . . . . . . . . . . . . . . . . . By o riginatio n o f c o ntent . . . . . . . . . . . . By type o f c o ntent . . . . . . . . . . . . . . . . By visito r type . . . . . . . . . . . . . . . . . . Dividing Co ntent . . . . . . . . . . . . . . . . . . . . Site Arc hitec ture . . . . . . . . . . . . . . . . . . . . Linear arc hitec ture: The fo rc ed marc h . . . . Hierarc hic al arc hitec ture . . . . . . . . . . . . Avo id extreme devo tio n to hierarc hy . . . . . Anarc hy . . . . . . . . . . . . . . . . . . . . . . A seamless web . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
411 412 412 414 414 414 415 416 417 419 421 422 423 423 424 424
xxix
xxx
Contents
Pro viding Navigatio nal Aids . . . . . . . . . Maintaining a Multipage Site . . . . . . . . Bo nus: Maintaining a Really Large Web Site Fro m Here . . . . . . . . . . . . . . . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
Part VI: Adding Sensory Excitement and Interactivity
. . . .
425 426 428 429
431
Chapter 37: Creating Still Graphics for the Web . . . . . . . . . . . . 433 Understanding Graphic s File Fo rmats Why c o mpressio n? . . . . . . . . Co mpressio n o ptio ns . . . . . . Understanding Co lo r Depth . . . . . . Enhanc ing Do wnlo ading Speed . . . . Image file sizes . . . . . . . . . . Number o f images . . . . . . . . Reuse images . . . . . . . . . . . Use frames . . . . . . . . . . . . Use text rather than images . . . Creating Graphic s . . . . . . . . . . . . Essential func tio ns . . . . . . . . Free alternatives . . . . . . . . . Capturing Graphic s . . . . . . . . . . . Pro gressive JPEGs and Interlac ed GIFs Using Transparent GIFs . . . . . . . . Fro m Here . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
433 433 436 437 438 438 439 439 440 440 440 440 441 442 442 443 444
Chapter 38: Creating Animated Graphics for the Web . . . . . . . . 445 Intro duc ing Animated GIFs . . . . . . . . Planning Yo ur Animatio n . . . . . . . . . . Creating the Animatio n . . . . . . . . . . . Using a GIF Animatio n Edito r . . . . . . . Inc luding an Animated GIF o n Yo ur Page Testing Yo ur Animatio n . . . . . . . . . . Mo re Animatio n Optio ns . . . . . . . . . . Sho c kwave/ Flash . . . . . . . . . . . Mo vies . . . . . . . . . . . . . . . . . Java applets . . . . . . . . . . . . . . Ac tiveX c o ntro ls . . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
445 446 448 448 450 450 450 450 451 451 451 451
Contents
Chapter 39: Designing and Implementing Imagemaps . . . . . . . . 453 Intro duc ing Imagemaps . . . . . . . . . . . Imagemap Design . . . . . . . . . . . . . . . Server-Side Versus Client-Side Imagemaps Develo ping Graphic s fo r Imagemaps . . . . Using an Imagemap Edito r . . . . . . . . . . The MAP Element . . . . . . . . . . . . . . . The AREA Element . . . . . . . . . . . . . . The Anato my o f an Imagemap . . . . . . . . Adding Alternate Text . . . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
453 454 455 455 456 457 457 458 458 458
Chapter 40: Producing and Adding Sounds . . . . . . . . . . . . . . . 461 Understanding Digital Audio . . . . . Rec o rding equipment . . . . . . Rec o rding bit-depth . . . . . . . Sample rate . . . . . . . . . . . . Mo no versus stereo . . . . . . . Playbac k equipment . . . . . . . Intro duc ing So und File Fo rmats . . . . Intro duc ing Streaming Audio . . . . . Obtaining So und Files . . . . . . . . . Rec o rding So und Files . . . . . . . . . Editing So und Files and Adding Filters Co mpressing So und Files . . . . . . . Adding So und Files to Yo ur Page . . . Inline so und . . . . . . . . . . . . Out-o f-line so und . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
461 462 462 462 463 463 463 464 465 465 466 466 467 467 468 468
Chapter 41: Producing and Adding Video . . . . . . . . . . . . . . . . 471 Intro duc tio n to Digital Video . Expec tatio ns . . . . . . . Garbage in, garbage o ut . The Anato my o f Digital Video . Frame rate . . . . . . . . . Frame size . . . . . . . . . Intro duc ing Video File Fo rmats Intro duc ing Streaming Video . Video Co mpressio n Sc hemes . Capturing Analo g Video . . . . Editing Digital Video . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
471 472 472 472 473 473 473 474 474 474 475
xxxi
xxxii
Contents
Adding Video Files to Yo ur Page Inline mo vies . . . . . . . . Out-o f-line mo vies . . . . . Invaluable Reso urc es . . . . . . . Fro m Here . . . . . . . . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
477 477 477 477 477
Chapter 42: Incorporating Plug-Ins and ActiveX Controls . . . . . . 479 Reviewing the OBJECT Element . . . . . . . Ho w Plug-Ins Wo rk . . . . . . . . . . . . . . Plug-In Pluses and Minuses . . . . . . . . . Adding Plug-Ins . . . . . . . . . . . . . . . . 3D and animatio n plug-ins . . . . . . . Audio and video plug-ins . . . . . . . Disc ipline-spec ific plug-ins . . . . . . Business plug-ins . . . . . . . . . . . . Testing Yo ur Plug-In . . . . . . . . . . . . . Co nfiguring Yo ur Server . . . . . . . . . . . Intro duc ing Ac tiveX . . . . . . . . . . . . . Ac tiveX Pluses and Minuses . . . . . . . . . Understanding the Ac tiveX Sec urity Mo del Finding Ac tiveX Co ntro ls . . . . . . . . . . . Inc o rpo rating Ac tiveX Co ntro ls . . . . . . . Defining Optio ns (Parameters) . . . . . . . Getting Aro und the Mac Pro blem . . . . . . Testing Yo ur Co ntro l . . . . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
479 480 482 482 483 484 485 485 486 487 487 488 489 489 490 491 491 492 492
Chapter 43: Adding Java Applets . . . . . . . . . . . . . . . . . . . . . 495 Intro duc ing Java . . . . . . . . . . . . . Java Pluses and Minuses . . . . . . . . . The Java virtual mac hine . . . . . The Just-In-Time c o mpiler . . . . Understanding the Java Sec urity Mo del Java Develo pment To o ls . . . . . . . . . Inc o rpo rating Java Applets . . . . . . . Defining Optio ns (Parameters) . . . . . Testing Yo ur Applet . . . . . . . . . . . . Intro duc ing Server-Side Java . . . . . . Fro m Here . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
495 496 496 497 497 498 500 500 501 501 501
Chapter 44: Creating Subscriptions with the Channel Definition Format . . . . . . . . . . . . . . . . . 503 Intro duc ing Push Optio ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503 No thing new . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504 Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
Contents
Marketing with Push . . . . . . . . . . . Intro duc ing Channel Definitio n Fo rmat CDF (XML) syntax . . . . . . . . . Images . . . . . . . . . . . . . . . . Items . . . . . . . . . . . . . . . . . Subsc ribing to a Channel . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
505 505 506 506 508 508 509
Chapter 45: Accessing External Databases . . . . . . . . . . . . . . . 511 Understanding Databases . . . . . . . . . . . . . . . . . . . Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . Relatio nships . . . . . . . . . . . . . . . . . . . . . . . Co mmo n databases . . . . . . . . . . . . . . . . . . . ODBC . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Web-to -Database Interfac e . . . . . . . . . . . . . . . . Requesting data . . . . . . . . . . . . . . . . . . . . . Co mmunic ating with the database . . . . . . . . . . . Returning results . . . . . . . . . . . . . . . . . . . . . Co nc lusio ns fro m the Web-to -database interac tio n . Optio ns fo r Ac c essing Database Data . . . . . . . . . . . . Three stand-alo ne c o mpo nents . . . . . . . . . . . . Dual-purpo se Web server and stand-alo ne database Stand-alo ne Web server and dual-purpo se database External Database Ac c ess witho ut Pro gramming . . . . . . External Database Ac c ess with SQL . . . . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
511 511 512 512 512 512 513 513 514 515 515 515 516 516 517 517 517 518
Chapter 46: Building a Community: Incorporating Discussion Groups and Chat . . . . . . . 519 Intro duc ing Threaded Disc ussio n Gro ups and Chat Applic atio ns o f threaded disc ussio n gro ups . Applic atio ns o f c hat ro o ms . . . . . . . . . . . Adding Threaded Disc ussio n Gro ups to a Web Page Adding Chat to a Web Page . . . . . . . . . . . . . . Text c hat . . . . . . . . . . . . . . . . . . . . . Visual c hat . . . . . . . . . . . . . . . . . . . . Creating Co mmunity . . . . . . . . . . . . . . . . . . What c an yo u o ffer? . . . . . . . . . . . . . . . A big-name c o lumnist . . . . . . . . . . . . . . Talk with a pro fessio nal . . . . . . . . . . . . . Beyo nd Chat and Threaded Disc ussio n Gro ups . . Fro m Here . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
519 520 520 521 521 521 522 522 522 523 523 523 524
xxxiii
xxxiv
Contents
Part VII: Using Cross-Browser Dynamic HTM L
525
Chapter 47: Introducing Dynamic HTM L and the Document Object M odel . . . . . . . . . . . . . . . . . 527 What Is Dynamic HTML? . . . . . . . . . . . . . . . . . Fo undatio n fo r Change: The Do c ument Objec t Mo del Ho w is the DOM implemented? . . . . . . . . . . Cro ss-bro wser c o mpatibility and the DOM . . . The struc ture o f the DOM . . . . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
528 531 532 533 533 536
Chapter 48: Cross-Browser Basics with JavaScript . . . . . . . . . . 539 JavaSc ript: The Dynamic in DHTML . . . . . . Adding sc ripts with the SCRIPT element JavaSc ript exec utio n . . . . . . . . . . . . Event handling in JavaSc ript . . . . . . . Pro perties, metho ds, and func tio ns . . . Passing data fro m the page to the sc ript Testing and debugging JavaSc ript . . . . Cro ss-Bro wser JavaSc ript . . . . . . . . . . . . Surveying the Bro wser Enviro nment . . . . . . Objec t detec tio n in JavaSc ript . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
539 541 542 544 547 549 551 552 552 555 556
Chapter 49: Frames, Layers, and the Shell Game . . . . . . . . . . . 557 Defining Hidden Text . . . . . . . . . . . . . . . . Bringing hidden text into view . . . . . . . Designing an interac tive table o f c o ntents Dynamic ally mo difying styles . . . . . . . . The sc ript . . . . . . . . . . . . . . . . . . . Mo ving Layers . . . . . . . . . . . . . . . . . . . . Creating c ro ss-bro wser HTML . . . . . . . DOM o bjec t detec tio n . . . . . . . . . . . . Setting the initial po sitio n . . . . . . . . . . Mo ving the o bjec t . . . . . . . . . . . . . . Fro m Here . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
557 558 558 561 562 563 565 566 566 567 569
Chapter 50: Doing Windows with JavaScript . . . . . . . . . . . . . . 571 What’s a Windo w? . . . . Windo w Wo rkings . . . . . Opening Windo ws . . . . . Spec ial-Purpo se Windo ws Windo ws by remo te Clo sing windo ws . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
571 572 573 574 576 577
Contents
Appendix A: HTML 4 Data Types . . . . . . . . . . . . . . . . . . . . . . . 579 Appendix B: HTML 4 Elem ents Reference . . . . . . . . . . . . . . . . . 583 Appendix C: HTML 4 Attributes Reference . . . . . . . . . . . . . . . . . 653 Appendix D: HTML 4 Character Entities Reference . . . . . . . . . . . . 665 Appendix E: Cascading Style Sheets Reference . . . . . . . . . . . . . . 669 Appendix F: Language Codes Reference . . . . . . . . . . . . . . . . . . 713 Appendix G: Hex Notations Reference . . . . . . . . . . . . . . . . . . . 719 Appendix H: About the CD-ROM . . . . . . . . . . . . . . . . . . . . . . . 723
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725 End-User License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 744 CD-Rom Installation Instructions . . . . . . . . . . . . . . . . . . . . . . . 750
xxxv
Introduction
S
ho rt fo r HyperText Markup Language, HTML is o ne o f many markup languages that have appeared in rec ent years. In brief, a markup language pro vides guidelines fo r adding markup — in the fo rm o f spec ial symbo ls — to text do c uments. These symbo ls desc ribe the parts o f the do c ument. Fo r example, yo u c an use a markup language to identify a po rtio n o f the text as an abstract, a brief summary o f the do c ument’s c o ntents. HTML is a markup language designed fo r Internet do c uments.
Introducing markup languages Markup is needed bec ause c o mputers are quite stupid when it c o mes to understanding text. A c o mputer c an’t really tell whether a c ertain po rtio n o f a text is an abstrac t, a title, a heading, o r a paragraph. Witho ut so me kind o f additio nal c o ding, the c o mputer do esn’t kno w ho w to display the text so that it lo o ks like an ac tual do c ument. Wo rd pro c essing pro grams pro vide the nec essary c o ding by means o f pro prietary fo rmatting c o des, but these have a gigantic do wnside: They wo rk o nly if yo u’re lo o king at the do c ument using the same wo rd pro c essing pro gram and type o f c o mputer that c reated it. If yo u ever tried to exc hange a Wo rdPerfec t file with a Mac into sh MS Wo rd user, yo u c an understand the diffic ulties invo lved. Markup languages so lve the file-c o mpatibility pro blem by using no thing but ASCII (plain text) c harac ters and, what’s mo re, by breaking the c o nnec tio n between struc tural markup and presentatio n. In struc tural markup, yo u identify the parts o f a do c ument — in effec t, yo u say this is a title o r this is a he ading — but yo u say no thing abo ut ho w this part o f the do c ument sho uld be presented using spec ific fo rmatting (fo nts, alignment, and so o n). Yo u mark up the do c ument’s struc ture by identifying the do c ument’s parts (title, abstrac t, headings, paragraphs, lists, and so o n). But there’s mo re. Pre se ntatio n — ho w the do c ument is fo rmatted fo r display o r printing — is left entirely up to a bro wse r, a pro gram designed to read the markedup do c ument fo r display o n a spec ific type o f c o mputer hardware. The distinc tio n between struc ture and presentatio n is impo rtant, fo r in it lies the key to a markup language’s c apability to wo rk smo o thly in a c ro ss-platfo rm enviro nment (a c o mputer netwo rk in whic h peo ple are using many different types o f c o m-
xxxviii
Contents
puters). With a markup language, yo u c an c reate just o ne versio n o f a do c ument. Peo ple c an run bro wsers designed to func tio n o n Mac into shes, UNIX c o mputers, and all the vario us versio ns o f Windo ws (3.1, 95, 98, NT, and 2000), and they c an display yo ur do c ument with abso lutely no tro uble. Fo r eac h o f these c o mputers, a bro wser kno ws ho w to display the marked-up do c ument o n a given system. Do es a do wnside exist to markup languages? Yes. If yo u do pure struc tural markup, with no presentatio n at all, yo u give up c o ntro l o ver ho w yo ur do c ument appears. On o ne system, it may appear with blac k Times Ro man text — but, o n ano ther, so me c razy user may have set up his o r her bro wser to display yo ur text in 28-po int Demented Bo ld. And there’s no thing yo u c an do to sto p this user.
HTM L —a hypertext markup language HTML is a markup language with all the advantages o f o ther markup languages when it c o mes to separating struc ture fro m presentatio n. But HTML has so mething mo re: HTML is a hypertext markup language. What’s hypertext? In brief, hype rte xt is a way o f o rganizing info rmatio n so readers c an c ho o se their o wn path thro ugh the material. Instead o f c lic king thro ugh sequentially o rganized pages, a hypertext user c lic ks spec ially highlighted text, c alled a hype rlink (o r just a link fo r sho rt), to go direc tly to info rmatio n o f interest. There’s mo re to say abo ut hypertext but, fo r no w, the impo rtant po int is this: HTML is the first markup language to inc o rpo rate markup fo r hyperlinks. When yo u mark up a do c ument with HTML, yo u c an define so me o f the text as a link, within whic h yo u embed the c o mputer address o f ano ther reso urc e o n the Internet. This c o uld be a do c ument, a mo vie, a so und, an animatio n, o r a file to do wnlo ad.
Eroding the structure/ presentation distinction As yo u just learned, the who le purpo se o f a markup language lies in separating struc ture fro m presentatio n and, in so do ing, enabling c o ntent develo pers to c reate do c uments that c an be displayed faultlessly o n any type o f c o mputer. But this distinc tio n hasn’t fared well. By the time HTML go t to Versio n 3.2, it had been serio usly ero ded. Why did this ero sio n o c c ur? The reaso n lies in the Web’s rapid c o mmerc ializatio n. Ac tually, HTML was initially designed to enable physic s researc hers to make their preliminary papers available to o ther physic s researc hers, and the humdrum appearanc e o f plain-vanilla HTML wasn’t an issue. As the Web migrated to the private sec to r and bec ame an impo rtant way fo r giant c o rpo ratio ns to get their message o ut, Web develo pers c o uldn’t igno re presentatio n anymo re. They needed to emulate the page layo ut designs o f pro fessio nal newsletter and magazine designers. They didn’t like the idea o f a pure markup language, whic h wo uld let so meo ne display Americ a, Inc .’s pages using 28-po int Demented Bo ld fo nt.
Contents
So what did Web develo pers do ? They learned a who le series o f tric ks to fake layo ut. Fo r example, they used tables — initially designed to gro up data in tabular fo rm — to emulate newspaper c o lumns and magazine layo uts. Bro wser publishers, inc luding bo th Netsc ape and Mic ro so ft, tried to expand their market share by c reating bro wsers that suppo rt e xte nsio ns, no nstandard additio ns to HTML that pro vide presentatio n c apabilities. (The mo st egregio us o f these is pro bably Netsc ape’s no to rio us blink extensio n, whic h enables Web autho rs to c reate text that blinks away anno yingly while yo u’re trying to read the page.) What’s the result o f HTML’s c o mmerc ializatio n? In brief, a mess. Yo u c an use the tric ks and extensio ns to fake presentatio n with a Web page, but ho w it’s go ing to lo o k o n a given c o mputer and mo nito r is anyo ne’s guess. HTML pages are c rammed with HTML c o de that’s been elabo rated to a ridic ulo us extent to emulate magazine layo uts, but editing and maintaining these pages is a c o stly nightmare. To c o rrec t erro rs in the text, yo u have to pic k thro ugh reams o f messy c o de. And suppo se yo u c reate a who le series o f pages, but later find they lo o k terrible when displayed o n a Mac into sh. Yo u’d have to go bac k into eac h page and c hange the o ffending c o de. In sho rt, the ero sio n o f the struc ture versus presentatio n distinc tio n has serio usly damaged HTML’s underlying purpo se. What’s wo rse, it’s slo wing do wn the Web’s develo pment. To be sure, c reating a simple page is easier. But the c o st o f c reating and maintaining HTML that generates pro fessio nal-lo o king results is so pro hibitive, many wo uld-be c o ntent pro viders are shying away — a bad sc ene!
HTM L 4 and the HTM L 4 Way Realizing that so mething drastic had to be do ne to resc ue HTML, the Wo rld Wide We b Co nso rtium (W3C) — the no npro fit, standards-setting bo dy respo nsible fo r HTML — has published a spec ific atio n fo r a new versio n o f HTML, Versio n 4.01. Altho ugh HTML 4.01 is do wnwardly c o mpatible with previo us versio ns o f HTML, the new versio n is designed to resto re the lo st balanc e between struc ture and presentatio n. What’s mo re, it do es so in a way that gives Web-c o ntent develo pers prec isely what they want: to tal c o ntro l o ver do c ument layo ut. The sec ret? Casc ading style sheets (CSS).
Introducing cascading style sheets The W3C-o riginated c asc ading style sheets (CSS) spec ific atio n is a dream c o me true fo r Web-c o ntent develo pers. To understand why it’s suc h a big deal, think abo ut wo rd pro c essing. The earliest wo rd pro c esso rs gave yo u fo rmatting c o mmands, but made yo u use them o ver and o ver. Fo r example, suppo se yo u wanted to fo rmat a paragraph with a first-line indent, do uble line spac ing, and Times Ro man text. With early pro grams,
xxxix
xl
Contents
yo u had to apply three different fo rmatting c o mmands to every paragraph yo u typed. What a hassle! Then alo ng c ame Mic ro so ft Wo rd. Wo rd enabled yo u to define a named style. Yo u c o uld c reate a style c alled Bo dy Text, and then define this style with all the fo rmats yo u want. Yo u then apply this style to any paragraph yo u type. When yo u apply the style, Bingo ! Yo u get all the fo rmats yo u assigned to the style. Onc e yo u’ve tried this, yo u c an never go bac k — and that’s o ne reaso n Mic ro so ft Wo rd has an o verwhelming market share in the wo rd-pro c essing wo rld.
Harnessing the power of styles Casc ading style sheets bring the po wer o f styles to HTML and the Web. Using CSS, yo u define styles, whic h tell Web bro wsers ho w to display the text yo u marked up with HTML. Suppo se, fo r example, yo u marked up so me o f the text as a heading. With CSS, yo u c an define the heading so it appears with the fo llo wing fo rmats: c entered, 12 po ints abo ve and belo w, 14-po int Helvetic a, and bo ld. The marked-up text is c lean, struc ture-o nly HTML — no go bbledygo o k designed to hassle HTML into a presentatio n language. And what’s mo re, yo u get all the benefits o f styles. Make o ne c hange to the underlying style definitio n and yo u c hange every instanc e o f text to whic h the style is assigned. Even mo re po werfully, yo u c an use external style sheets, whic h define the styles appearing in do zens o r even tho usands o f do c uments. One little c hange to the underlying style and all the linked do c uments are c hanged, to o . CSS is easy to learn, easy to use, and — o nc e yo u grasp what CSS c an do — to tally indispensable. And the benefits are amazing. By remo ving the presentatio n fro m HTML, yo u let HTML do what it do es best — namely, define struc ture. Yo ur HTML will be c leaner, muc h mo re readable, and muc h easier to edit. What’s mo re, CSS do es a far better jo b o f presentatio n than HTML ever c o uld. Fo r example, the latest versio n o f CSS enables abso lute po sitio ning, in whic h yo u c an nail do wn the prec ise lo c atio n o f text o r graphic s o n the page. Yo u c an c reate newspaper-c o lumn effec ts, and even superimpo se text o n graphic s.
What about the structure versus presentation distinction? Wait a minute! Do esn’t CSS vio late the struc ture versus presentatio n distinc tio n? In so me ways, yes. Admittedly, it’s a c o mpro mise, but an elegant c o mpro mise. The CSS autho rs rec o gnized Web develo pers wanted and needed to c o ntro l their do c uments’ presentatio n aspec ts. But they wanted to give autho rs presentatio n c o ntro l witho ut harming the basic benefit o f a markup language, namely, the ability to c reate do c uments that func tio n well in a c ro ss-platfo rm enviro nment. CSS do es enable yo u to define presentatio n — in fac t, that’s its po int. With CSS, yo u c an, indeed, define presentatio n aspec ts suc h as fo nts, and a CSS-c o mpatible
Contents
bro wser respec ts yo ur c ho ic e. The guy who wants to lo o k at yo ur page with 28-po int Demented Bo ld sees yo ur Times Ro man instead. Unlike a wo rd pro c esso r’s fo rmatting c o des, tho ugh, CSS do esn’t lo c k users into a rigid straightjac ket. If Times Ro man isn’t available, the bro wser lo o ks fo r fo nts yo u listed as likely alternates. And, if these aren’t available, the bro wser defaults to a fallbac k fo nt. All this is to tally auto matic , so no o ne is prevented fro m reading yo ur page. In sho rt, CSS pulls o ff so mething wo rd pro c essing pro grams c an’t: CSS c reates ric hly fo rmatted do c uments that are easily exc hanged and used in a c ro ss-platfo rm enviro nment. What’s mo re, CSS enables yo u to mo ve the presentatio n o ut o f HTML. To be sure, yo u c an inc lude CSS style spec ific atio ns within yo ur HTML, but this bo o k do esn’t rec o mmend this prac tic e. It’s muc h better to mo ve the style spec ific atio ns o ut o f the HTML entirely, either in a gro uped style spec ific atio n within the do c ument’s header o r (better yet) in a separate file. With the presentatio n c o de o ut o f the way, yo u c an write pure, struc ture-o nly HTML. And this is prec isely the c o ntro lling theme o f the HTML 4 revisio n.
Back to pure structure with HTM L 4 Altho ugh HTML 4 suppo rts the vario us presentatio n features and extensio ns sho eho rned into previo us versio ns o f HTML, this new versio n’s real signific anc e lies in its reassertio n o f pure struc ture. By mo ving the presentatio n to CSS, yo ur HTML go es bac k to what it sho uld be: c lean, easy to read, inexpensive to maintain, quic k to pro c ess and display, and — mo st o f all — ideal fo r a c ro ss-platfo rm enviro nment.
The HTM L 4 Way This bo o k teac hes an entirely new appro ac h to HTML, o ne yo u wo n’t find in c o mpeting bo o ks that explo re HTML as extensively as this o ne. It’s c alled the HTML 4 Way. The HTML 4 Way takes full advantage o f the exc iting new po ssibilities o f HTML and CSS, and c alls fo r learning bo th, fro m the beginning. That’s why this bo o k’s appro ac h is unique. Almo st all HTML bo o ks begin with HTML, teac h all tho se ho rrible presentatio n tric ks that have ac c umulated o ver the years, and then thro w in a c hapter o n CSS as an aftertho ught. No t so with this bo o k. As yo u’ll see, yo u begin by writing pure struc tural HTML, with abso lutely no presentatio n inc luded. Yo u then learn ho w to weave CSS into yo ur do c uments to o btain to tal, impressive c o ntro l o ver every aspec t o f yo ur do c uments’ presentatio n. Yo u pro duc e c o de that’s beautifully simple and c lear, easy and inexpensive to maintain, and abso lutely stunning o nsc reen.
xli
1
C H A P T E R
HTM L 4 Basics
W
hen yo u learn a language, yo u need to learn rules, c alled syntax . Unless yo u fo llo w these rules, yo ur statements do n’t have any meaning. Co nsider this statement, fo r instanc e: “Extra! Pizza, with a bring peppero ni me; c heese.” The wo rd o rder is o ut o f whac k and so is the punc tuatio n. Yo u c an say this to a waiter, but go o d luc k getting yo ur pizza! Like any language, HTML has syntax rules. Fo rtunately, they’re simple and easy to learn. Befo re yo u start trying to write HTML, yo u’ll be wise to spend a little time learning these rules. It do esn’t take lo ng and there’s a huge payo ff: Yo u’ll avo id c o nfusio n and find it muc h easier to trac k do wn yo ur erro rs. This c hapter intro duc es the basic building blo c ks o f HTML, inc luding elements, attributes, and entities. (Do n’t wo rry abo ut defining these terms right no w; that’s do ne in this c hapter.) Yo u also learn the basic s o f nesting tags and abo ut the basic , underlying struc ture o f every HTML do c ument. Onc e yo u learn these c o nc epts, yo u’re ready to starting writing HTML.
Introducing the Basic Building Blocks: Elements When yo u write yo ur HTML, yo u use e le me nts to define the struc ture o f the do c ument, to define the presentatio n o f yo ur do c ument, to define links to o ther do c uments, and to spec ify desired behavio r. Examples o f elements are: HEAD, BODY, P, BLOCKQUOTE, and UL. When yo u ac tually go to insert these elements into yo ur text, yo u surro und them with < (less than) and > (greater than) symbo ls, whic h are c o llec tively referred to as angle bracke ts. Onc e yo u have do ne this, yo u have , ,
, , and
, , and
No w, lo o k at a po ssible versio n o f navigational-tools.html, the file c o ntaining the navigatio n butto ns (in this c ase text) and the links. No tic e ho w the A element fo r eac h o f the links inc ludes a target attribute direc ting the results o f the link to lo ad into the main frame.
... TITLE and META elements here ...
267
268
Part III ✦ Developing Document Structure with HTM L 4
Products and Solutions Customer Service White Papers Job Postings
Yo u must start yo ur target names with letters. After that, yo u c an use any o f the regular, ac c eptable c harac ters. So me target names begin with undersc o re (_). These are the reserved target names HTML makes available to help yo u with yo ur frames. Using reserved names gives yo u a way to referenc e yo ur frames relatively. Even if yo u c hange the target names o f yo ur frames, the reserved names still wo rk.
✦ blank. This c auses the results o f the link to be lo aded into a new bro wser windo w. Unless the do c ument referred to by the src attribute is a master frame do c ument, the new page wo n’t use frames.
✦ self. This c auses the results o f the link to be lo aded into the same frame as the A element, whic h c reated the link. In the previo us example, yo u wo uld use the _self target fo r links yo u have within the main frame.
✦ parent. This c auses the results o f the link to be lo aded into the FRAMESET parent o f the c urrent frame. If there is no FRAMESET parent, the results o f the link are lo aded into the same frame.
✦ top. This c auses the results o f the link to be lo aded into the full bro wser windo w, c anc eling frames. When wo uld yo u want to use this? If yo u have a “bac k to ho me” link o n the bo tto m o f yo ur main sc reen, yo u’d want it to po int to the master frame do c ument with a target o f _to p. This way, yo u wo uldn’t end up with the pro blem o f unintentio nally nested frames.
Creating FRAM Es Finally, having to ld the bro wser ho w muc h spac e to allo c ate fo r eac h frame and having given eac h frame a name, yo u need to tell the bro wser what to put into eac h frame. Yo u do this with the FRAME element. Yo u’ve already seen the FRAME element at wo rk.
Frame Start Tag:
Required
Content:
Empty
End Tag:
Fo rbidden
Chapter 22 ✦ Creating Frames
Attributes:
id, class, title, style name: used to indic ate the name to be asso c iated with this frame (the target name) src: used to spec ify what sho uld initially be lo aded into this frame longdesc: spec ifies a link to a lo nger frame desc riptio n using the title attribute, and may be partic ularly useful fo r no nvisual user agents. frameborder: tells bro wser to draw a bo rder aro und this frame (1, the default value), o r no t to draw a bo rder (0); if the adjo ining frame has a framebo rder, it will appear between the unbo rdered frame and the bo rdered frame marginwidth: width o f margin in pixels (margin between frame c o ntents and bo rders o n sides) marginheight: height o f margin in pixels (margin between frame c o ntents and bo rders o n to p and bo tto m) noresize: Bo o lean attribute (meaning if yo u want to indic ate no resize, yo u just inc lude the attribute witho ut a value) that tells the bro wser this frame is no t resizable by the visito r scrolling: There are three values fo r this attribute: yes, no , and auto . Cho o se no if yo u kno w the c o ntents o f the frame will always fit into the frame (say yo u have c o lumn width and ro w height set in pixels to fit the image in the frame). Cho o se yes if yo u want there always to be a sc ro ll bar o n the side o f this frame. Cho o se auto if yo u want the bro wser o nly to display a sc ro ll bar if the c o ntent do esn’t fit into the frame.
Yo u must define a FRAME element fo r eac h frame yo u want to c reate. The FRAMESET element tells the bro wser ho w many frames and ho w muc h spac e to give them. The FRAME element names eac h frame and gives it an initial value. When defining FRAMEs, yo u c an spec ify URLs using either relative o r abso lute file names. Just as with any o ther referenc e element ( A o r IMG), yo u c an spec ify bo th lo c al and remo te file names. It is pro bably better to refer to lo c al file names with relative file names. Remo te file names require fully qualified URLs.
Enhancing Navigability Frames are a great way to ensure that visito rs always have navigatio nal to o ls right o n the sc reen where they c an see them. Right? No t nec essarily. One thing yo u sho uld be c autio us abo ut is c reating a page yo u plan to use o nly in the main frame, when a searc h engine might index it as a stand-alo ne page. Why is this a pro blem?
269
270
Part III ✦ Developing Document Structure with HTM L 4
Bec ause when visito rs c o me to that page fro m a searc h engine, they have no way to get to the rest o f yo ur site. Do es this mean yo u need to put navigatio nal to o ls o n every page? No t nec essarily. What yo u sho uld have o n every page is a link bac k to the fro nt page o f yo ur site. That link must have a target o f _to p to wo rk pro perly. If yo u do n’t inc lude a target o f _to p, yo u will have a pro blem with yo ur site self-nesting when anyo ne c lic ks that link if the main page is ac tually part o f the framed site. If yo ur site lo o ks like Figure 22-5, and so meo ne c lic ks the [Go to Home Page] link yo u rightly have at the bo tto m o f every page, but yo u fo rget the target=”_top” attribute-value pair in yo ur link, visito rs get the results sho wn in Figure 22-6.
Really Big Company Web Site
Products
M ain Page
Service
Welcome to the Really Big Company Web Site
Jobs
[Go to Home Page]
Figure 22-5: Your fram ed site
Really Big Company Web Site Products
Really Big Company Web Site
Service
Products
M ain Page
Jobs
Service
Welcome to the Really Big Company Web Site
Jobs
[Go to Home Page]
Figure 22-6: Your fram ed site w ith unintentional nesting
Chapter 22 ✦ Creating Frames
NOFRAM ES Yo u c an plac e o ne mo re element in yo ur FRAMESET element. This is the NOFRAMES element. The NOFRAMES element is o ne yo u sho uld inc lude in the o utermo st FRAMESET, after yo u have defined all yo ur o ther FRAMESETs and FRAMEs. NOFRAMES c o ntains the page yo u want yo ur visito rs to get if their bro wsers do n’t suppo rt frames, o r if their bro wsers suppo rt frames but are c o nfigured no t to display frames. It c o uld be as simple as a message telling them to upgrade their bro wsers o r enable frames to see yo ur site pro perly. Note
If you do use the NOFRAMES elem ent, and you should, be sure the text you include is som ething you w ouldn’t m ind seeing on a Search Engine Results page. Search engines are notorious for using this text as your synopsis w hen indexing a site. This w on’t help attract visitors to your site.
Over the Web provides robust, turn-key modules for your professional Web site. The Over the Web site is only accessible with a frames-capable browser. Please upgrade your browser at one of the following locations:
This is the first sentence of this simple example. Here is the first supporting sentence. This is the second supporting sentence.
This is the next paragraph. It’s not introductory so it doesn’t use the class.
You can apply styles to a single paragraph. This paragraph displays with red lettering on a black background. The font is 14-point Helvetica. It gets its style attributes from the declarations after STYLE=.
To start another paragraph of the same style without using a class you need to repeat all of the declarations.
This paragraph appears in yellow lettering on a black background. The font is 14-point Helvetica.
This text is also inside of the DIV block, so it displays in yellow on black 14-point Helvetica too. and This is a first-class paragraph. This is a second-class paragraph. This is a paragraph of widely spaced text. This is one very important paragraph. This is another important paragraph. This is somewhat important. And this is really incidental. But you might want to remember this fact. This paragraph has a one inch indentation--twice the normal paragraph indentation-on the first line and is rendered with blue text. This paragraph has a one inch indentation-twice the normal paragraph indentation--on the first line and is rendered with blue text. This paragraph looks just the way they want it to look. But I sure wish I could make this one look different. This paragraph looks just the way they want it to look. I’m so pleased that I can make this one look different. This paragraph looks just the way they want it to look. I’m so pleased that I can make this one look different. This paragraph looks just the way they want it to look. I’m so pleased that I can make this one look different. This paragraph contains some rather widelyspaced text. This paragraph is normal, but you can link to weird stuff from here. In Chicago today, it was announced that people with more money live in nicer neighborhoods. In Chicago today, it was announced that people with more money live in nicer neighborhoods. No elements have a default value of run-in. Setting the display value of an element to run-in has the effect you see in this example. It is common to want to have images appear on the same line as your text. In this example, the float property of the IMG class icon is set to “left” to achieve this effect. More text is required in this example so that you can see that the text continues to wrap around the image. This is that additional text that is required. By now, the example should have enough text to make the point. Just in case, another sentence will provide additional text for purposes of making this point. This will be the last sentence. OK, maybe just one more, but I mean it this time. It is common to want to have images appear on the same line as your text. In this example, the float property of the IMG class icon is set to “left” to achieve this effect. More text is required in this example so that you can see that the text continues to wrap around the image. This is that additional text that is required. By now, the example should have enough text to make the point. Just in case, another sentence will provide additional text for purposes of making this point. This will be the last sentence. OK, maybe just one more, but I mean it this time. No elements have a default value of run-in. Setting the display value of an element to run-in has the effect you see in this example. It is common to want to have images appear on the same line as your text. In this example, the float property of the IMG class icon is set to “left” to achieve this effect. More text is required in this example so that you can see that the text continues to wrap around the image. This is that additional text that is required. By now, the example should have enough text to make the point. Just in case, another sentence will provide additional text for purposes of making this point. This will be the last sentence. OK, maybe just one more, but I mean it this time. It is common to want to have images appear on the same line as your text. In this example, the float property of the IMG class icon is set to “left” to achieve this effect. More text is required in this example so that you can see that the text continues to wrap around the image. This is that additional text that is required. By now, the example should have enough text to make the point. Just in case, another sentence will provide additional text for purposes of making this point. This will be the last sentence. OK, maybe just one more, but I mean it this time. This is a sample paragraph. Had this been an actual paragraph, you would have been instructed where to turn in your area for assistance on positioning text. This is only a sample. This is a sample paragraph. Had this been an actual paragraph, you would have been instructed where to turn in your area for assistance on positioning text. This is only a sample. Makes you want to buy some, eh? Not a lot has been written about creating pull quotes, but they can be an attractive addition to your Web page. They can draw attention to a few key words or sentences that summarize a thought, thus giving the visitor a quick idea of the point of the page. This is especially important if there is a lot of text on the page. Web visitors have gotten used to gleaning the message of the page from a combination of things, of which text is only a small part. Some visitors won’t sit still to read an entire page of text unless you can grab them with a snappy quote. Pull quotes can do that for you. ”pull quotes ... can draw attention to a few key words or sentences that summarize a thought” Not a lot has been written about creating pull quotes, but they can be an attractive addition to your Web page. They can draw attention to a few key words or sentences that summarize a thought, thus giving the visitor a quick idea of the point of the page. This is especially important if there is a lot of text on the page. Web visitors have gotten used to gleaning the message of the page from a combination of things, of which text is only a small part. Some visitors won’t sit still to read an entire page of text unless you can grab them with a snappy quote. Pull quotes can do that for you.
What do es this style sheet do ?
1. It fo rmats all the BODY elements with a light yello w (#000040) bac kgro und and dark gray (#FFFF9F) text using a fo nt o f Bo o k Antiqua o r, if that fo nt is no t available, Times New Ro man o r, if that is no t available, any serif fo nt, and it sets padding o n the page o f o ne inc h.
2. It fo rmats no t-yet-visited links ( A:LINK) to fuc hsia (#FF00FF). 3. It fo rmats visited links ( A:VISITED) to gray (#808080). 4. It fo rmats blo c kquo tes to have o ne-inc h left and right margins, whic h the bro wser wo uld add to the o ne-inc h padding already defined in the BODY element.
5. It fo rmats all ho rizo ntal rules to be two pixels tall. 6. It gives paragraphs a half-inc h indentatio n o n the first line. 7. It c reates a paragraph c lass c alled do uble ( P.double), whic h has the same half-inc h indentatio n o n the first line, but also inc ludes do uble-spac ing o f text (line height: 24pt).
8. It also c reates a SPAN c lass c alled highlight ( SPAN.highlight), whic h will have a text c o lo r o f navy blue (#000080) and a bac kgro und c o lo r o f bright yello w (#FFFF00).
Chapter 25 ✦ Introducing Cascading Style Sheets
Browser Compatibility Issues What abo ut ac tually using style sheets in bro wsers? Is all this stuff suppo rted? Unfo rtunately, no . Internet Explo rer 5 do es the best jo b o f implementing style sheets. Netsc ape 4.x is signific antly less suppo rtive o f style sheets, but do es suppo rt many features o f style sheets. Internet Explo rer 3 and 4 also do a respec table jo b o f suppo rting style sheets. What do es this mean fo r yo u? If yo u are c reating pages fo r an intranet and yo u kno w peo ple using yo ur pages will have IE 5, o r Navigato r 4, then yo u c an test yo ur pages o n the platfo rm yo u kno w peo ple will be using, and o nly use the styles suppo rted o n that platfo rm. Ho wever, if yo u are c reating pages fo r the Internet, where yo u c an’t predic t what kind o f bro wser visito rs will be using, yo u have three c ho ic es, rec apped fro m Chapter 2:
✦ Do n’t use style sheets. Co ntinue to design yo ur pages with the deprec ated HTML 3.2 elements and attributes and lo o k fo rward to the day when bro wsers that suppo rt style sheets are mo re widely used.
✦ Maintain two versio ns o f yo ur site. Believe it o r no t, this is what many large, high-pro file sites do . In Chapter 48, yo u will learn ho w to test to see whic h bro wser a visito r is using so that yo u c an auto matic ally lo ad the appro priate versio n o f the page.
✦ Use style sheets and to hec k with the luddites who haven’t upgraded. They will, after all, be able to see yo ur site; they just wo n’t get the same design lo o k that they sho uld.
From Here CrossReference
Jum p to Chapter 48 and learn about using JavaScript to test to see w hich version of w hich brow ser a visitor is using. Proceed to Chapter 26 and learn the syntax of style sheets.
Summary In this c hapter yo u learned just why style sheets are so valuable. Yo u learned what they c an do that c o uldn’t previo usly be do ne. Yo u learned abo ut the c asc ading mo del. Yo u go t a c hanc e to analyze an example o f a style sheet. Yo u also learned eno ugh abo ut bro wser c o mpatibility issues to understand that making a dec isio n abo ut using style sheets requires so me analysis.
✦
✦
✦
295
26 C H A P T E R
Learning CSS Syntax
✦
✦
✦
✦
In This Cha pter
I
f yo u lo o k at a style sheet and think yo u’ll never get the hang o f it, remember ho w yo u felt when yo u lo o ked at HTML fo r the first time. No w yo u have no fear o f it bec ause yo u understand the rules; yo u kno w that even if yo u see an element yo u’ve never seen befo re, yo u c an figure it o ut. CSS isn’t any mo re diffic ult. It has a c lear set o f rules that, unlike the set o f rules fo r HTML, fits into o ne c hapter. To help yo u alo ng, a c o mplete list o f all the pro perties yo u c an use in CSS is in Appendix E. By the time yo u finish this c hapter, yo u’ll kno w the syntax o f CSS, ho w CSS differs fro m HTML, and ho w to define and gro up CSS pro perties. Yo u learn so me sho rtc uts so yo ur pro perty definitio ns wo n’t be quite as verbo se as the example in the previo us c hapter. Yo u also learn abo ut the bo x-fo rmatting mo del CSS uses and abo ut inheritanc e, whic h is why yo u do n’t need to redefine every pro perty fo r every element. Yo u also learn abo ut defining c lasses and IDs, whic h enable yo u to add variety to different instanc es o f the same element o n the same page. Finally, yo u see the DIV and SPAN elements in ac tio n.
Anato my o f a style sheet Differences between CSS and HTML syntax Defining pro perties G ro uping pro perties Pro perty definitio n sho rtcuts Bo x fo rmatting : the CSS fo rmatting mo del Understanding inheritance Defining classes
Anatomy of a Style Sheet CSS has its o wn vo c abulary. To understand what go es where in a style sheet, yo u need to understand what eac h item o n the style sheet is c alled. A style sheet is c o mpo sed o f rule s. This is a rule:
P { text-indent: 2cm; color: black; padding-top: .25in; }
Pseudo -classes Defining IDs G ro uping elements with DIV and SPAN Adding co mments to yo ur style sheet
✦
✦
✦
✦
298
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
In the previo us example, P is the se le cto r. The selec to r c o uld just as easily have been P.spec ial, o r P#123. A selec to r indic ates to whic h elements, whic h c lass o f elements, o r whic h IDs o f elements the rule applies. A rule is made up o f a selec to r with o ne o r mo re dec laratio ns. Eac h o f the three lines under the selec to r is a dec laratio n. A de claratio n is c o mpo sed o f a pro perty and o ne o r mo re values. The pro pe rty is separated fro m the value by a c o lo n. Eac h dec laratio n ends with a semic o lo n. All the dec laratio ns are listed within c urly brac es ({}).
Differences Between CSS and HTM L Syntax When learning HTML, yo u learned HTML has e le me nts and that e le me nts have attribute s. CSS has selec to rs, whic h yo u sho uld rec o gnize, bec ause they c an be the same as the elements yo u use in HTML. In CSS, ho wever, instead o f the selec to rs having attributes, they have pro perties. The pro perties o f CSS selec to rs, just like the attributes o f HTML elements, have values. Here is an example o f an HTML element with o ne attribute:
This is my very short page.
and this is an example o f a CSS selec to r with o ne dec laratio n (pro perty-value pair):
BODY { color: white; } Yo u c an see that, just like an HTML element definitio n, the CSS selec to r has the element name in it. This is where the similarities end, tho ugh. In CSS, there are no angle brac kets (). Instead, a CSS rule has c urly brac es aro und the dec laratio n o r dec laratio ns. The CSS selec to r name is no t enc lo sed with any kind o f markings. There are no start o r end tags, and no c o ntent. The reaso n fo r this sho uld be o bvio us: CSS do c uments do n’t have anything rendered. Instead, they just have info rmatio n abo ut what is rendered in the HTML do c ument. CSS do c uments have pro perties that desc ribe ho w different parts o f the element will be rendered. These pro perties have values, just like attributes in HTML have values. The attribute-value pair in HTML lo o ks like this:
colspan=”3” In CSS, a pro perty-value pair, whic h is c alled a de claratio n, lo o ks like this:
color: white;
Chapter 26 ✦ Learning CSS Syntax
The three differenc es between defining attribute-value pairs and defining pro pertyvalue pairs are as fo llo ws:
1. Pro perty-value pairs use a c o lo n instead o f an equal sign. 2. In CSS, do uble quo tatio n marks do no t enc lo se the value (unless the value is multiple wo rds, as in a fo nt name).
3. A semic o lo n fo llo ws the pro perty-value pair. Onc e yo u get used to tho se differenc es, yo u’ll write dec laratio ns in CSS as deftly as yo u write attributes in HTML.
Defining Properties CSS is flexible. Yo u c an define a selec to r with o ne dec laratio n o r a selec to r with many dec laratio ns. Yo u use the same syntax either way. The basic o utline o f a CSS rule is as fo llo ws:
SELECTOR-NAME { property: value; property: value; property: value; }
/* declaration */
If a value has multiple wo rds, the value needs to be enc lo sed in do uble quo tatio n marks. Here is an example o f a style sheet with two rules:
BODY { font-family: “Times New Roman”, “Times Roman”, serif; color: black; background: white; margin-left: .5in; margin-right: .5in; } P { text-indent: .5in; margin-top: .25in; } All it do es is set the bo dy o f the do c ument to have a white bac kgro und with left and right margins o f a half inc h. It also sets the text to be blac k. The fo nt-family pro perty tells the bro wser to use the first fo nt in the list that it finds o n the c lient c o mputer. No tic e multiwo rd fo nt names, suc h as Bo o k Antiqua and Times New Ro man, eac h
299
300
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
have do uble quo tatio n marks aro und them. The last name in the list is a fo nt type, rather than a spec ific fo nt. If neither o f the first two fo nts are o n the c lient c o mputer, it says, use any serif fo nt. This style sheet also fo rmats paragraphs to have an indentatio n o n the first line o f paragraphs o f a half inc h, and a to p margin o f a quarter inc h. This means a quarter inc h o f white spac e will be between paragraphs.
Grouping Properties Here’s ano ther style sheet that defines the fo nt family fo r headings:
H1 { font-family:
Helvetica, Arial, sans-serif;
font-family:
Helvetica, Arial, sans-serif;
font-family:
Helvetica, Arial, sans-serif;
} H2 {
} H3 {
} What it says is headings H1, H2, and H3 sho uld use Helvetic a, if it is available; Arial, if Helvetic a is no t available; and any sans-serif fo nt, if neither Helvetic a no r Arial are available. To say all this takes a lo t o f spac e, tho ugh. Fo rtunately, a mo re c o nc ise way exists. Yo u c an gro up pro perty definitio ns by plac ing the element names into a c o mma-delimited list as fo llo ws:
H1, H2, H3 { font-family:
Helvetica, Arial, sans-serif;
} Using this tec hnique o f gro uping elements is a go o d way to save spac e, inc rease readability, and reduc e the po ssibility o f intro duc ing erro rs.
Chapter 26 ✦ Learning CSS Syntax
Property Definition Shortcuts Yo u c an define a lo t o f pro perties fo r fo nts, as this style-sheet exc erpt demo nstrates:
H3 { font-weight: bold; font-size: 16pt; line-height: 20pt; font-family: “Times New Roman”; font-variant: normal; font-style: italic; } Fo rtunately, yo u c an string this all into o ne pro perty, c alled fo nt, whic h sho rtens the definitio n c o nsiderably.
H3 { font: bold 16pt/20pt “Times New Roman” normal italic; } Onc e yo u get used to the sho rtc ut, yo u’ll never use the verbo se definitio n again.
Box Formatting: The CSS Formatting M odel CSS uses a c lever metapho r fo r helping yo u spec ify c o ntainers (blo c k-level elements) o n yo ur page: the bo x. When yo u define fo rmatting fo r yo ur blo c k-level elements — whether they be paragraphs, blo c kquo tes, lists, images, o r whatever — fo r purpo ses o f CSS, yo u are defining fo rmatting fo r a bo x. It do esn’t c are what is in the bo x; it just wants to fo rmat the bo x.
Box dimensions The first thing the bro wser do es is render the blo c k-level element to determine what the physic al dimensio ns o f the element are, given the fo nt selec ted fo r the element, the c o ntents o f the element, and any o ther internal fo rmatting instruc tio ns supplied by the style sheet. Then the bro wser lo o ks at the padding, the bo rder, and the margins o f the element to determine the spac e it ac tually requires o n the page.
301
302
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
element padding border margin
Padding is the distanc e between the o utside edges o f the element and the bo rder. The bo rde r is a line o r ridge. The margin is the distanc e between the bo rder and the o uter bo x o f the next c o ntainer. Ho w yo u define the padding, bo rder, and margin is desc ribed in detail in the fo llo wing sec tio ns.
Padding Yo u do n’t need to define any padding, but if yo u are go ing to define a bo rder, then yo u pro bably want to define padding so yo ur element do esn’t lo o k to o c ro wded. The default fo r an element is no padding. Figure 26-1 sho ws the same table with and witho ut padding. Yo u c an see the o ne witho ut padding lo o ks c ro wded.
Figure 26-1: Tables w ith and w ithout padding
Chapter 26 ✦ Learning CSS Syntax
Five pro perties are asso c iated with padding. They are as fo llo ws:
1. padding, whic h gives the same padding o n all sides 2. padding-top 3. padding-right 4. padding-bottom 5. padding-left Get used to seeing the -to p, -right, -bo tto m, and -left additio ns to pro perty names. This is ho w all bo x-related pro perties are spec ified. Suppo se yo u want to define yo ur paragraphs to have padding o n the to p, the left, and the right; yo u c o uld use the fo llo wing style sheet:
P { padding-top: .5in; padding-right: .5in; padding-left: .5in; } Or yo u c o uld use sho rthand to write o ut the padding pro perties as fo llo ws:
P { padding: .5in .5in 0in .5in; } Yo u c an always string the to p, right, bo tto m, and left pro perties to gether in that o rder. The same sho rthand wo rks fo r margins and bo rders. No tic e no c o mmas are between the items in the list.
Border The default is to have no bo rder o n elements. Yo u c an define a bo rder in two different ways. Either yo u c an define the width, c o lo r and style o f the bo rder, by side, o r yo u c an define the width, c o lo r, and style fo r the bo x individually. Two examples fo llo w:
BLOCKQUOTE { border-width: 1pt 1pt 0pt 1pt; border-color: black; border-style: solid; }
303
304
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
The previo us example c reates a blac k, so lid bo rder fo r the to p, right, and left sides o f the list.
BLOCKQUOTE { border-top: 1pt solid black; border-right: 1pt solid black; border-left: 1pt solid black; } Bo th these examples c reate the same bo rder. The bo rder is inserted between the padding, if there is any, and the margin, if there is any. Valid values fo r bo rder style are: no ne, do tted, dashed, so lid, do uble, gro o ve, ridge, inset, and o utset. Or, if yo u want to c reate a bo rder that is the same o n all fo ur sides, yo u c an use the bo rder pro perty:
BLOCKQUOTE { border: 1pt solid black; }
M argins Margins c reate white spac e o utside o f the bo rder. No tic e in Figure 26-1 that the two tables are immediately adjac ent to eac h o ther. This is bec ause neither o ne has margins. Margins are c reated with the margin, margin-to p, margin-right, margin-bo tto m, and margin-left pro perties. They wo rk exac tly the same as the padding pro perty.
Understanding Inheritance If yo u define a bac kgro und c o lo r fo r the BODY o f yo ur do c ument, yo u do n’t have to define the same bac kgro und c o lo r fo r eac h P element. Why no t? Inheritanc e. Elements within c o ntainers inherit c harac teristic s o f the c o ntainers in whic h they exist. A paragraph is a c o ntainer, but it is also within a c o ntainer — the BODY element. If yo u have an italic ized wo rd in yo ur paragraph, yo u c an expec t that wo rd to inherit the fo nt, text c o lo r, text size, line spac ing, and so fo rth o f the paragraph (exc ept it will be italic ized); yo u c an also expec t the paragraph to inherit a few things fro m the BODY, suc h as bac kgro und c o lo r, padding, margins, and anything else the P element do esn’t spec ific ally spec ify. Inheritanc e is great. Inhe ritance enables yo u to define fo rmatting o nly at the highest level. The fo rmatting yo u define tric kles do wn to the lo wer-level elements. An awareness o f inheritanc e c an keep yo u fro m spec ifying every pro perty at every level.
Chapter 26 ✦ Learning CSS Syntax
Defining Classes Classe s are ho w yo u c usto mize elements in yo ur page. With c lasses, yo u c an define mo re than o ne lo o k fo r an element in yo ur style sheet and then, in yo ur page, yo u say whic h lo o k yo u want to use. Classes are defined in yo ur style sheet using the fo llo wing no tatio n:
P.first { font: bold 12pt/14pt “Times New Roman”; } P.second { font: normal 12pt/12pt “Times New Roman”; } To use these c lasses in yo ur page, refer to them as fo llo ws:
Pseudo-Classes When yo u are lo o king at a page and have already c lic ked o ne o r mo re o f the links o n the page, yo u might no tic e the links yo u have already c lic ked are a different c o lo r fro m the links yo u have no t yet c lic ked. Yo u c an define what yo u want tho se c o lo rs to be using so me o f the available pseudo -c lasses in style sheets. Even tho ugh pse udo means fake in Greek, these aren’t really fake c lasses — they’re predefined c lasses that already mean so mething to the bro wser. Pseudo -c lasses enable fo rmatting based o n c harac teristic s o ther than name, attributes, o r c o ntent. Yo u c an define pseudo -c lasses fo r three different types o f links:
1. A:link fo r unvisited links 2. A:visited fo r visited links 3. A:active fo r the ac tive link (that is, the link yo u are c urrently c lic king) If yo u want to add a regular c lass to the A element, yo u define the selec to r as A.first-class:link. Co nsider the fo llo wing example:
A:link { color: red;
305
306
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
} A:visited { color: blue; } A:active { color: green; } A.special:link { color: #FF33FF; }
/* fuchsia */
This style sheet has fo ur rules. The first three define the c o lo rs o f unvisited links, visited links, and ac tive links. The last o ne will o nly be used when the c lass is spec ified as spec ial; it spec ifies the c o lo r o f unvisited links.
Defining IDs Yo u wo n’t use IDs nearly as o ften as yo u use c lasses, but it’s nic e to kno w they are there if yo u need them. IDs are like c lasses, exc ept they are no t nec essarily asso c iated with elements. Isn’t this c o ntrary to the HTML 4 Way? Yes, but it’s there if yo u need it. IDs are defined as fo llo ws:
#wide { letter-spacing: .4em; } And used as fo llo ws:
This is a wide heading
Grouping Elements with DIV and SPAN In Chapters 16 and 17, yo u learned abo ut using the DIV and SPAN elements to gro up blo c k-level elements and inline elements, respec tively. No w yo u c an finally see ho w this wo rks with style sheets. Co nsider the fo llo wing style-sheet rules:
DIV.important { background: red; font: bold 14pt/18pt Helvetica; }
Chapter 26 ✦ Learning CSS Syntax
SPAN.incidental { font: normal 8pt/8pt Helvetica; background: gray; } Yo u c an use them as fo llo ws:
...table contents...
Comments in Style Sheets Adding c o mments to yo ur style sheets, just as yo u add c o mments to yo ur HTML pages, is no t a bad idea. Co mments are defined in yo ur style sheet using a different c o nventio n than in yo ur HTML pages. Lo o k bac k to the sample c o de fo r the pseudo -c lasses style sheet. No tic e next to the hexadec imal value #FF33FF, there is the fo llo wing:
/* fuchsia */ That is a c o mment in CSS. Adding a c o mment is little tro uble when yo u c reate the style sheet; it is a lo t mo re wo rk to go bac k and remember what yo u meant when yo u defined the style sheet. If yo u use c o mments no where else, use them when yo u use hexadec imal no tatio n fo r c o lo rs. Co mments are c reated with a / * prec eding them and a */ fo llo wing them.
From Here CrossReference
Jum p to Chapter 33 to learn about CSS positioning options Proceed to Chapter 27 and begin adding styles to your Web page.
307
308
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
Summary In this c hapter yo u learned abo ut the basic s o f CSS. Yo u learned the vo c abulary, the c o nventio ns, and differenc es between CSS and HTML syntax. Yo u learned abo ut defining pro perties, gro uping pro perties, and defining pro perties using sho rtc uts. Yo u learned abo ut the CSS bo x mo del and abo ut inheritanc e fro m c o ntainers to elements. Yo u also learned abo ut c lasses, pseudo -c lasses, and IDs. Finally, yo u learned abo ut using the DIV and SPAN elements to gro up elements so they c an all take advantage o f the same fo rmatting.
✦
✦
✦
27 C H A P T E R
Adding Styles to Your Web Pages
✦
✦
✦
✦
In This Cha pter
N
o w that yo u kno w why yo u sho uld use a style sheet and ho w to write a style sheet, yo u need to kno w ho w to inc lude style sheets in yo ur page. This do c ument takes yo u thro ugh the three o ptio ns yo u have fo r adding styles to yo ur page. With the c asc ading appro ac h, yo u c an ac tually use all three at the same time, but yo u pro bably do n’t want to do this, as yo u learn in this c hapter.
Using an External Style Sheet The preferred way to inc lude styles in yo ur page is to use an external style sheet. This is the o nly way to take advantage o f all the benefits yo u have read abo ut relating to using style sheets. If yo u use an external style sheet, then all yo ur style info rmatio n fo r all yo ur pages is sto red in o ne c entral plac e. If yo u want to give yo ur site a fac e-lift, it’s as easy as c hanging the external style sheet. To use an external style sheet, simply c reate yo ur style sheet and save it with a .c ss extensio n. Then link to it fro m the HEAD o f yo ur page using the LINK element. The fo llo wing list is no t the c o mplete spec ific atio n fo r the LINK element. The LINK element is used fo r o ther unrelated func tio ns, whic h o nly c o nfuse this use. CrossReference
For the com plete specification of the LINK elem ent, refer to Chapter 12.
Using an external style sheet Using a STYLE element within the HEAD Adding inline styles Using a standardized style sheet Cho o sing the rig ht appro ach
✦
✦
✦
✦
310
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
Link Start Tag:
Required
Content:
Empty
End Tag:
Fo rbidden
Attributes:
id, class, lang, dir, title, style, events href: URL o f style sheet hreflang: language o f do c ument spec ified in href attribute type: MIME type o f do c ument spec ified in href attribute, usually “text/ c ss”
Here is an example o f the LINK element used to link to an external style sheet c alled may2000.css that exists in the styles subdirec to ry:
The LINK element, whether it is used fo r linking to an external style sheet o r fo r so me o ther purpo se, must be lo c ated in the HEAD element.
Using a STYLE Element within the HEAD If yo u are unhappy with any pre-existing style sheet o r yo u do n’t want to sto re yo ur styles in a separate style sheet fo r whatever reaso n, then yo u c an sto re yo ur c o mplete style sheet in the HEAD element direc tly. Ho w do es this wo rk? Yo u put the rules (the statements that tell the bro wser ho w to render eac h element) direc tly into a STYLE element in the HEAD. As yo u c an imagine, this c o uld make yo ur HEAD quite lo ng. The STYLE element has the fo llo wing spec ific atio n:
Style
311
312
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
Adding Inline Styles Reaso ns may exist why yo u wo uld want to add style info rmatio n direc tly at the element level. Yo u may have no tic ed that nearly every element intro duc ed in this bo o k has had a style attribute. This attribute is used to define element-spec ific style info rmatio n. The style attribute is used as fo llo ws:
P.deep-blue { text-indent: 1in; color: blue; } Either example renders the same in the bro wser. Either o ne enables yo ur page to be rendered easily in speec h-synthesizing bro wsers. Bo th are vastly preferable to the HTML 3.2 metho d o f using a c lear GIF to indent the paragraph and then using the FONT element to c hange the text c o lo r to blue.
Using a Standardized Style Sheet If after all these style sheets examples, yo u still do n’t feel c o mfo rtable writing yo ur o wn style sheet, do n’t despair. Many standard style sheets are available. Mo st peo ple get started writing HTML by c o pying pages with features they like and mo difying the c o de to meet their needs. Mo st peo ple who write Perl use this
Chapter 27 ✦ Adding Styles to Your Web Pages
tec hnique; mo st peo ple who write JavaSc ript go t started this way. Finding a style sheet yo u like and mo difying it to meet yo ur needs is no disgrac e. On the CD-ROM
To help m ake it easier, the CD-ROM in the back of this book has several standard style sheets on it. Pick one that com es close to approxim ating the look you w ant and custom ize it to m ake it your ow n.
Yo u might find yo ur o rganizatio n has its o wn style sheet, whic h yo u are expec ted to use. If this is the c ase, the po wers that c o ntro l the style sheet might no t let yo u c reate spec ial c lasses to ac c o mmo date yo ur fo rmatting needs. Fo rtunately, CSS has a way to help yo u get aro und any limitatio ns this might present. Co nsider the fo llo wing HTML, whic h refers to a c o rpo rate style sheet. It do esn’t even matter what is in the style sheet fo r yo ur purpo ses bec ause yo u are required to use it and yo u are no t allo wed to c hange it.
A heading
Yo u c an see the frustratio n yo u wo uld enc o unter bec ause yo u c an’t c hange the fo rmatting o f the sec o nd paragraph using the c o rpo rate style sheet yo u are pro vided. Given what yo u’ve learned in this c hapter, yo u kno w two ways to get aro und this limitatio n. The first is to c reate a STYLE element in the HEAD element and c reate a c lass fo r the sec o nd paragraph.
313
314
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
A heading
The o ther way yo u learned is to put the style info rmatio n direc tly into a style attribute in the P element.
A heading
Fo r the previo us example, where the c usto mizatio n yo u want to affec t in fo rmatting is minimal and o nly affec ts o ne element, either o f the two metho ds o f ac c o mplishing this wo uld be fine. Neither o ne substantially c lutters yo ur HTML. The first o ne is pro bably better, but the differenc e is minusc ule. Ho wever, there is o ne o ther way to take c o ntro l o f the lo o k o f yo ur page at a mic ro level when yo u are fo rc ed to use a style sheet o ver whic h yo u have no c o ntro l. This is to c reate ano ther external style sheet and link to it in the HEAD fo llo wing the link to the standard style sheet. If, ho wever, yo u want to c reate c lasses o r c hange fo rmatting fo r multiple elements, yo u pro bably want to mo ve this fo rmatting to yo ur o wn style sheet, as sho wn in the fo llo wing:
A heading
Chapter 27 ✦ Adding Styles to Your Web Pages
Yo u c an ac tually inc lude as many links to external style sheets as yo u need. Do es the o rder matter? Yo u bet! Bec ause o f the c asc ading rules disc ussed in the last c hapter, the last style sheet spec ified c an o verride all previo us style sheets spec ified. If yo u are suppo sed to use a standard style sheet c reated by so meo ne else, then yo u want to be c areful no t to o verride any o f tho se styles. As with all style definitio ns, the lo west-level style defined has the highest prio rity. Co nversely, the higher a style is defined, the lo wer the prio rity.
M ixing the Approaches: An Example The fo llo wing example o f c o mbining style definitio ns sho uld help make the c o nc ept o f c asc ading style sheets and the use o f c lasses, IDs, and inline style definitio ns c lear. This is a lo ng example, but it is o ne to whic h yo u c an refer later if yo u have questio ns abo ut yo ur o wn implementatio n o f style sheets.
Corporate.css BODY { color: black; background: white; padding-left: 1in; padding-right: 1in; } H1 { font: bold 24pt/30pt black; } P { text-indent: .5in; } A:link { color: blue; } A:visited { color: red; } A:active { color: yellow; } BLOCKQUOTE { margin-left: 1in;
315
316
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
margin-right: 1in; } mine.css SPAN.special { color: red; } #wide { letter-spacing: .5em; } HR { width: 3pt; color: red; } The two external style sheets used in this example are defined previo usly. They are c alled corporate.css and mine.css. The HTML page is defined in the fo llo wing:
A page with special formatting
In the previo us example, many c o nflic ting instruc tio ns exist in the fo rm o f style info rmatio n fo r the bro wser. Ho w will it render? The first H1 has an ID o f wide. If yo u lo o k at mine.css, yo u c an see an ID o f wide is defined that affec ts letter spac ing. But this wo n’t be used. Why? Bec ause ano ther ID o f wide spec ific to the H1 element is defined in the STYLE element and that ID affec ts line height. No tic e the H1 element also has a SPAN element with a class o f spec ial that affec ts o ne wo rd. The spec ial c lass is defined in mine.css and isn’t
Chapter 27 ✦ Adding Styles to Your Web Pages
o verridden anywhere further do wn, so the wo rd special, within the SPAN element, will be rendered as red. The first paragraph also uses the SPAN element with an ID o f wide. Ho w will this render? It will use the ID wide defined in mine.css, bec ause it isn’t affec ted by the H1 element defined in the STYLE element. The first HR element will render in blac k, bec ause the style attribute is defined right there and will o verride the HR definitio n in mine.css. It will render with the width pro vided in mine.css, sinc e the new definitio n do esn’t spec ify the width. Ho w abo ut the sec o nd HR definitio n? Will it inherit the c o lo r o f the previo us HR element? No . It will render just as mine.css defines it bec ause no style info rmatio n o verrides the style info rmatio n in mine.css. Finally, in the last paragraph, whic h do esn’t have any style referenc es, there is a link. Ho w will the link render? Until the link is visited, it will render in blue as defined by A:link in corporate.css. Onc e it is visited, it will render in red, and when it is ac tive, it will render in yello w. No thing spec ial must be do ne to the HTML to take advantage o f the three pseudo -elements related to the A element.
From Here CrossReference
Jum p to Chapter 33 and learn about absolute positioning in CSS. Proceed to Chapter 28 and learn about adding colors and backgrounds to your pages.
Summary In this c hapter yo u go t a c rash c o urse in using CSS in yo ur page. Yo u learned ho w to link to an external style sheet. Yo u learned abo ut using the STYLE element and yo u learned abo ut using inline style definitio ns. Yo u learned abo ut using a standardized style sheet and ho w yo u c an get aro und any limitatio ns related to this. If yo u persevered, yo u also learned ho w c asc ading rules affec t the implementatio n o f styles in yo ur page in a tho ro ugh example.
✦
✦
✦
317
28 C H A P T E R
Adding Colors and Backgrounds
✦
✦
✦
✦
In This Cha pter Ho w yo ur mo nito r creates co lo r
T
he HTML 4 Way gives yo u lo ts o f ways to c hange the c o lo rs o n yo ur sc reen. Yo u c an c hange text c o lo rs, bac kgro und c o lo rs, and bac kgro und images fo r everything o n the page, o r o n an element-by-element basis. This c hapter explains ho w yo ur sc reen renders c o lo rs and why no two mo nito rs lo o k alike. It also disc usses c o lo r palettes — the c o lo r info rmatio n an image sends — inc luding a c o lo r-safe palette that renders pro perly o n bo th PCs and Mac s. Next, yo u learn abo ut c o lo r c o mpatibility and why it’s wise to c ho o se yo ur c o lo rs and stic k with them. Yo u learn ho w to define a bac kgro und c o lo r and text c o lo rs. Finally, yo u learn ho w to add a bac kgro und graphic and to spec ify whether it repeats.
Intro ducing co lo r co des Co lo r palettes Co lo r-co mpatibility co nsideratio ns Defining a backg ro und co lo r Chang ing default text co lo rs Adding a backg ro und g raphic
How Your M onitor Creates Color Co mputers use the RGB system to c reate c o lo rs. Do n’t be put o ff by ano ther ac ro nym; RGB stands fo r Re d-Gre e n-Blue . Basic ally, the c o mputer c an generate o nly red, green, o r blue light. When it generates all three to gether, at full po wer, it pro duc es white. When it generates no ne o f them, it pro duc es blac k. This is c o ntrary to the way that artists think abo ut c o lo r. White is usually the absenc e o f c o lo r in art — but o n yo ur c o mputer sc reen, white is what yo u get when yo u mix all the o ther c o lo rs to gether. All info rmatio n o n yo ur c o mputer is passed in the fo rm o f binary data — a lo ng string o f o nes and zero s — whic h is no t a very useful way to c o nvey info rmatio n to peo ple. A sho rthand fo r the o nes and zero s, he xade cimal (o r he x ) no tatio n, o ffers
✦
✦
✦
✦
320
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
peo ple a way to disc uss this info rmatio n. The hexadec imal system assigns eac h digit a value between 0 and 15. The dec imal system, the way we’re used to c o unting, takes two digits to c o nvey the numbers 10, 11, 12, 13, 14, and 15; hex substitutes letters fo r tho se six numbers. So , this is ho w yo u c o unt fro m 0 to 15 in hex: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. If yo u want to c o unt to 16, it’s like go ing fro m 9 to 10 in the dec imal system; to go fro m 15 to 16 in the hex system, yo u intro duc e a new digit. That’s where it gets c o nfusing. If 15 is F, then yo u write 16 as 10 (pro no unc ed “o ne-zero ,” no t te n) in hex. Yo u frequently see numbers in hex like FF33A0. That might lo o k like a fo reign language, but it’s far easier to wo rk with than 111111110011001110100000, whic h translates to the same thing! Here’s the go o d news: Yo u wo n’t have to do math in hex to add c o lo rs to yo ur page.
Introducing Color Codes The c o mputer pro jec ts c o lo r based o n the intensity o f red, green, and blue yo u tell it to pro vide. Yo u tell it what intensity to pro vide by using co lo r co de s written in the hex system; yo u have already seen c o lo rs in this bo o k defined in hex. In HTML, when yo u spec ify a c o lo r in hex, yo u need to prec ede the c o lo r c o de with a po und sign (#). Here are so me easy o nes: #000000 (no red, no green, no blue) is blac k; #FFFFFF (full-po wer red, full-po wer green, full-po wer blue) is white. Are yo u getting the hang o f this? Ho w abo ut #FF0000? Red. #008000? Green. #0000FF? Blue.
Using English At this po int, there’s mo re go o d news: Yo u needn’t use c o lo r c o des to define yo ur c o lo rs. All the c o lo rs in the previo us sec tio n ac tually have English names that HTML rec o gnizes. The pro blem with using English c o lo r names is o nly 16 o f them are guaranteed to wo rk. They are listed in Table 28-1.
Table 28-1 English Names for Colors Color Name
Hex Value
Black
# 000000
Green
# 008000
Silver
# C0C0C0
Lim e
# 00FF00
Gray
# 808080
Chapter 28 ✦ Adding Colors and Backgrounds
Color Name
Hex Value
Olive
# 808000
White
# FFFFFF
Yellow
# FFFF00
Maroon
# 800000
Navy
# 000080
Red
# FF0000
Blue
# 0000FF
Purple
# 800080
Teal
# 008080
Fuchsia
# FF00FF
Aqua
# 00FFFF
M onitor-to-monitor variations Have yo u ever no tic ed that a sc reen image yo u’re used to seeing o ne way o n yo ur mo nito r renders in slightly different c o lo rs o n ano ther mo nito r? The reaso n is no abso lute red exists in the c o mputer wo rld. There isn’t even an abso lute white. Depending o n the tubes in yo ur mo nito r, ho w o ld it is, ho w it is adjusted, and a few o ther things, white may be white, pinkish white, bluish white, greenish white, o r just plain gray. Yo ur eyes adjust to what they kno w o ught to be white, but if yo u ho ld a white piec e o f paper up next to yo ur mo nito r, yo u will see yo ur mo nito r’s idea o f white pro bably isn’t true white. What do es this mean to yo u as a designer? It means that altho ugh yo u want to selec t yo ur c o lo rs c arefully, yo u do n’t have c o ntro l o ver ho w they render. Yo u want to test them extensively o n a number o f different mo nito rs — no t just the same brand o f mo nito r o n ten different desks, altho ugh there will be a differenc e — but even o n o ther platfo rms and brands o f mo nito rs. CrossReference
Chapter 37 takes you through an explanation of bit depth that you m ay w ant to review before you select the colors for your site.
Color Palettes Remember o pening that bo x o f 64 c rayo ns as a c hild? That was a c o lo r palette o f 64. It didn’t seem limiting at the time. Yo u had blue, green-blue, blue-green, green, and 60 o ther c o lo rs to c ho o se fro m. If yo u had to limit yo urself to a 64-c o lo r palette fo r yo ur Web site, tho ugh, yo u’d be terribly frustrated. Fo rtunately, nearly everyo ne
321
322
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
who visits yo ur site with a bro wser that suppo rts mo re than text is also likely to have a c o lo r mo nito r that suppo rts at least 256 c o lo rs. Where do es that number 256 c o me fro m? In the hex system, 100 (o ne-zero -zero ) translates into 256 in the dec imal system. When yo u send info rmatio n (suc h as a bac kgro und image o r info rmatio n abo ut the text c o lo r), yo u want to save time by using the palette o n the visito r’s system whenever po ssible, rather than sending ano ther palette ac ro ss the Web to the visito r’s system. All c o mputers have built-in c o lo r palettes — ho w c o nvenient! — the o nly pro blem is that c o lo r palettes are no t the same o n all systems. A 256-c o lo r palette is available o n bo th Mac s and PCs, but o nly 216 o f the c o lo rs are the same o n bo th platfo rms. If yo u plan to use the built-in c o lo r palette o n yo ur visito rs’ c o mputers, make sure yo ur site is using a co lo r-safe palette. Tip
You can find the color-safe palette on the Web at www.lynda.com/hex.html, courtesy of Lynda Weinm an.
Color-Compatibility Considerations When yo u c ho o se the c o lo rs fo r yo ur bac kgro und, bac kgro und images, text c o lo r, and headings c o lo rs, yo u want to be sure that yo u are selec ting them all fro m the same palette. If yo u selec t c o lo rs ac ro ss palettes, there are two pro blems. The first is yo u need to send mo re palette info rmatio n o ver the Web than nec essary, slo wing yo ur page’s do wnlo ad time. The sec o nd is yo ur c o lo rs might no t matc h. No t every shade o f blue go es with every shade o f green. By keeping yo ur c o lo r selec tio n within a single palette, yo u are sure to avo id the pro blem o f c lashing shades, where so me o f yo ur c o lo rs are c o nsidered warm, while o thers are c o nsidered c o o l.
Defining a Background Color Yo u are finally ready to start defining c o lo rs fo r yo ur page. Yo u saw in the previo us c hapters that yo u c an define c o lo rs in yo ur style sheet. Yo u c an define a bac kgro und c o lo r fo r eac h element o n yo ur page, but unless yo u are do ing that fo r so me instruc tio nal purpo se, yo u pro bably do n’t want to do that. Under no rmal c irc umstanc es, yo u define a bac kgro und c o lo r fo r yo ur BODY element and just let inheritanc e do its jo b so that every o ther element o n the page ends up with the same bac kgro und c o lo r. By inc luding a dec laratio n like the o ne here in yo ur style sheet, yo u c an set the bac kgro und c o lo r fo r any element:
background-color: #00AAAA;
/* light aqua */
Chapter 28 ✦ Adding Colors and Backgrounds
The impo rtant thing to remember is that the pro perty is c alled backgro und-co lo r. If yo u are used to defining the bac kgro und c o lo r direc tly in the BODY element, yo u are used to an attribute name o f bgc o lo r.
Changing Default Text Colors Yo u c an use style sheets to set text c o lo rs, as well. The pro perty name to remember is co lo r. By setting the c o lo r pro perty fo r the BODY, all o ther elements will inherit that c o lo r. Yo u c an, o f c o urse, c hange the c o lo r o f the text fo r any element by inc luding the c o lo r pro perty in a dec laratio n like the o ne in the fo llo wing, in that element’s style-sheet rule.
color: #FF33FF;
/* a loud shade of fuchsia */
Yo u have already seen ho w text c o lo rs fo r links c an be c hanged: Yo u use the pseudo -elements related to the A element. In the style sheet that fo llo ws, the link c o lo r fo r links that have no t yet been visited is yello w. The c o lo r fo r links that have been visited is gray; the c o lo r o f the ac tive link is blue. It so unds awful, but it wo uldn’t lo o k bad if the bac kgro und c o lo r were very dark.
A:link { color: yellow; } A:visited { color: gray; } A:active { color: blue; }
Adding a Background Graphic HTML 4 do es a great favo r fo r Web visito rs by helping Web designers c urb their natural desire fo r flash. Fo r the first time, yo u c an add a bac kgro und graphic to yo ur page that do es no t tile. The default is fo r all bac kgro und images to tile. This means any image yo u assign to be yo ur bac kgro und image auto matic ally repeats itself until the sc reen is c o vered. This may o r may no t have been what yo u intended. If yo u aren’t c areful, the results c an be ho rrendo us. Clever Web designers have always taken advantage o f the tiling effec t by spec ifying graphic s that tile well, o r tile invisibly, suc h as a marble effec t, o r c lo uds. An effec t that c an be stunning is c reating a lo go o r the name o f yo ur c o mpany in a nic e fo nt and then using a graphic s pac kage — suc h as Pho to sho p — to embo ss the image and then subduing the c o lo rs and letting that tile.
323
324
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
Adding a bac kgro und image is a c inc h in CSS:
BODY { background-color: white; background-image: url(../images/background.gif); background-repeat: no-repeat; background-attachment: scroll; background-position: top center; } A few things to no te abo ut these five bac kgro und pro perties:
✦ background-color. This pro perty determines the bac kgro und c o lo r fo r yo ur page. Yo u want to make sure that the bac kgro und c o lo r yo u selec t matc hes yo ur bac kgro und image c o lo r, if yo u have o ne.
✦ background-image. This pro perty c o ntains the URL o f the bac kgro und image. No tic e that the URL is spec ified within parentheses with the keywo rd url prec eding the parenthesis. This is ho w URLs are spec ified in CSS. Yo u haven’t seen this c o nventio n yet in this bo o k.
✦ background-repeat. This pro perty determines whether to repeat (that is, tile) the bac kgro und image. Yo ur c ho ic es are repeat (tile the way yo u are used to seeing bac kgro und images tile), repeat-x (tile ho rizo ntally o nly), repeat-y (tile vertic ally o nly), o r no -repeat.
✦ background-attachment. This pro perty enables yo u to spec ify whether the bac kgro und image mo ves with the text (that is, sc ro lls) o r stays in o ne po sitio n relative to the page (remains fixed).
✦ background-position. Yo u c an spec ify two values fo r this pro perty with a spac e between them: vertic al po sitio n and ho rizo ntal po sitio n. Yo u c an spec ify them in terms o f a perc entage o f the page, the distanc e o n the page, o r a keywo rd. All o f the fo llo wing are valid:
background-position: 10% 10%; background-position: 1cm 3in; background-position: top center; background-position: 30% center; As with fo nt definitio ns, yo u c an define bac kgro und pro perties to gether in o ne pro perty c alled background. The background pro perty is defined by this c o de:
background: background-color background-image background-repeat background-attachment background-position
Chapter 28 ✦ Adding Colors and Backgrounds
In the fo llo wing valid examples o f the background pro perty, no tic e backgroundposition is ac tually two values; a c o mplete list o f all the bac kgro und pro perties is ac tually six values lo ng. As with all sho rtc uts, yo u needn’t inc lude all the values.
background: white url(../images/logo-faded.gif) no-repeat scroll center center; background: url(../images/logo-faded.gif) 2cm center; background: url(../images/logo-faded.gif) repeat-x fixed 10% center;
From Here CrossReference
Jum p to Chapter 37 and learn about bit depth in colors. Proceed to Chapter 29 and learn about form atting paragraphs.
Summary In this c hapter, yo u learned abo ut ho w yo ur c o mputer c reates c o lo rs fro m zero s and o nes. Yo u learned a little bit abo ut the hexadec imal system and ho w yo u c an use it to define c o lo rs. Yo u also learned abo ut palettes and where to find systemsafe palettes. Finally, yo u learned ho w to apply all this info rmatio n to define a bac kgro und c o lo r, text c o lo rs, and a bac kgro und image that do esn’t tile.
✦
✦
✦
325
29 C H A P T E R
Formatting Paragraphs
✦
✦
✦
✦
In This Cha pter
I
n this c hapter, yo u learn abo ut fo rmatting paragraphs with the bo x fo rmatting mo de l. This CSS feature fo rmats blo c klevel elements o f a do c ument, inc luding paragraphs. Yo u learn abo ut indenting text, c o ntro lling alignment, spec ifying line spac ing, and c o ntro lling lists. Yo u also learn ho w to add rules and bo rders.
The CSS bo x fo rmatting mo del Adding indentatio ns Co ntro lling alig nment Cho o sing line spacing
Reviewing the CSS Box Formatting M odel Yo u may rec all the CSS bo x fo rmatting mo del fro m Chapter 26: After a blo c k-level o bjec t is rendered, the bro wser uses info rmatio n in the style sheet to determine ho w to fo rmat aro und the bo x in whic h the o bjec t is rendered.
element padding border margin
Co ntro lling lists with styles Adding bo rders
✦
✦
✦
✦
328
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
Padding summary Padding — the white spac e between the element itself and the bo rder (if there is o ne) — takes o n the bac kgro und c o lo r assigned to the element. These five pro perties are related to padding:
✦ padding-top ✦ padding-right ✦ padding-bottom ✦ padding-left ✦ padding The first fo ur take either a valid length o r a perc entage o f the c anvas. The fifth pro perty, padding, is the sho rtc ut fo r the first fo ur. It c an take between o ne and fo ur values. It assumes that the values yo u pro vide are fo r the to p, right, bo tto m, and left, in that o rder.
M argins summary Margins take o n the bac kgro und c o lo r o f the parent element — the c o ntainer in whic h this blo c k-level element is defined. Fo r example, if the element being defined is a paragraph, the parent element might be the BODY element. Suppo se two items are vertic ally aligned o n the page, eac h with its o wn margin defined; fo r the to p element, the margin wo uld be the margin-bottom element, fo r the bo tto m element, it wo uld be margin-top; the bro wser renders the two elements with a margin between them that equals the larger o f these two margins, no t the sum o f the margins. Fo r elements aligned ho rizo ntally, the bro wser renders eac h element with its o wn margin; it do es no t c o llapse the two margins into the greater o f the two . Five pro perties spec ify no t o nly the margins, but also the white spac e between the bo rder o f the element (if it has o ne) and the margin o f the next element. These pro perties are as fo llo ws:
✦ margin-top ✦ margin-right ✦ margin-bottom ✦ margin-left ✦ margin The margin pro perties wo rk exac tly the same as the padding pro perties.
Chapter 29 ✦ Formatting Paragraphs
Units of length To define padding o r margins, first yo u need to kno w what units yo u c an use to define them. Many pro perties in CSS take lengths in bo th re lative units and abso lute units. The relative units are as fo llo ws:
✦ em — the height o f the element’s fo nt ✦ ex — the height o f the letter x ✦ px — pixels, whic h are measurable o n the c anvas The abso lute units are as fo llo ws:
✦ in — inc hes ✦ cm — c entimeters ✦ mm — millimeters ✦ pt — po ints; 72 po ints to an inc h ✦ pc — pic as; 12 po ints to a pic a
Adding Indentations Ano ther way to fo rmat yo ur paragraph is to indent the first line o f text, o r o utdent the first line o f text. Outde nting, also kno wn as c reating a hanging indent, is when the first line o f text hangs o ut into the margin and subsequent lines o f text begin further in. Yo u c an define text indenting using the text-indent pro perty as fo llo ws:
text-indent: .5in; text-indent: 2cm; text-indent: -8em;
Controlling Alignment Yo u might also want to c o ntro l what is no rmally c alled text justific atio n. CSS c alls it alignme nt. Text alignment c an be set to left, whic h is the default; center;, right;, o r justify, whic h is full alignment. The pro perty is c alled text-align. Here are so me examples:
text-align: left; text-align: center; text-align: justify;
329
330
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
Choosing Line Height By default, yo ur bro wser renders yo ur fo nt size with o ne pixel abo ve the tallest letter and o ne pixel belo w the lo west-reac hing letter. So , if yo u spec ify yo u want the fo nt-size to be 12pt, the bro wser assumes line spac ing sho uld be 14pt. Yo u c an, ho wever, c hange that by using a greater line-height to spread o ut yo ur text o n the page. The fo llo wing example c reates a paragraph with standard indentatio n and very tight line spac ing:
P { font-size: medium; line-height: 12pt; }
Controlling Lists with Styles Yo u c an use mo st o f the pro perties listed earlier in this c hapter to fo rmat yo ur lists as well. Eac h list item is fo rmatted as its o wn blo c k-level element, whic h means yo u c an assign that element its o wn padding, bo rders, and margins. Yo u c an spec ify what bullets lo o k like fo r uno rdered lists, the numbering system used fo r o rdered lists, and (if yo u prefer) the image to be used as a bullet po int. Yo u c an also spec ify whether the bullets are o utdented (whic h is pro bably the way yo u’re used to seeing them in lists), o r flush with the left margin; if yo ur text direc tio n is right-to -left, yo ur bullets c an be flush with the right margin.
List style type Fo r o rdered lists ( OL), whic h typic ally have a number o r a letter next to eac h list item, yo u c an c ho o se fro m amo ng these types o f list style:
✦ decimal. 1, 2, 3, 4, 5, and so o n ✦ lower-roman. i, ii, iii, iv, v, and so o n ✦ upper-roman. I, II, III, IV, V, and so o n ✦ lower-alpha. a, b, c , d, e, and so o n ✦ upper-alpha. A, B, C, D, E, and so o n Fo r uno rdered lists, whic h typic ally have so me shape o f bullet next to eac h list item, yo u c an c ho o se between
✦ disc. standard so lid c irc le
Chapter 29 ✦ Formatting Paragraphs
✦ circle. empty c irc le ✦ square. so lid square So me examples fo llo w:
OL { list-style-type: lower-alpha; /* a, b, c, etc. */ } UL { list-style-type: circle; }
List style image CSS enables yo u to spec ify an image instead o f a disc , c irc le, o r square fo r the bullet in uno rdered lists; yo u identify the image by its URL. The pro perty is named list-style-image. If the bro wser c an’t find the URL o f the image yo u have selec ted, it uses the style type yo u spec ified in the list-style-type property.
UL { list-style-type: square; list-style-image: url(../images/blue-box.gif); }
List style position The fo llo wing example sho ws regular fo rmatting o f lists.
✦ Outside list item 1 has bullet o utside the margin o f subsequent lines
✦ Outside list item 2 has bullet o utside the margin o f subsequent lines This is ho w yo u spec ify it:
UL { list-style: outside; } The next example sho ws c o mpac t fo rmatting o f lists:
✦ Inside list item 1 has flush subsequent lines
331
332
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
✦ Inside list item 2 has flush subsequent lines Yo u c an spec ify c o mpac t fo rmatting by using the CSS pro perty c alled list-style. The c o de lo o ks like this:
UL { list-style: inside; } No tic e the pro perty is asso c iated with the UL element and no t with the LI elements.
List style shorthand As with many CSS pro perty gro ups, yo u c an use the list-style pro perty to gro up yo ur list fo rmatting. The list-style pro perty takes three values: the value o f the list-style-type pro perty, the value o f the list-style-position pro perty, and the value o f the list-style-image pro perty. The po ssible values o f the three do n’t c o nflic t; yo u c an spec ify o nly o ne value — o r any three values — and it will wo rk. An example fo llo ws:
UL { list-style: square outside url(../images/blue-box.gif); } OL { list-style: decimal inside; }
Adding Borders Bo rders are a great way to break up yo ur page and to draw attentio n to so mething impo rtant. CSS o ffers yo u superio r flexibility when yo u spec ify whic h (if any) rules and bo rders yo u want to inc lude with yo ur bo x-fo rmatted elements. Yo u c an c ho o se border-width pro perties, a border-color pro perty, a border-style pro perty, and a variety o f sho rthand no tatio ns to define bo rders.
Border width Yo u c an use five pro perties to define the width o f the bo rder. They are bordertop-width, border-right-width, border-bottom-width, border-left-width, and border-width. CSS is no thing if no t predic table. Yo u c an spec ify any o f the first fo ur o r yo u c an use the fifth o ne to spec ify up to all fo ur o f the widths in sho rthand, just as with the margin and padding pro perties.
Chapter 29 ✦ Formatting Paragraphs
If yo u spec ify o ne value fo r the border-width pro perty, all fo ur sides will be that width. If yo u spec ify two values fo r the border-width pro perty, the to p and bo tto m are assigned the first value, and the sides are assigned the sec o nd value. If yo u spec ify three values (and this is c o mpletely unintuitive), the to p is assigned the first value, the sides are assigned the sec o nd value, and the bo tto m is assigned the third value. In additio n to spec ifying a valid length (using o ne o f the measurements listed earlier), yo u c an also use o ne o f three keywo rds to instruc t the bro wser to render yo ur bo rder width: thin, medium, and thick. The default is medium. An example o f suc h a bo rder rendering fo llo ws:
border-width: border-width: thick */ border-width: 2px */ border-width: that order */
thin; medium thick;
/* all 4 sides will be thin */ /* top, bottom medium, sides
4px thin 2px;
/* top 4px, sides thin, bottom
3mm 4mm 2mm 1mm; /* top, right, bottom, left, in
Border color The border-color pro perty takes up to fo ur values; it wo rks exac tly like the border-width pro perty. Yo u c an spec ify bo rder c o lo r fo r all fo ur sides at o nc e o r fo r eac h side individually. The pro perty is c alled border-color. Here is what it lo o ks like in ac tio n:
border-color: #FF0000; red */ border-color: red blue red blue; borders red, sides blue */ border-color: yellow black; yellow, sides black */
/* makes all four borders /* makes top and bottom /* makes top and bottom
Border style The border-style pro perty tells the bro wser what kind o f bo rder to use. As with the border-width pro perty, yo u c an spec ify o ne to fo ur values. Netsc ape 4.7 suppo rts mo re styles then Internet Expo lo rer 5.0. Yo ur c ho ic es are as fo llo ws:
✦ none. No bo rder; o verrides border-width spec ific atio n. ✦ dotted. Bo rder is a do tted line. ✦ dashed. Bo rder is a dashed line. ✦ solid. Bo rder is a so lid line (the default).
333
334
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
✦ double. Bo rder is a do uble line. The border-width value spec ifies the to tal width o f bo th lines and the white spac e between them.
✦ groove. Bo rder is a 3D gro o ve o f the c o lo r assigned in border-color pro perty.
✦ ridge. Bo rder is a 3D ridge o f the c o lo r assigned in border-color pro perty. ✦ inset. Bo rder is a 3D inset o f the c o lo r assigned in border-color pro perty. ✦ outset. Bo rder is a 3D o utset o f the c o lo r assigned in border-color pro perty. border-style: solid none; /* makes top and bottom solid, none on sides */ border-style: ridge; /* ridge on all four sides */ border-style: dotted dashed solid /* top dotted, sides dashed, bottom solid */ border-style: solid dotted double dashed /* top, right, bottom, left in that order */
Shorthand techniques CSS pro vides several tec hniques fo r c reating sho rthand definitio ns related to bo rders. Fo ur pro perties — border-top, border-right, border-bottom, and border-left — c an be used to spec ify values fo r width, style, and c o lo r, in that o rder. A brief example fo llo ws:
border-top: thick dashed blue; border-bottom: thick dashed red; A border pro perty c an be used to set values fo r width, style, and c o lo r — but o nly if yo u want to assign the same values to all fo ur sides, as in the fo llo wing example:
border: thin solid black; solid, and black */ border: 6px double yellow; double, and yellow */
/* all four sides will be thin, /* all four sides will be 6px,
From Here CrossReference
Jum p to Chapter 33 and learn about using CSS for absolute positioning. Proceed to Chapter 30 and learn about CSS and tables.
Chapter 29 ✦ Formatting Paragraphs
Summary In this c hapter, yo u reviewed the CSS bo x-fo rmatting mo del. Yo u learned mo re abo ut spec ifying margins and padding fo r paragraphs. Yo u learned the units o f measurement to use when spec ifying many CSS pro perty values. Yo u also learned abo ut inc luding paragraph indentatio n, paragraph alignment, and the pro perty that spec ifies line spac ing. Yo u learned abo ut fo rmatting lists, either with the bullet o utdented o r flush with the text. Finally, yo u learned abo ut spec ifying bo rders fo r yo ur blo c k-level elements.
✦
✦
✦
335
30 C H A P T E R
Formatting Tables
✦
✦
✦
✦
In This Cha pter
I
n this c hapter, yo u learn abo ut using CSS to fo rmat tables. As yo u read in Chapter 20, CSS1 do es no t pro vide as many ways to affec t fo rmatting o f tables as it do es fo rmatting o f o ther elements. Fo rtunately, the W3C has remedied this pro blem with CSS2. As always, the transitio n isn’t seamless, bec ause no t all bro wsers fully suppo rt CSS2. This c hapter inc o rpo rates bo th CSS1 and CSS2 to sho w yo u ho w to fo rmat every aspec t o f yo ur HTML table.
Co ntro lling table alig nment Setting ho rizo ntal cell alig nment Setting vertical cell alig nment Specifying table and cell widths
Controlling Table Alignment CSS pro vides the align pro perty to enable yo u to spec ify table alignment. The align pro perty fo r tables wo rks exac tly as it do es fo r aligning paragraphs o r any o ther blo c k-level element. Yo u c an c ho o se to align the table o n the left, in the c enter, o n the right, o r fully justified ac ro ss the c anvas. Lo o k at the c o de fo r an example. Yo u c an spec ify the align pro perty fo r the TABLE selec to r, fo r a c lass o f the TABLE selec to r, o r fo r an ID that affec ts the TABLE element.
TABLE { text-align: center; } TABLE.right-leaning { text-align: right; } TABLE#full { text-align: justify; }
Adding cell spacing Defining cell padding Defining rules and bo rders Using co lo rs in tables
✦
✦
✦
✦
338
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
Setting Horizontal Cell Alignment Yo u c an spec ify ho rizo ntal c ell alignment in fo ur plac es: at the c ell level, at the ro w level, at the c o lumn level, o r at the ro w gro up level.
At the cell level Spec ifying alignment at the c ell level is easy. Inc lude the align attribute in the TD element. The pro blem with this is yo u c o uld end up defining this attribute in every single c ell. If yo u c an define this attribute at a higher level, this c an save yo u a lo t o f typing and reduc e the c hanc e o f intro duc ing erro rs into yo ur TABLE definitio n.
Using CSS, yo u c an mo ve so me o f this fo rmatting into c lasses. There is no c harac ter alignment in CSS, so so me fo rmatting wo uld have to remain in the HTML. The style sheet wo uld lo o k like this: Vacation Location Avg. Temp. Package Deal Ireland 68° $799.95 Greek Islands 84° $649.95 Cancun 85° $729.99
TD.left { align: left; } TH.center { align: center; } And the HTML wo uld lo o k like this:
Vacation Location
Chapter 30 ✦ Formatting Tables
Avg. Temp. Package Deal Ireland 68° $799.95 Greek Islands 84° $649.95 Cancun 85° $729.99
At the row level As yo u c an see in the previo us example, defining alignment at the c ell level is imprac tic al — espec ially fo r the first ro w, where every c ell has the same c lass. Mo ving alignment to the ro w level makes mo re sense. The style sheet wo uld no w lo o k like this:
TD.left { text-align: left; } TR.center TH.center { text-align: center; } And the HTML wo uld lo o k like this:
Vacation Location Avg. Temp. Package Deal Ireland 68° $799.95 Greek Islands 84° $649.95 Cancun 85° $729.99
339
340
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
No tic e the alignment fo r the first ro w was mo ved fro m the c ell level to the ro w level. Already, the HTML lo o ks better.
At the column level Unfo rtunately, no ne o f the o ther ro ws lend themselves to mo ving the alignment attribute to the ro w level. But all o f them share c o lumn fo rmatting. They all have a left c o lumn with left alignment; a c enter c o lumn with c harac ter alignment that lines up o n the degree sign (°), defined using the ° entity; and a right c o lumn with c harac ter alignment that lines up o n the dec imal po int. To take advantage o f c o lumn-level alignment, yo u have to define c o lumns. The previo us example do esn’t define c o lumns, but the fo llo wing example do es. All the alignment fo rmatting fo r ro ws after the first ro w is mo ved to the c o lumn level. The style sheet needs to be mo dified to lo o k like this:
COL.left TD.left { text-align: left; } TR.center TH.center { text-align: center; } Bec ause there is no c harac ter alignment in CSS, the fo rmatting fo r the sec o nd and third c o lumns wo uld still need to be spec ified in the HTML.
Vacation Location Avg. Temp. Package Deal Ireland 68° $799.95 Greek Islands 84° $649.95 Cancun 85° $729.99
Chapter 30 ✦ Formatting Tables
Even tho ugh the first ro w wo uld be affec ted by the alignment fo rmatting defined at the c o lumn level, the ro w-level alignment o verrides the c o lumn-level fo rmatting, so all the c ells in the first ro w will have c enter alignment. Finally, the HTML lo o ks like so mething yo u pro bably wo uldn’t mind maintaining.
At the row group level or column group level The previo us example do esn’t lend itself to the use o f the THEAD, TFOOT, TBODY, o r COLGROUP elements to spec ify alignment, but yo u c an spec ify alignment at either the ro w gro up level o r the c o lumn gro up level.
COLGROUP.center { text-align: center; } TBODY.right { text-align: right; }
Setting Vertical Cell Alignment New to CSS2 is the vertical-align pro perty. Yo u c an spec ify vertic al alignment (c alled valign in HTML 3.2) in yo ur style sheet to apply to TD elements. See the c o de example fo r ho w to implement the TD elements.
TD.mid { vertical-align: middle; } Yo u may use a keywo rd o r spec ify a perc entage value. The keywo rds are as fo llo ws:
✦ top. Sets the to p o f the c ell to align with the to p o f the ro w in whic h the c ell is defined.
✦ middle. Sets the middle o f the c ell to align with the middle o f the ro w in whic h the c ell is defined.
✦ bottom. Sets the bo tto m o f the c ell to align with the bo tto m o f the ro w in whic h the c ell is defined.
✦ baseline. This is a relative spec ific atio n. The baseline o f the ro w is the baseline o f the to p line o f the text in the ro w. The baseline o f the to p line o f text in the ro w depends o n the fo nt sizes used in eac h o f the c ells. The bro wser determines the baseline o f the first ro w o f text and aligns the baseline o f the text in this c ell with the baseline o f the ro w.
✦ sub. This subsc ripts the c ell. ✦ super. This supersc ripts the c ell.
341
342
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
✦ text-top. Aligns the to p o f the c ell with the to p o f the fo nt o f the highest text in that ro w.
✦ text-bottom. Aligns the bo tto m o f the c ell with the bo tto m o f the fo nt o f the lo west text in that ro w.
Specifying Table and Cell Widths Yo u c an spec ify widths fo r bo th the table and individual c ells. With c ell spec ific atio ns, spec ify width at the c o lumn level o r at the c ell level. Fo r bo th c ells and tables, yo u c an either spec ify widths as abso lute values o r as relative values.
Absolute values Befo re yo u dec ide to spec ify yo ur table width using abso lute values, be sure yo u kno w ho w eac h c ell will render. Otherwise, yo u c o uld end up with c ells that aren’t wide eno ugh to ho ld an entire wo rd. Tables do n’t do a go o d jo b o f breaking wo rds at the syllable o r hyphenating yo ur wo rds when yo u spec ify to o small a width fo r c ells. In fac t, if yo u spec ify an abso lute value fo r c ell height and an abso lute value fo r c ell width, yo ur c ell might be to o small to display all yo ur text. In this c ase, the text might spill o ver into the next c ell, c ro ssing rules!
Vocabulary antidisestablishmentarianis m
When yo u spec ify abso lute widths, yo u are spec ifying them in pixels. A sc reen c an be 640 pixels wide; 800 pixels wide; o r 1,024 pixels wide (even mo re fo r super-highreso lutio n mo nito rs), but the bro wser will no t always be set to fill the entire sc reen. Yo u have no way o f predic ting ho w wide the bro wser windo w will be. The attribute used fo r spec ifying width is the width attribute.
In the previo us example, the table is set to 200 pixels wide, the first c o lumn is 100 pixels wide, and the sec o nd and third c o lumns are eac h 50 pixels wide. No rmally yo u wo uldn’t spec ify bo th TABLE width and COL width abso lutely.
... rest of table...
Chapter 30 ✦ Formatting Tables
Relative values Whenever po ssible, yo u want to use relative values to spec ify table width. Yo u c an spec ify the table width as a perc entage o f the sc reen.
... rest of table...
Yo u c an also spec ify relative c ell widths within a table fo r whic h yo u have spec ified an abso lute width. The example in the previo us sec tio n abo ut abso lute widths wo uld pro bably be better defined as fo llo ws:
Ano ther way to define c ell widths is to use the 0* value. The 0* value is the way yo u instruc t the bro wser to use the minimum width nec essary to c o nstruc t a table.
... rest of table...
... rest of table...
Specifying width in style sheets Yo u c an also use style sheets to spec ify widths. The pro perty is c alled width. The last two examples c o uld be rewo rked, using style sheets, into the fo llo wing c o de:
... rest of table...
The style sheet fo r these two tables wo uld lo o k like this:
... rest of table...
TABLE.this-one { width: 200;
343
344
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
} #half { width: } #quarter { width: } COL.min { width: } COL.this-one { width: }
50%; 25%; 0*; 100;
Adding Cell Spacing Yo u c an spec ify c ell spac ing within a table. The pro perty is c alled ce ll spacing (c ell spac ing as an attribute o f the TABLE element). Ce ll spacing is the spac e between the bo rder o n the inside o f o ne c ell and the bo rder o n the inside o f the next c ell o r the o utside bo rder o f the table. When yo u define bo rders, bo rders are ac tually aro und eac h c ell, and a separate bo rder is aro und the entire table. If the bo rders are thin and there is no c ell spac ing, it will lo o k like it is o ne line that surro unds the c ells and attac hes to the bo rder aro und the table. The mo re c ell spac ing yo u define, the c learer it will be that these are separate lines.
The previo us table has no c ell spac ing.
The previo us table has c ell spac ing. The spac ing attribute is defined as part o f the TABLE element as fo llo ws:
Chapter 30 ✦ Formatting Tables
Or, as part o f a style sheet:
TABLE { cellspacing: 3 } New to CSS2, yo u c an spec ify different values fo r ho rizo ntal spac e between c ells and fo r vertic al spac e between c ells. The first value supplied to the cellspacing pro perty is fo r ho rizo ntal c ell spac ing; the sec o nd is fo r vertic al c ell spac ing. If yo u pro vide o nly o ne, it applies to bo th kinds o f c ell spac ing. Also new to CSS2, yo u c an c o llapse bo rders, remo ving the c ell spac ing alto gether. This makes yo ur table lo o k mo re like the way a table appears in a wo rd-pro c essing do c ument. The pro perty is c alled border-collapse. This applies o nly to table elements: TABLE, COLGROUP, COL, THEAD, TFOOT, TBODY, TR, TH, and TD.
TABLE { border-collapse: collapse; } The default value o f border-collapse is se parate . Yo u c an c ho o se between the keywo rds co llapse and se parate .
Defining Cell Padding Cell padding is the white spac e between the c o ntents o f a c ell and the bo rders o f a c ell. Cell padding c an be defined at the TABLE level, the c o lumn gro up o r c o lumn level, the ro w gro up o r ro w level, o r the c ell level. By default, bro wsers render tables witho ut any c ell padding. This tends to make the widest element in eac h c ell lo o k c ro wded. The pro perty is the same padding pro perty used to define padding fo r any blo c klevel element that takes advantage o f the bo x fo rmatting mo del.
TABLE { padding: 1em; } Even if yo u spec ify an abso lute width fo r a table o r a c ell, the padding attribute has an effec t. If yo u spec ify an abso lute width and padding, the bro wser will make the width o f the c ell in whic h the c o ntents appear smaller, allo wing ro o m fo r the padding.
345
346
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
Using Colors in Tables Within a table, yo u c an assign c o lo r to several elements. These elements inc lude the bo rders, the rules, the bac kgro und c o lo r, and the text c o lo r. Yo u c an spec ify all these things as the same fo r a table o r yo u c an spec ify different c o lo rs fo r every rule, bo rder, c ell text c o lo r, and c ell bac kgro und c o lo r. The pro perties are the same as fo r the rest o f CSS: color, background-color, and the variatio ns o n the border/border-color pro perty.
COLGROUP { border: thin solid black; background-color: white; color: black; } COLGROUP.highlight { border-left: thick solid blue; background-color: yellow; color: navy; }
Defining Rules and Borders By default, tables in HTML have a bo rder-width set to zero . This means all rules and bo rders are turned o ff. If yo u take the small ac tio n o f setting bo rder-width to 1, yo u will suddenly have bo th bo rders and rules. Rule s are the lines between c ells. The c apability to define these independently o f the bo rder, whic h is the line aro und the table, is new to HTML 4. The three attributes fo r defining bo rders are: rules, frame, and border. The bo rder attribute defines the width o f the frame and rules; the value must be defined as a valid measurement using the units listed in Chapter 29.
The frame attribute takes a keywo rd value; valid values are as fo llo ws:
✦ void. No bo rders are displayed o n the table; this is the default value. ✦ above. Only a to p bo rder is displayed. ✦ below. Only the bo tto m bo rder is displayed. ✦ hsides. The to p and bo tto m bo rders are displayed. ✦ vsides. The right and left bo rders are displayed. ✦ lhs. Only the left-hand side bo rder is displayed. ✦ rhs. Only the right-hand side bo rder is displayed. ✦ box. All fo ur sides are displayed. ✦ border. All fo ur sides are displayed.
Chapter 30 ✦ Formatting Tables
The rules attribute also takes a keywo rd value. The rules attribute spec ifies internal lines. Valid values fo r the rules attribute are as fo llo ws:
✦ none. No rules are displayed. This is the default value. ✦ group. Rules are displayed o nly between gro ups. ✦ rows. Rules are displayed between ro ws. ✦ cols. Rules are displayed between c o lumns. ✦ all. Rules are displayed between all c ells.
From Here CrossReference
Jum p to Chapter 33 and learn about CSS absolute-positioning tricks. Proceed to Chapter 31 to learn about using CSS to define fonts.
Summary Using a c o mbinatio n o f CSS1, CSS2, and HTML 4, yo u c an define the fo rmatting o f yo ur tables. Co ntro lling table alignment, ho rizo ntal alignment o f c ell c o ntents in yo ur c ells, and vertic al alignment o f c ell c o ntents in yo ur ro ws is relatively straightfo rward. In this c hapter, yo u learned abo ut spec ifying table and c ell widths as bo th relative and abso lute values. Yo u also learned abo ut c ell spac ing, c ell padding, defining rules and bo rders, and defining c o lo rs in tables.
✦
✦
✦
347
31 C H A P T E R
Adding Fonts
C
SS gives yo u inc redible flexibility in defining fo nts fo r yo ur pages. Yo u c an spec ify multiple fo nt fac es, sizes fo r eac h element, the width between letters, and the spac ing between wo rds. Yo u c an even add interesting typo graphic al effec ts, suc h as all c aps o n the first line (whic h many magazines and newspapers use), and a first letter that spans multiple lines. This c hapter explains ho w to c reate all these effec ts using CSS.
Introducing Fonts Mo st peo ple think o f fo nts as letters. Fo nts are really the representatio n o f letters with glyphs (pic tures). The letters a, b, and c c an lo o k very different in Arial, Times New Ro man, and Luc ida Co nso le. Even tho ugh the letters are the same, the glyphs are different.
Font families The two majo r fo nt families are se rif and sans se rif. Serif fo nts inc lude little dec o ratio ns o n the edges o f letters. The mo st c o mmo n serif fo nt is Times Ro man o r Times New Ro man, depending o n yo ur platfo rm. Sans serif (meaning witho ut serif) fo nts are muc h plainer. As yo u c an see in Figure 31-1, Arial and Luc ida Co nso le are sans serif fo nts. When yo u send text o ver the Internet, no rmally yo u send o nly yo ur c ho ic es o f the letters that make up the text. The rec ipient’s bro wser renders yo ur text by using whatever fo nt fac e and size its o wner has c o nfigured it to use. Until rec ently, yo u c o uldn’t send the c ho ic e o f fo nt — and yo u c ertainly c o uldn’t send the ac tual fo nt. With CSS, Web autho rs have inc reasing c o ntro l o ver fo nt c ho ic e.
✦
✦
✦
✦
In This Cha pter Intro ducing fo nts Fo nts o n the W eb Fo nt selectio n co nsideratio ns Co ntro lling fo nt selectio n Cho o sing fo nt sizes Using co ndensed and expanded fo nts Adding small caps and o ther text deco ratio ns
✦
✦
✦
✦
350
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
Figure 31-1: Sam ple fonts displayed in Netscape Com m unicator 4.7
One reaso n text renders so quic kly in yo ur bro wser is that no thing mo re than c ho ic es o f letters — no t the ac tual glyphs — are sent to yo ur c o mputer. With CSS, the Web develo per no w has fo ur po ssible c ho ic es:
✦ Send text witho ut spec ifying a fo nt ✦ Send text that spec ifies whic h fo nt the bro wser sho uld use (usually as a list o f c ho ic es in c ase the first c ho ic e isn’t present)
✦ Rely o n CSS2’s suppo rt fo r intelligent matc hing o r fo nt synthesis, if the spec ified fo nt is unavailable o n the target c o mputer — if suppo rted by the bro wser
✦ Send the text with the URL o f a do wnlo adable fo nt (whic h requires spec ialized so ftware)
Chapter 31 ✦ Adding Fonts
Fonts versus the image of fonts Mo st Web develo pers who want to inc lude fo nts o ther than tho se c o mmo nly available c reate their text as graphic s and send graphic s instead o f text. This appro ac h c an substantially slo w do wn the lo ad time o f their pages. On the upside, it do es guarantee that anyo ne with a graphic s-c apable bro wser will see the fo nt the same way. If yo u want to sho w a small amo unt o f a fo reign language, using an image o f text is pro bably the best way to go ; yo ur visito rs need no t lo ad a spec ial fo nt set o r run any partic ular o perating system.
Using Local Fonts If yo u dec ided yo u do n’t want to be stuc k using the default fo nt o n the system — and yo u do n’t want to play games with c reating images o f text instead o f sending the text — then yo u may want to take advantage o f the CSS c apability that spec ifies whic h lo c al fo nts the system o ught to use. Bec ause yo u c an’t kno w whic h fo nts are installed o n the bro wser — and yo u c an’t even kno w whether the bro wser is a PC, a Mac , o r so mething else (unless yo u are develo ping fo r an intranet) — CSS gives yo u the o ptio n o f spec ifying a list o f fo nts fro m whic h the bro wser c an selec t. It will use the first listed fo nt that matc hes o ne c urrently installed. To be even mo re tho ro ugh, after spec ifying eac h spec ific fo nt name yo u wo uld prefer the bro wser to use, yo u c an spec ify fo nt family names; do ing so ensures that if no ne o f yo ur spec ified fo nts is present, the bro wser selec ts so mething that at least lo o ks similar.
Font-Selection Considerations There are two majo r fac to rs to c o nsider when selec ting the fo nts fo r yo ur page. The first relates to aesthetic s:
✦ Do the fo nts o n the page wo rk to gether? ✦ Ho w many different fo nts wo rk o n o ne page? ✦ Sho uld yo u mix serif and sans serif fo nts? The sec o nd fac to r relates direc tly to whether the bro wser c an re-c reate the page as yo u initially c o nc eived it.
351
352
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
The aesthetics of font selection Different fo nts c o nno te different qualities. Do yo u want the artistic sweep o f a c ursive fo nt suc h as Brush Sc ript? Do yo u want the c lean lines o f a sans serif fo nt suc h as Helvetic a? There are go o d reaso ns to use just abo ut any fo nt, but yo u’ll want to make sure the fo nt yo u selec t helps c o nvey yo ur message, rather than getting in the way o f it. Co nsider whether to use the same fo nt fo r headings as yo u do fo r paragraph text. Serif fo nts suc h as Times Ro man (whic h have little ho o ks o n the ends o f the letters) are easier to read. Sans serif fo nts suc h as Helvetic a are c leaner lo o king and leave mo re white spac e. Fo r these reaso ns, many peo ple c ho o se to use serif fo nts fo r paragraph text and sans serif text fo r headings. Yo u c an use mo re than o ne fo nt family in yo ur do c ument, but no rmally it’s wise to avo id using mo re than two fo nt families in o ne do c ument. To o many fo nt families c an c o ntribute to a c luttered o r diso rganized lo o k.
Availability of local fonts Even if yo u c an c reate the perfec t page, with just the right fo nts, o n yo ur lo c al system, what c an yo u do to ensure that the bro wser renders yo ur page as yo u wo uld like it to be rendered? Yo u c an send a list o f fo nts yo u wo uld like the bro wser to use, and the bro wser will use the first o ne in yo ur list that it has. Yo u aren’t limited in ho w many yo u c an list. If the default bro wser fo nt wo uld be no tic eably wo rse, yo u wo uld be well advised to list every fo nt that wo uld wo rk well.
Controlling Font Selection Yo u c an use the fo nt-family pro perty to indic ate whic h fo nt yo u want the bro wser to use. Yo u c an identify spec ific fo nts, fo nt families (serif, sans serif, c ursive, fantasy, mo no spac e), o r bo th. If yo u list bo th, inc lude the fo nt families at the end so the bro wser will lo o k fo r the mo st prec ise matc h befo re it uses a generic fo nt family.
P { font-family: “Bookman Antiqua”, Georgia, “Times New Roman”, “Times Roman”, Times, serif; } The rule just given tells the bro wser the paragraph text sho uld be rendered with Bo o kman Antiqua fo nt; if that is no t available, Geo rgia; if Geo rgia is no t available, Times New Ro man; if Times New Ro man is no t available, Times Ro man; if Times Ro man is no t available, Times — o r, if no ne o f tho se fo nts are available, any serif fo nt. No te, any fo nt name with mo re than o ne wo rd in it sho uld be c o ntained in do uble quo tes.
Chapter 31 ✦ Adding Fonts
Tip
Internet Explorer does a pretty good job of handling font fam ilies. It does provide a script font w hen you specify cursive, but it gives you the sam e font for fantasy as for sans serif. Netscape gives you sans serif for both cursive and fantasy font fam ilies. How ever, if you specify “Com ic Sans MS” font (w hich is part of the fantasy fam ily), it w ill w ork on both Netscape and Internet Explorer. The m oral of the story: Specify the exact font you w ant used; don’t rely on font fam ilies.
Choosing Font Sizes Yo u c an set the fo nt size with the fo nt-size pro perty. Setting the fo nt size is useful bec ause yo u c an be sure the bro wser will lay o ut headings as yo u want them to appear. No rmally, H6 elements render the same as regular paragraph text. Yo u c an c hange this and give greater impo rtanc e to H6 elements by inc reasing the fo nt size, c hanging the fo nt style, o r inc reasing the line height. The fo nt-size pro perty takes a value in po ints (pt):
H6 { font-size: 14pt; }
Using Condensed and Expanded Fonts Yo u c an c o ndense and expand fo nts bo th ho rizo ntally — by c o mpressing o r spreading o ut the letters o r the wo rds — and vertic ally — by dec reasing o r inc reasing the white spac e between lines, using CSS. Table 31-1 sho ws eac h type o f pro perty at wo rk.
Table 31-1 Expanding and Condensing Lines, Words, and Letter Spacing Type of Spacing
CSS
Example
Expanding letter spacing
P.wide {letter-spacing: .5pt; }
This is an exam ple of increased letter spacing.
Condensing letter spacing
P.narrow {letter-spacing: -.8pt; }
This is an exam ple of decreased letter spacing. Continued
353
354
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
Table 31-1 (continued) Type of Spacing
CSS
Example
Condensing space betw een row s
P.crowded { line-height: 10pt; }
This is an exam ple of decreased line height; notice the lines really crow d each other.
Expanding space betw een row s
P.speaking-slowly { line-height: 18pt; }
This is an exam ple of increased line height; notice the lines are a bit m ore spread out.
Expanding space betw een w ords
P.speaking-slowly { word-spacing: 1em; }
This is an exam ple of expanded w ord spacing.
Condensing and expanding horizontally To c o ndense o r expand fo nts ho rizo ntally (meaning the letters appear c lo ser to eac h o ther than they no rmally wo uld), use the letter-spac ing pro perty to add to the default value o f spac e between letters.
H1 { letter-spacing: .2em; } In the prec eding example, the letter spac ing will be inc reased by 0.2em fo r H1 elements.
P.legal { letter-spacing: -.2em; } In the prec eding example, the letter spac ing will be dec reased by 0.2em fo r P elements with a c lass o f le gal. Yo u c an also expand o r c o ndense fo nts by inc reasing o r dec reasing the white spac e between wo rds. The pro perty fo r this is c alled wo rd spacing. It wo rks like letter spac ing, whic h adds to the default amo unt o f white spac e between wo rds.
P.spread-out { letter-spacing: .2em; word-spacing: .5em; }
Chapter 31 ✦ Adding Fonts
The previo us example c reates a c lass c alled spre ad o ut, in whic h there is an extra 0.2em o f spac e between letters and an extra 0.5em o f spac e between wo rds. Tip
If you spread out letters, you probably w ant to spread out w ords as w ell, or it m ight not be clear w here one w ord ends and the next one begins.
Condensing and expanding vertically Co ndensing o r expanding text o n the page vertic ally — that is, leaving mo re o r less white spac e between lines — is easily ac c o mplished with the line-height pro perty. By default, line height is two pixels greater than fo nt-size. Fo r example, if yo u have a 12pt fo nt fo r yo ur paragraph text, the bro wser will auto matic ally render the text with 14pt line height — 12 po ints fo r the letter and o ne blank po int to pro vide blank spac e at bo th the to p and bo tto m o f the letter. If yo u want to c o ndense the line height, yo u c an do so by spec ifying a line height less than 2 po ints greater than the fo nt size. If yo u want to inc rease the white spac e between lines, inc rease the line height to mo re than two po ints greater than the fo nt size.
P { font-size: 12pt; line-height: 14pt; } P.double { font-size: 12pt; line-height: 24pt; } P.smooshed { font-size: 12pt; line-height: 12pt; } Fo r c larity in this example, the fo nt size is repeated fo r eac h c lass, but it needn’t be repeated. The do uble c lass do uble-spac es the 12pt text. The smo o shed c lass leaves no white spac e between lines.
Adding Small Caps and Other Decorations Yo u c an do two very c o o l things with CSS. They take advantage o f the pseudo elements c alled first-line and first-letter. Yo u learned abo ut pseudo -c lasses in Chapter 26; pseudo -c lasses are related to the A element. The desc ripto rs fo r these c lasses ( A:link, A:visited, A:active) c an be assigned their o wn values to further c usto mize the lo o k o f linked text.
355
356
Part IV ✦ Enhancing Presentation with Cascading Style Sheets
Changing the first line Pseudo -elements relate to the typo graphic al layo ut o f yo ur page. The pro perty c alled first-line enables yo u to simulate newspapers and magazines, whic h o ften apply a different typo graphic al effec t to the first line o f text in a paragraph (all c aps, fo r example).
P.first:first-line { font-style: small-caps; } When yo u have this rule in yo ur style sheet, yo u c an use the fo llo wing HTML:
Changing the first letter The pro perty c alled first-letter enables yo u to c reate text with a first letter that extends belo w the first line. Fo r example, in many magazines, the first letter o f the first paragraph in an artic le is two lines high.
P.drop-cap:first-letter { font-size: 36pt; float: left; } With this rule in yo ur style sheet, yo u c an use the fo llo wing HTML:
I
n Chic ago to day, it was anno unc ed that peo ple with mo re mo ney live in nic er neighbo rho o ds.
Chapter 31 ✦ Adding Fonts
From Here CrossReference
Proceed to Chapter 32 and explore the essentials of Web page design. Refer back to Chapter 22 to review fram es.
Summary In this c hapter, yo u learned abo ut spec ifying the fo nts yo u want used with yo ur Web page. Yo u also learned that fo nts are really pic tures o f letters c alled glyphs. This c hapter disc ussed the fac to rs yo u sho uld c o nsider when selec ting fo nts and the number o f fo nt fac es yo u pro bably do n’t want to exc eed. Yo u learned to spec ify fo nt size and fo nt spac ing (bo th ho rizo ntally and vertic ally), and yo u learned to add very c o o l text dec o ratio ns, suc h as all c aps o n the first line, o r a first letter that spans several ro ws.
✦
✦
✦
357
32 C H A P T E R
Essentials of Web Page Design
✦
✦
✦
✦
In This Cha pter
A
re yo u ready to design a page? Ho w yo u design yo ur page is a tactical de cisio n, whic h this c hapter c o vers .
Yo ur page design must be fo c used to c o ntribute the feelings yo u want yo ur visito rs to have abo ut yo ur site. It needs to inc o rpo rate c o nsistenc y, predic tability, navigability, and a c lear purpo se with visual appeal and interac tivity. When yo u finish this c hapter, yo u’ll be ready to start designing yo ur c o ntent.
W hat’s in a pag e? Fo cusing o n yo ur messag e The shell g ame Co nsistency Predictability
What’s in a Page? The first thing yo u must do is dec ide what yo u want to c o mmunic ate in eac h page. As yo u break yo ur text into separate tho ughts, a pro c ess referred to as c hunking, the result will be a number o f pages. Eac h page will c o ntribute in so me way to the o verall go al o f yo ur site, either direc tly o r indirec tly. Figure 32-1 sho ws a diagram o f a listing page. What needs to be in a page? Generally, yo u want all yo ur pages to have c ertain items. These inc lude the fo llo wing:
✦ The name o f the o rganizatio n o r perso n publishing the page. Remember, with searc h engines indexing yo ur site, so meo ne c an jump into the middle o f yo ur site. If yo u do n’t say who yo u are o n every page, visito rs may no t kno w.
✦ A way to get to yo ur Welc o me page. This fo llo ws fro m the previo us o ne. Do n’t assume everyo ne c o ming to yo ur site is c o ming thro ugh the fro nt do o r.
N avig ability Interactivity Speed Desig n g uidelines Future expandability Desig ning an effective welco me pag e Splash screens Testing
✦
✦
✦
✦
362
Part V ✦ Lay It Out Like the Pros
Over the Web Product Listing Pages Product listing
Stay in touch
Instant feedback
Bulk rate
Figure 32-1: A detail from the fully developed Over the Web site m ap
Other o ptio nal elements inc lude the fo llo wing:
✦ Yo ur lo go ✦ Ho w to c o ntac t yo u ✦ A navigatio n bar o r navigatio n butto ns ✦ A link to a table o f c o ntents ✦ A link to a site searc h page ✦ A link to a site map ✦ A dro p-do wn list o f plac es to go ✦ Co ntent, if a terminal page ✦ Links to a gro up o f pages, if a links page
Focusing on Your M essage No w that yo u have a page-size mo rsel o f info rmatio n, yo u sho uld have an idea o f what the message o f that page is. If yo u do n’t kno w, c o nsider ho w it fits into the site. If yo u do n’t think it c o ntributes to the o verall go als o f the site in so me way, dro p it. Everything yo u put o n yo ur page sho uld c o ntribute in so me way to c o mmunic ating yo ur message. One o f the sec rets o f c reating c o nsistent, easily navigated, visually appealing, c o mpelling sites is to limit the amo unt o f c o ntent o n eac h page.
Keeping it to the point (your left brain) Yo ur message needs to be sho rt and sweet. If yo u find yo u have to o many different things to c o mmunic ate in yo ur page, take o ne o f three ac tio ns:
Chapter 32 ✦ Essentials of Web Page Design
1. Unless your page is a ter m ina l p a ge, you can group related material and link to it. Be c areful abo ut adding to o many layers o f linking pages, tho ugh. Whenever po ssible, gro up yo ur links so even tho ugh the list o f links might be lo ng, yo ur visito rs c an still find what they want relatively easily. The nic est way to do this is by using dynamic HTML, whic h is disc ussed in Part VII. The next best thing is to give a list o f the gro ups o f links o n yo ur page at the to p o f yo ur page and then use internal links (remember learning abo ut them in Chapter 3?) to jump within yo ur page to the gro up o f links asso c iated with the sho rt list.
2. Decide what is important and forget about the rest. Yo u keep reading this, do n’t yo u? Simply to o muc h info rmatio n is o n mo st sites. Unnec essary info rmatio n do es no t help yo ur visito r understand yo ur message. Unnec essary info rmatio n just c lutters.
3. Break your material into more than one page. We put this last bec ause if yo u’ve bro ken yo ur material into separate tho ughts (c hunking) and yo u still think yo u have to o muc h to put into o ne page, then yo u pro bably have material that isn’t well suited to hypertext. Or, yo u have material that will be printed, and yo ur visito rs will apprec iate yo u no t breaking up yo ur material if they plan to print it. Definition
Terminal page. A term inal page is a page w hose prim ary function is to provide content, rather than to provide links. This is w hat your visitors cam e for: content. Your site is com posed of a Welcom e page, linking pages, and term inal pages. You can visualize the Welcom e page as the root of a tree, the linking pages as the trunk and branches, and the term inal page as the leaves.
Go with the feeling (your right brain) What kinds o f tho ughts and feelings do yo u want to c o nvey with yo ur page? What adjec tives do yo u want peo ple to use when they desc ribe yo ur site? Yo ur page design will evo ke c ertain feelings in yo ur visito r, even if yo u do n’t want it to do this. What kinds o f feelings do yo u get fro m eac h o f the fo llo wing?
✦ White bac kgro und with blac k text, Helvetic a fo nt ✦ Cream bac kgro und with bro wn text, brush sc ript fo nt ✦ Co o l gray bac kgro und with burgundy and blac k lines breaking up the blac k text, fo nt that lo o ks like printing
✦ Tan bac kgro und, fo rest green text, mustard-c o lo red lines and ac c ents
363
364
Part V ✦ Lay It Out Like the Pros
Yo ur c o lo rs, ac c ents, graphic s, and text style and size c an all c o ntribute to yo ur message. They make an impressio n o n yo ur visito rs whether o r no t yo u intend them to do so . Do n’t take sho rtc uts here.
When to ask for help If, after reading thro ugh this c hapter, yo u dec ide yo u are simply no t a de signe r, and many o f us are no t, then hire so meo ne to pro vide just the lo o k o f the page. Yo u c an do everything else with the HTML; yo ur designer c an just c reate the style sheet and the graphic s. This is to o impo rtant to take sho rtc uts. Ho w do yo u find a go o d designer? Surf the Web. If yo u find a site that rings yo ur bell, write to the Webmaster and find o ut who designed it. Designers eac h have their o wn lo o ks. Find a designer who has the lo o k yo u want. Pro fessio nal designers o ften leave their signatures o n the site, as an artist signs a painting. Lo o k fo r this. Explain that yo u will c reate the site and all yo u are lo o king fo r is the design wo rk. It wo n’t c o st that muc h. The labo r-intensive part is c reating and maintaining the HTML. Note
One respected professional Web designer, Tam ra Heathershaw -Hart, had this to say about the costs of creating versus m aintaining a Web site: “I’ve found that for m ost 20-page sites, graphic design (and the m anagem ent of getting the design) takes 50 percent of the cost. Another 30 percent is HTML and production, and 20 percent is for content creation. Because graphics are so subjective (unlike a typo), there’s a lot of overhead in the graphics production process. It also usually takes 4–6 w eeks to get a design from first m eeting to HTML com ps —producing the pages is quick once that’s all done.”
Lead me not into temptation It’s easy to get distrac ted fro m the message o f yo ur page when yo u start thinking abo ut graphic s, fo nts, c o lo rs, animatio ns, and so fo rth. Yo u need to balanc e these c o mpeting interests. The HTML 4 Way helps relieve yo u o f this temptatio n. Yo u c an ac tually separate yo ur right-brain wo rk (design) fro m yo ur left-brain wo rk (c o ntent and struc ture) by using style sheets. To help yo u stay fo c used, settle o n yo ur design and mo ve o n. Co mmit to a design and do n’t go bac k and fiddle with it. Yo u c an easily c hange the style sheet later, but yo u will have mo re wo rk if yo u c hange the basic design. The best way to avo id the c o nstant temptatio n to add nic e-lo o king things to yo ur site is to divide the wo rk o f yo ur site between two peo ple o r teams. This way the perso n respo nsible fo r the c o ntent wo n’t get o ff trac k. And, mo st impo rtant, the site will be finished — at least fo r a mo ment! Later in this c hapter, we give so me attentio n to the myth o f Web site c o mpleteness. Yo u will be relieved to kno w yo u aren’t the o nly o ne who feels like yo ur site is never do ne.
Chapter 32 ✦ Essentials of Web Page Design
The Shell Game Is there any go o d way to assure c o nsistenc e, predic tability, and easy navigatio n fro m all the pages o f a site? Yo u bet! Use a shell. Yo ur page has basic ally three types o f pages:
1. A Welc o me page 2. Links pages 3. Terminal pages Eac h o f these three types o f pages requires a slightly different design. Page shells — o r templates — pro vide the c o nsistenc y yo u need. The wo rd she ll is mo re ac c urate than the wo rd te mplate bec ause templates traditio nally have fo rmatting info rmatio n in them. Bec ause The HTML 4 Way pulls all this fo rmatting o ut, what is left is a shell o f a page. Lo o k at the three sc reen c aptures, sho wn in Figures 32-2, 32-3, and 32-4. They sho w the page design fo r eac h o f the three types o f pages fo r this site. Wo uldn’t it be easy to c reate a great-lo o king site if yo u c o uld insert yo ur c o ntent into shells that lo o ked like this?
Figure 32-2: This Welcom e page isn’t really a shell, because there w ill only be one, but it is consistent w ith the design of the rest of the site.
365
366
Part V ✦ Lay It Out Like the Pros
Figure 32-3: Links pages share the look of the Welcom e page.
Figure 32-4: Term inal pages carry out the sam e design them e.
Chapter 32 ✦ Essentials of Web Page Design
Consistency Yo u want to make sure yo ur entire site has the same lo o k. No t just in the big pic ture, but in the details. Fo rtunately, style sheets c an help yo u here. Yo u c an assure that all yo ur paragraphs have the same level o f indentatio n and the same amo unt o f white spac e abo ve and belo w them. As a Webmaster, yo u do have to make sure everyo ne develo ping c o ntent fo r yo ur site understands when to use the paragraph element and when to use the blo c kquo te element. Veteran Web develo pers have had to use a lo t o f tric ks in the past to get paragraphs to lo o k nic e; o ne o f these tric ks was using the blo c kquo te element to fo rmat paragraphs. This is a habit yo u sho uld help them break. Figure 32-5 illustrates the pro blem o f distinguishing o ne fro m the o ther.
Figure 32-5: Are these paragraphs or blockquotes? You’d have to view the source to find out.
Applying a style sheet to a page with paragraphs fo rmatted with the blo c kquo te element c an have unpredic table and unattrac tive results.
367
368
Part V ✦ Lay It Out Like the Pros
Predictability No o ne really likes surprises. Elements o f yo ur page sho uld behave the way visito rs expec t. Do n’t fo rmat text in blue with an underline, bec ause it will lo o k the way visito rs expec t links to lo o k, but wo n’t link. Do n’t c reate butto n-lo o king designs with text in yo ur graphic unless yo ur graphic is also an imagemap. On the o ther side o f the c o in, do n’t fo rmat yo ur links to be the same c o lo r as yo ur o ther text o r visito rs wo n’t kno w to c lic k them. Also , while subtlety is nic e, do n’t make the butto ns o n yo ur imagemaps so subtle that no o ne wo uld think to c lic k them. The Web is a fabulo us platfo rm and is unique amo ng platfo rms bec ause yo ur visito rs do n’t have to learn to use a new interfac e to view yo ur material. In the o lden days, befo re the Web, every so ftware pro gram had its o wn interfac e. This meant users o f the so ftware had to learn new interfac es every time they wanted to use new so ftware. With the Web, if yo u give users what they expec t, the interfac e is a no nissue fo r yo u. Take advantage o f it.
Navigability Bec ause this is the tac tic s c hapter, this is where yo u need to think abo ut ho w yo u are go ing to implement them within yo ur page design. Earlier in this c hapter, so me attentio n was devo ted to navigatio nal c o ntro ls. Whic h o nes sho uld yo u use? Ho w muc h sc reen real estate sho uld yo u devo te to them? Yo u c ertainly need to use so me navigatio nal c o ntro ls. The simplest kind to use is a navigatio n bar o r navigatio n butto ns. Other o ptio ns inc lude a table o f c o ntents, site searc hing, and site maps.
Navigation bar or navigation buttons The simplest kind o f navigatio nal to o l to use is the navigatio n bar. A navigatio n bar c an be either text, text in a table, o r an imagemap. The navigatio n bar sho uld appear o n every page in the same plac e o r plac es. Many sites use frames to keep the navigatio n bar o r butto ns statio nary while the c o ntent and links mo ve into and o ut o f a different frame. The navigatio n bar with text in a table, sho wn in Figure 32-6, is in a different frame fro m the c o ntent o n the right. Figure 32-7 sho ws a navigatio nal bar used with an image map. CrossReference
Jum p to Chapter 22 for a refresher on the pros and cons of using fram es.
Chapter 32 ✦ Essentials of Web Page Design
Figure 32-6: Over the Web uses a navigation bar w ith text in a table.
Figure 32-7: The University of Virginia uses a navigation bar w ith an im agem ap.
369
370
Part V ✦ Lay It Out Like the Pros
Definition
Frames. Fram es are a w ay to have tw o different HTML files open at the sam e tim e in the brow ser. You can divide your brow ser page either vertically, horizontally, or both. Fram es keep your visitor grounded because only part of the brow ser gets updated m ost of the tim e, w hich leads to faster page loading.
Yo u are likely to see text navigatio n bars o n the te xt-o nly versio n o f a site, but yo u c an c ertainly put them o n all versio ns o f the site. They lo o k like this:
[Home][Support][Service][Sales][Contact Us][Feedback] Eac h item within the square brac kets is a hyperlink to that area o f the site. A text navigatio n bar sho uld go o n its o wn line and sho uld appear in the same plac e o n every page.
Table of contents Having a table o f c o ntents (TOC) o nly o ne c lic k away c an be a lifesaver fo r yo ur visito r. This c an also save yo u valuable sc reen real estate as a designer. A site map and a TOC sho uld c o ntain basic ally the same info rmatio n, but a TOC is usually textbased, whereas a site map is usually graphic al. Yo u c an implement a TOC in two ways — the easy way and the elegant way.
Text-only sites Should you create a text-only version of your site? Yes. Every site should have a text-only version to allow m axim um access even to people w hose Internet connections involve cups and a string. Is that realistic? No. If you have the resources to m aintain a text-only site, great. But for m ost Webm asters, w ho are struggling just to keep the prim ary Web site up-to-date and keep up w ith em erging technologies, it is sim ply not realistic. Why m aintain a text-only site? Faster access for people w ith slow Internet connections w ho have never heard of turning off the graphics, and for people using Lynx brow sers, w ho can’t see graphics. Why not m aintain a text-only site? Tim e, energy, and expense. What alternative do you have to providing a text-only site? You can do several things to increase dow nloading speed and they are all discussed later in this chapter. In addition, there are things that w ill m ake a page heavily dependent on graphics useful to a visitor w ho arrives w ith im age loading turned off. Watch for the alt attribute to elem ents throughout this book.
Chapter 32 ✦ Essentials of Web Page Design
The easy way Even if yo u c ho o se to implement the TOC the elegant way, yo u still need to implement it the easy way fo r peo ple who have o ld bro wsers. In the easy way, every page in yo ur site has a butto n o r part o f the navigatio n bar that links to a separate page where the TOC resides. If the TOC is large, then yo u want to have all the majo r headings near the to p o f the page with links to the details later in the same page. If yo u c an, try to keep the sho rt list at the to p o f the page o nly o ne sc reen lo ng. If the TOC is no t that lo ng, just list all the pages. Yo u pro bably want to have the names o f the pages in the TOC c o rrespo nd with the titles o f the pages. Yo u c ertainly want every page name in the TOC to link to the c o rrespo nding page in yo ur site. If the page names, o r if o nly a few page names, aren’t adequately desc riptive, inc lude a brief desc riptio n under tho se page names. Use the brief desc riptio n o nly if it inc reases c larity; yo u needn’t do it fo r every single page.
The elegant way Using JavaSc ript and the Do c ument Objec t Mo del, c o llec tively kno wn as dynamic HTML, yo u c an c reate an inc redibly ric h, interac tive table o f c o ntents that c an make yo ur site lo o k like a millio n do llars. Of c o urse, this o nly wo rks o n bro wsers that suppo rt HTML 4, but yo u c an use ano ther line o r two o f JavaSc ript to c hec k to see what bro wser yo ur visito r is running and implement the easy way fo r tho se who c an’t see yo ur wo rk o f art in dynamic HTML. Definition
Document Object M odel (DOM ). A set of rules that, w hen im plem ented by brow sers, give you, the designer, incredible access to the elem ents on your Web page. Form erly, if you w anted to have JavaScript change the color of your text, you had to reload your page; w ith the DOM the change to text color can happen w hen the user clicks a radio button or a check box. You can create dynam ic form s, w here the next field on the screen appears in response to the inform ation entered in the previous field. The DOM em pow ers the designer enorm ously and saves the visitor from page reloads and m ultiple screens. This is so exciting and im portant, Part VII is devoted to it.
Site map Site maps c an b e useful, and Chapter 36 has in-depth c o verage o f them. Yo u want to b e c areful ho w muc h detail yo u inc lude in yo ur site map, whic h sho uld b e an imagemap, as well. If yo u inc lude to o muc h detail either it will take a lo ng time to lo ad, b ec ause the graphic s file will b e eno rmo us, o r the text will b e tiny and diffic ult to read, o r b o th.
371
372
Part V ✦ Lay It Out Like the Pros
Site mapping tools There are site m apping tools and there are site m apping tools. Most often w hen one hears about site m apping, it is about m apping the site from a Webm aster’s perspective: Do all the links w ork? Where are the files physically located? This is not the kind of site m ap a visitor to a site needs. In addition, tools that m ap sites for purposes of site m anagem ent rarely produce Web-quality digital im ages that m ake sense to the visitor. Tw o different approaches you can take to create a site m ap for the Web visitor are dem onstrated by Microsoft Organization Chart and Dynam ic Diagram s’ MAPA Service. On the low end is Microsoft Organization Chart. This is an easy tool to use to create attractive site m aps, but you have to do all the w ork yourself. If you have Pow erPoint installed on your com puter, then you already have it. Whenever you change your site, you m ust rem em ber to update your site m ap published w ith the new version. This product only w orks for sm all sites. The am ount of energy required to m aintain the site m ap for sites developed by the team w ould soon outstrip the econom y of the initial softw are price. On the high end is Dynam ic Diagram s’ MAPA Service. This is w ritten in Java and lets your Web site m ap itself. Because it is a service, there is no softw are to purchase, upgrade, or install. You alw ays get the m ost recent version of the product. MAPA creates a 3D anim ated m ap, a Java applet, that runs on the Java-enabled brow sers of your visitors. The MAPA service is priced based on the size of your site. You pay a m onthly fee for either daily or w eekly m appings. The price is so low that if your site is over 100 pages, you shouldn’t even consider creating and m aintaining the site m ap yourself. The applet it creates is so sm ooth and w ell designed, it solves all your navigation problem s. Definitely look at it at http://www. dynamicdiagrams.com.
Site search So me sites inc lude a searc h field o n every page; so me link to a searc h page. If yo ur audienc e is so phistic ated eno ugh to kno w ho w to use the searc h field and yo u c an spare the spac e o n yo ur page, then go ahead and put the searc h field o n every page. If yo ur audienc e is likely no t to be to o tec hnic ally so phistic ated o r yo u want to give them mo re info rmatio n abo ut searc hing, then link to a separate page fo r entering searc h terms. In either c ase, yo u need either a separate page o r a separate frame fo r searc h results. On the bac k end, yo u need to be sure yo ur server has a searc h and index pro gram running o r yo ur visito r’s searc h will never return any results.
Site drop-down list This is a c lever item to add to yo ur arsenal o f navigatio nal to o ls. Using a dro p-do wn list, yo u c an give yo ur visito rs the po wer to link anywhere o n yo ur list with just o ne c lic k. The list c an be as lo ng as yo u want. The dro p-do wn list (c alled a se le ct list in HTML) takes up little sc reen real estate, so it is a do uble value.
Chapter 32 ✦ Essentials of Web Page Design
Tip
Make sure your visitors understand the drop-dow n list is another navigational tool. Otherw ise, the value is w asted. Visitors to your site —especially inexperienced users —m ay need a little direction.
Visual Appeal Beautiful pages are no t that plentiful o n the Web. What do peo ple find beautiful o n a page? The same things that are beautiful o n a bro c hure: c lean lines, smo o th shapes, and c o mplementary c o lo rs. In 1765, Edmund Burke, the English po litic al philo so pher, wro te A Philo so phical Enquiry into the Origin o f Our Ide as o f the Sublime and Be autiful. This sho rt bo o k (less than 200 pages) abo ut what we find beautiful is as ac c urate to day as any bo o k yo u c an find o n c reating graphic s fo r elec tro nic delivery. No thing has c hanged. Beauty is timeless. Yo u are rec eiving a lo t o f design suggestio ns in this c hapter. Yo u might be wo ndering ho w yo u c an fit all these things into just o ne page and still have ro o m fo r the c o ntent o r the links. Try to inc o rpo rate as many guidelines as po ssible into yo ur page. The page sho wn in Figure 32-2 meets every test o f go o d design in this c hapter and it lo o ks like it isn’t even trying. Go o d design is like that. Great athletes make their feats lo o k effo rtless; go o d design wo rks the same way. At the end o f this c hapter is a c hec klist yo u c an use to make sure yo ur pages have the essentials o f go o d design fo r the Web.
Interactivity Yo ur visito rs expec t almo st every page to have so me level o f interac tivity. Fo r links pages and the Welc o me page, this is easy. That is really all they do . Fo r c o ntent pages, ho wever, visito rs also expec t to be able to interac t with yo ur site. Yo u c an inc lude interac tivity by using hyperlinks and imagemaps to link bo th within and o utside o f the site. Yo u c an use dynamic HTML to have interac tivity within yo ur page. Fo rms are ano ther way to pro vide interac tivity.
Speed Ho w muc h sho uld yo u wo rry abo ut speed? Wo rry may be to o stro ng a wo rd. Even tho ugh bandwidth is getting c heaper and mo re available, do n’t make the mistake o f believing everyo ne ac c essing yo ur page is o n a T1 line (with fast ac c ess). Yo u still sho uld be c o nsiderate abo ut the amo unt o f data yo u expec t them to do wnlo ad to see yo ur page. Even tho ugh this bo o k talks abo ut visito rs to yo ur site , in fac t, yo ur site is de live re d to the deskto ps o f the peo ple who request it in their bro wsers. When yo u design yo ur pages with huge graphic s — bac kgro und images that fill the sc reen, large image maps, graphic al representatio ns o f text rather than text — yo u are telling yo ur visito rs yo u do n’t respec t their time. Is this the message yo u want to send?
373
374
Part V ✦ Lay It Out Like the Pros
The facts about Internet connections T1, T3, dial-up, 56K, cable m odem : w hat does it all m ean in plain English? T1 and T3 are types of Internet connections used by those users w illing to pay m ore for the faster connection —typically businesses, universities, and probably by your ISP, if you have one. The backbone of the Internet is T3. T1 transfers data at 1.5 Mbps. T3 com m unicates at betw een 3 Mbps and 45 Mbps (som ething you w ant to ask your ISP about if it claim s to have a T3 line). When you have a dial-up connection to the Internet, your m odem com m unicates w ith your ISP’s m odem at the speed of the slow er m odem . So even if you have a 56K m odem , if your ISP has 28.8 lines, you com m unicate at 28.8. Som e technologies, such as 56K m odem s and cable m odem s, use asym m etrical com m unication, w hich m eans dow nload from the Internet is at one speed and upload to the Internet is at another speed. Dow nload m ay approach the prom ised speed, but upload w on’t. This chart should help. It assum es the other end of the connection is at least as fast.
Type of Connection
Download
Upload
28.8K m odem
28.8K
28.8K
56K m odem
50K
33.6K
cable m odem (varied by m odem )
400K
100K
T1
1MG
1MG
T3
10MG
10MG
Of course, there is no guarantee you w ill ever com m unicate at the ceiling speed, w hich is w hat the table show s, but for purposes of calculation, you m ust assum e som ething. An overloaded Web server could cut dow nload speed by a factor of ten or m ore. The chart doesn’t define K, w hich is 1,000 bytes per second or 1,000 characters per second, but w hat really m atters is you see the relationship betw een the different connection speeds. If a page takes a m om ent to dow nload for you w hen you are connected via a T1, it w ill take a long tim e to load for your visitors, w ho, you should assum e, are probably at a slow er connection speed.
Design Guidelines Go o d page design is a skill. If yo u kno w abso lutely no thing abo ut page layo ut and design, it’ll sho w. If yo u are attempting to design a site fo r c o mmerc ial use, it’s pro bably best to hire a pro fessio nal. Yo u c an learn it yo urself, but yo u must expend so me intensive time and effo rt. Fo r tho se o f yo u insistent upo n do ing page layo ut yo urselves, here are ten things to remember:
1. Think o f the underlying design as a hange r. Onc e yo u figure o ut what the basic design is, everything else hangs o ff it. If yo u do n’t have the hanger, yo u’re go ing to be struggling with eac h element and it’s go ing to drive yo u insane.
Chapter 32 ✦ Essentials of Web Page Design
Lo o k at Figure 32-2 again. The designer, Debra Weiss o f drw Design ( http:// www.cstone.net/~debra/drwdesign), had this to say abo ut it: “I was struggling o ver the lo o k and feel o f this site fo r quite so me time. I wanted it to lo o k elegant, but I didn’t want the design to get in the way o f the func tio nality. Then, it struc k me. When I was visiting the Co lo nnade o ffic es, I remembered no tic ing several framed prints o f Greek arc hitec tural drawings o f temples and c o lumns and admiring them. I was able to lo c ate so me wo nderful digital artwo rk o f this type — flo o rplans, pillars, c o lumns, and c o lo nnades. This c o nc ept bec ame the hanger. Eac h sec tio n o f the site has a different c o lumn that represents it. One o f the page bac kgro unds is a sc reened-bac k flo o r plan. The headline fo nt is Palatino , a c lassic al fo nt. The navigatio nal ic o ns are teeny c o lumn to ps. The design just snapped into plac e.”
2. Dec ide o n an underlying grid struc ture and do n’t deviate. Lo o k at any magazine o r public atio n. Analyze ho w the text and graphic s are aligned. Is it a o ne-, two -, three-, o r fo ur-c o lumn grid? Fo r c o nsistenc y, use the same number o f pixels fo r ho rizo ntal spac ing between text and images — at least 5 pixels.
3. Use real typo graphic al marks. This is a subtlety, but it makes a subc o nsc io us impressio n o n the reader. Mo st Web bro wsers display quo tatio n marks like this: "hello ." Yo u want this: “hello .” While no t all bro wsers suppo rt these entities yet, ideally yo u c an insert real typo graphic al quo tatio n marks using entities as fo llo ws: “ ”
= =
“ ”
‘ ’
= =
‹ ›
4. Dec ide o n yo ur c o lo r palette, and stic k with it. If yo ur c o lo rs are navy, burgundy, and c ream, do n’t make yo ur links green.
5. Anti-alias yo ur display fo nts. The mark o f a pro fessio nal site c an so metimes be as simple as the lo o k o f the fo nts.
6. Be target-aware. Many sites make the mistake o f pro viding hundreds o f links to o ther sites. It’s hard eno ugh to get peo ple to c o me to yo ur site — why send them away? If yo u link to o ther sites, use the target =_blank attribute-value pair to o pen the link in a new windo w. This way, visito rs c an return to yo ur site easily. Opening links in a separate windo w also so lves ano malies that o c c ur when yo ur site has frames and yo u link to a site that also has frames.
7. Peo ple read fro m left to right and fro m to p to bo tto m. This seems o bvio us, but inexperienc ed designers seem to have tro uble remembering this. Put yo ur mo st impo rtant elements at the to p left o f the page. If yo u do n’t grab the reader’s attentio n there, yo u’re never go ing to get them to read mo re.
8. Think c arefully abo ut bells and whistles. Animatio ns, marquees, DHTML, and so fo rth are all great, whe n use d in mo de ratio n. Do n’t pull all yo ur tric ks o ut o f the bag and plo p them all o n o ne page. If yo ur c o ntent isn’t go o d eno ugh to stand alo ne, rethink it.
375
376
Part V ✦ Lay It Out Like the Pros
9. Use different fo nt styles sparingly. A go o d rule o f thumb is to pic k two fo nt families at the mo st. Use o ne fo r yo ur headlines and subheads. Use the o ther fo r bo dy c o py.
10. Lo o k at yo ur site using the wo rst c o nditio ns po ssible. Get a c o py o f Netsc ape 2.0. Set yo ur display to 600 × 480, 256 c o lo rs. Set yo ur mo dem do wn to 14.4 o r 28.8 and lo o k at yo ur site. Every page. If yo u c an’t stand it, redesign until it’s ac c eptable. If yo ur page lo o ks great under the wo rst c o nditio ns, it’ll shine under the best o nes. Do es this mean yo u have to sac rific e design to keep pages lo ading quic kly? No t nec essarily. The impo rtant thing is yo u do n’t add gratuito us graphic s if yo u c an avo id it. If yo u need slo w-to -lo ad features o n yo ur site — as an example, Java applets c an be very slo w to lo ad — then yo u want to do what yo u c an to have them lo ad witho ut making the visito r wait fo r them. Just igno re this who le sec tio n if yo u are designing fo r an intranet where every visito r to yo ur pages will have a reliably fast c o nnec tio n. There are enviro nments where yo u do n’t have to wo rry abo ut these things. Fo r the rest o f us: things c an be do ne to speed the delivery time o f yo ur pages. But first yo u need to understand what slo ws the lo ading o f yo ur page. Slo w mo dems and large graphic s are the biggest o ffenders. Bec ause yo u c an’t c o ntro l the mo dem speed o f yo ur visito r, yo u have to do what yo u c an o n yo ur end to make sure yo ur page wo n’t take an unreaso nably lo ng time to do wnlo ad. The o nly c o ntro l yo u have is to c o ntro l the size o f graphic s o n yo ur page. By using intelligent c o mpressio n o n yo ur images and by using multiple small images with white spac e aro und them (rather than o ne large image), yo u c an reduc e the size o f the files yo ur visito r has to do wnlo ad, thus reduc ing the do wnlo ad time. CrossReference
Chapter 37 explains all these concepts and m ore.
Witho ut getting a Ph.D. in Digital Art, the fo llo wing guidelines c an help yo u make intelligent dec isio ns abo ut ho w to sho w yo u respec t the time o f yo ur visito rs:
1. Reduc e the number o f graphic s files o n yo ur pages. Simple eno ugh. Dec ide what yo u need (element-wise) o n yo ur page and see ho w yo u c an c o nvey the info rmatio n yo u want to c o nvey witho ut using graphic s. Two no -brainers: Do n’t use c usto m bullets in a bulleted (unnumbered list), o r if yo u feel yo u abso lutely must use c usto m bullets, use o nly o ne bullet graphic fo r every bullet in yo ur site; and do n’t c reate c usto m Go o r Submit butto ns.
2. Reduc e the size o f graphic s files. Yo u c an do this two ways: reduc e the dimensio ns o f the file (height and width) befo re yo u publish it, o r reduc e the bit depth o f the images (the amo unt o f c o lo r info rmatio n the file c arries). Yo u c an also use a tric k under c ertain c irc umstanc es to lo ad a tiny file and sho w a fullsized file. If what yo u want to do is sho w so me pattern o f c o lo rs, c reate the file as a tiny versio n o f the image yo u want and use the height and width attributes o f the o bjec t element o r the image element (whic hever yo u prefer) to stre tch the file to the dimensio ns yo u want.
Chapter 32 ✦ Essentials of Web Page Design
Tip
Check out GIF Wizard at www.gifwizard.com. This is a Web-based utility that analyzes and shrinks your GIFs and JPGs. GIF or JPG? For additional inform ation, check out the collection of excellent articles on the Microsoft Site Builder site at http://msdn.microsoft.com/workshop/ design/color/default.asp.
3. Do n’t use a bac kgro und image. Or, if yo u abso lutely must, then use a tiny bac kgro und image that tiles well. See Figure 32-8. CrossReference
Chapter 28 discusses the use of background im ages at length.
Figure 32-8: The background im age on this page is a 6 × 6-pixel file.
4. Use text when yo u c an use text. What a c o nc ept! Next time yo u have yo ur wo rd pro c esso r o pen, if yo u use Windo ws 95, Windo ws NT, o r higher, c lic k the list o f fo nts available to yo u. Unless yo u installed so me fanc y fo nts pac kage, yo u have the base install o f fo nts. These same fo nts are available to everyo ne else o n the Web who is bro wsing fro m either Windo ws 95 o r Windo ws NT (yo ur results will vary o n a Mac o r o n UNIX). Is this huge list so limiting, yo u have to re-c reate text in a graphic s pac kage and lo ad it as an image? Get real!
377
378
Part V ✦ Lay It Out Like the Pros
Tip
You can create nice bullets using sym bol fonts, such as Wingdings. To figure out w hat keystrokes to use to insert into your file, use the Window s Character Map, found under Accessories. If you don’t have this installed, you should. Don’t do this if you expect a significant num ber of visitors to com e to your page from Macs. Macs don’t have Wingdings as an installed font and w hat they see w ill be unpredictable.
Effective Use of White Space White spac e has the mo st remarkable effec t o n a page’s design. It impro ves it immeasurably. When yo u are designing, make sure yo u allo w plenty o f it. When yo u have a lo t o f white spac e, yo u c an inc lude the same info rmatio n (sure, the page will be lo nger) witho ut c reating the feeling o f frenzy and c hao s that permeates the Web. White spac e is relaxing. White spac e do esn’t have to be white. If yo ur bac kgro und is pale po wder blue, then yo ur white space is really blue space . Definition
White space. Uncluttered space on the page. Margins around text and im ages is w hite space.
Yo u c an use white spac e to draw attentio n to a title, a heading, o r even a list. Why do yo u suppo se a bulleted list draws yo ur eye? White spac e c o ntributes to the effec t. When in do ubt, use white spac e to break up yo ur design.
Optimum Page Length Fo rget abo ut the idea that yo ur entire page needs to fit into o ne sc reen witho ut sc ro lling. What yo u really must do is to make sure what yo u do see lo o ks c o mplete. Ho w c an yo u tell ho w muc h will fit into a sc reen? Do n’t assume all yo ur visito rs are running their bro wsers the way yo u are. The fo llo wing sec tio n o n testing walks yo u thro ugh all the ways yo u need to test yo ur design to make sure visito rs see what lo o ks like a c o mplete page. Mo re impo rtant than the page length is the page c o ntent. Yo u do n’t want to break up yo ur c o ntent into anno yingly small bites just to have everything fit into o ne sc reen. Frames c an help yo u maintain the sense o f c o mpleteness so even if visito rs have to sc ro ll, they wo n’t lo se their gro unding. What yo u want to avo id at all c o sts is ho rizo ntal sc ro lling. Do no t make yo ur visito rs pan ac ro ss yo ur page to see yo ur c o ntent. If yo u design yo ur pages with a width o f 550–600 pixels, yo u avo id this.
Chapter 32 ✦ Essentials of Web Page Design
Future Expandability Yo u mean there’ll be mo re? Definitely. Assume yo ur site will never go away. It will c o ntinue to gro w. Paying c lo se attentio n to the site arc hitec ture and site o rganizatio n, as we’ll c o ver in Chapter 36, and to navigatio nal c o ntro ls as previo usly desc ribed, takes yo u 80 perc ent o f the way to ward having an infinitely expandable site. Creating effec tive page shells and applying them with disc ipline takes yo u the rest o f the way.
Designing an Effective Welcome Page Ho wever yo u dec ide to o rganize yo ur site and the c o ntent o n the pages within yo ur site, yo u need a Welc o me page. The We lco me page is the first plac e visito rs see when they c o me thro ugh the fro nt do o r o f yo ur site. As disc ussed previo usly, so me visito rs will c o me to yo ur site thro ugh o ther do o rs. What sho uld yo u have o n a Welc o me page? Just eno ugh. Lo o k again at Figure 32-2, bec ause a pic ture really is wo rth a tho usand wo rds. Just eno ugh to c o nvey a sense abo ut who put up the site. Just eno ugh to get yo u heading in the direc tio n o f the c o ntent.
Splash Screens What abo ut splash sc reens? Splash scre e ns are pages that appear befo re the Welc o me page. They c an also be c alled e ntry tunne ls. Usually all they do is enable yo u to pass thro ugh to the Welc o me page. There is just o ne link o n a splash sc reen and it takes yo u to the Welc o me page. The theo ry behind the splash sc reen is yo u have the visito rs’ c o mplete attentio n and yo u c an use this mo ment to c reate o ne stro ng impressio n (whether this impressio n is that yo u have a great lo go o r graphic artist o r yo u are wasting their time with slo wlo ading graphic s is hard to say). If yo u are go ing to use a splash sc reen, whic h is o f arguable value — ho w muc h attentio n is the lo ss o f go o dwill wo rth? — then at least lo o k aro und the Web and find so me nic e o nes. Make sure yo ur splash sc reen fits into o ne sc reen o n all bro wsers at all sc reen reso lutio ns; this is no time to sc ro ll.
Testing The impo rtanc e o f testing yo ur page design c anno t be emphasized eno ugh. Lo o k at it in all bro wsers o n all platfo rms at all sc reen reso lutio ns yo u c an po ssibly c o nc eive o f yo ur visito rs using. Subtle differenc es exist between bro wsers and yo u c an’t assume things will lo o k the same. If yo u are o ne who spends weeks at the
379
380
Part V ✦ Lay It Out Like the Pros
paint sto re trying to find just the right shade o f paint fo r yo ur ro o m, then yo u will waste a lo t o f time playing with c o lo rs in yo ur design o nly to learn that what lo o ks like a beautiful, ric h burgundy o n o ne sc reen is bro wn o n ano ther and purple o n yet ano ther. Tip
Looking for inform ation about the Web-safe palette? An excellent article is at http://msdn.microsoft.com/workshop/design/color/safety.asp.
The M yth of Completeness Never, never, never say unde r co nstructio n. The entire Web is under c o nstruc tio n. If it is c o mplete eno ugh to publish, publish it; o therwise, do n’t. In the pro c ess o f writing this bo o k, do zens o f pro fessio nal Web develo pers were c o ntac ted fo r permissio n to use their materials in the figures thro ugho ut these pages. Pro bably half o f them said so mething abo ut ho w the sc reen c aptures sho uldn’t be taken until they had fixed just o ne mo re thing they didn’t like. Yo u will never be entirely satisfied with yo ur page. Yo u will always want to do mo re. If it is so embarrassing yo u have to tell peo ple it is under c o nstruc tio n, then yo u pro bably sho uldn’t publish it yet. Alo ng the same lines, do n’t be afraid to retire pages. Do n’t leave o ld junk up there if it is no lo nger attrac tive o r ac c urate. Run link-c hec king so ftware right away to make sure all yo ur links still wo rk. Bec ause o thers will retire their o wn pages o c c asio nally, yo u’ll want to run link-c hec king so ftware regularly to be sure yo ur external links aren’t bro ken either.
From Here CrossReference
Jum p to Part VII and learn about the m ost exciting thing going on w ith the Web: Dynam ic HTML. Jum p to Chapter 37 and get an intensive course in graphics.
Summary Page design requires balanc ing visual appeal against speed, c o nsistenc y, predic tability, easy navigatio n, and a ho st o f o ther things. Getting distrac ted is easy when yo u are invo lved in the design pro c ess. Remember, this is just a step o n the way to publishing yo ur site. If yo u c o ntinually c hange yo ur design, yo u’ll never get yo ur site published. The HTML 4 Way suppo rts the separatio n o f c o ntent fro m presentatio n that c an help keep yo u fo c used. Finally, test, test, test yo ur design to make sure all visito rs, no matter where they c o me fro m, have a po sitive experienc e o n yo ur site.
✦
✦
✦
33 C H A P T E R
Understanding CSS Positioning Options
✦
✦
✦
✦
In This Cha pter The display pro perty The flo at pro perty
I
n the last few c hapters o f Part IV, yo u learned muc h o f what yo u need to kno w to use CSS. In this c hapter, yo u learn abo ut po sitio ning o ptio ns available to yo u in CSS. This c hapter fo c uses o n the five pro perties that give yo u c o mplete c o ntro l o ver ho w yo ur elements are po sitio ned o n the page. The po sitio ning pro perties — display, float, clear, position, and z-index — give yo u the po wer to po sitio n yo ur text and graphic s relatively, abso lutely, o r using so me c o mbinatio n o f the two .
The clear pro perty The po sitio n pro perty The z-index pro perty Understanding relative po sitio ning Understanding abso lute po sitio ning
The display Property The display pro perty is o ne yo u already take fo r granted. All elements have a display pro perty. Yo u c an use the default display pro perty o r set yo ur o wn. Yo u c an also use the display pro perty to make elements appear and disappear o n yo ur page. Dynamic HTML, whic h is just JavaSc ript and CSS with the Do c ument Objec t Mo del, takes advantage o f the display pro perty to have o bjec ts appear and disappear witho ut relo ading the page. There are 17 valid values fo r the display pro perty:
✦ block. All block elements have a default display value o f blo c k. Yo u c an make an inline element behave like a block element by setting the value o f the display pro perty to blo c k.
✦ inline. All inline elements have a default display value o f inline. Yo u c an, o f c o urse, c hange this.
Co mbining relative and abso lute po sitio ning
✦
✦
✦
✦
382
Part V ✦ Lay It Out Like the Pros
✦ list-item. List items are so rt o f a hybrid between block elements and inline elements. Yo u pro bably no tic ed the c hapter that disc usses lists beats aro und the bush o n what type o f element lists and list items are. A list item is treated as a block element with an added list-item marker.
✦ compact. This value c reates either blo c k o r inline bo xes, depending o n the c o ntext o f its use. Pro perties apply to run-in and c o mpac t bo xes based o n their final status (inline o r blo c k level).
✦ marker. This value dec lares generated c o ntent befo re o r after a marker bo x. This value sho uld o nly be used with :before and :after pseudo -elements that are attac hed to blo c k-level elements. In o ther c ases, this value is interpreted as inline.
✦ none. An element with a display value set to no ne do es no t render o n the page. The bo rder, if there is any aro und the element, is no t rendered either. The element do esn’t take up any spac e o n the page; thus, it do esn’t affec t the layo ut o f any o ther elements. Finally, any c hild elements o f the element who se display value is set to no ne are no t rendered (they inherit this display value), e ve n if their o wn display values are explic itly set to so mething o ther than no ne. CrossReference
Chapter 48, w hich covers JavaScript, explains w hy you m ight set the display property to none.
✦ table, inline-table, table-row-group, table-column, table-column-group, tableheader-group, table-footer-group, table-row, table-cell, and table-caption. These values c ause an element to behave like a table element (subjec t to table restric tio ns).
✦ run-in. No elements have a default value o f run-in. Setting the display value o f an element to run-in has this effec t: If the fo llo wing element is no t o f type blo c k, is flo ating, o r is po sitio ned abso lutely, the run-in element renders as a block element. Otherwise, the run-in element renders as if it were part o f the fo llo wing element, whic h means inline with the fo llo wing element. This do esn’t wo rk in Versio n 5 o r earlier bro wsers.
H6.run-in { display: run-in; font-variant: bold; } H6:after.run-in { content: “. “; }
Chapter 33 ✦ Understanding CSS Positioning Options
Run-in.
Run-in. No elements have a default value o f run-in. Setting the display value o f an element to run-in has the effec t yo u see in this example.
The float Property It is no t unusual to want to arrange yo ur page so that o ne o r mo re elements, mo st c o mmo nly images, appear next to (rather than abo ve o r belo w) o ther elements. The fo llo wing HTML and CSS c reate the effec t yo u see in Figure 33-1:
IMG.icon { padding: 20px; float: left; }
Chapter 33 Examples
Chapter 33 Examples
The float pro perty has three values: left, right, and no ne. Setting the value o f the float pro perty to no ne (the default value) results in the element no t flo ating at all. In the previo us example, the page wo uld instead be rendered as seen in Figure 33-2.
383
384
Part V ✦ Lay It Out Like the Pros
Figure 33-1: Using the float property to w rap text around an im age
Figure 33-2: Setting the float property to none results in no floating
Chapter 33 ✦ Understanding CSS Positioning Options
The clear Property The clear pro perty wo rks in c o njunc tio n with the float pro perty. While the float pro perty is applied to the o bjec t yo u want to wrap aro und, the clear pro perty is applied to the o bjec t yo u want to do the wrapping. The default value fo r the clear pro perty is no ne . This means bo th the right and the left sides o f the element are allo wed to have a flo ating o bjec t next to them. In the fo llo wing example, there are two ic o n c lasses. One po sitio ns an image as flo ating to the left o f the no nflo ating element. The o ther po sitio ns an image as flo ating to the right o f the no nflo ating element: in this c ase, the P element. No tic e that bo th the images must appear be fo re the no nflo ating element. If they do n’t, the no nflo ating element o nly wraps aro und the first image and the sec o nd image appears o n a line by itself after the no nflo ating element.
IMG.icon { padding: 20px; float: left; } IMG.icon2 { padding: 20px; float: right; } P { clear: none; }
Chapter 33 Examples
The results o f the prec eding example c an be seen in Figures 33-3 and 33-4. The same example is sho wn in bo th Netsc ape and Internet Explo rer so yo u c an see that bo th bro wsers render the same thing slightly differently. Spec ific ally, Internet Explo rer seems no t to respec t the padding pro perty. Netsc ape graduates the text aro und the image.
385
386
Part V ✦ Lay It Out Like the Pros
Figure 33-3: Using the float and the clear properties together (in Netscape)
Figure 33-4: Using the float and the clear properties together (in Internet Explorer)
Chapter 33 ✦ Understanding CSS Positioning Options
In Figure 33-5, the clear pro perty o f the no nflo ating element ( P) is set to left. This prevents anything fro m flo ating to the left o f the P element. In this example, ho wever, bec ause bo th images (being the same image) are the same height, the sec o nd image (with a c lass o f ic o n2) flo ats to the right o n the page, parallel to the first image.
Figure 33-5: Floating w ith the clear property set to left
The results in Figure 33-5 are no t exac tly what were intended. If what was wanted was fo r the sec o nd image to flo at to the right o f the text and the first image to be po sitio ned abo ve the text, then the float pro perty o f the first image must also be turned o ff (set to no ne, c o mmented o ut, o r deleted fro m the style sheet). The resultant style sheet wo uld lo o k like this:
IMG.icon { padding: 20px; /* float: left; */ } IMG.icon2 { padding: 20px; float: right; } P { clear: left; }
387
388
Part V ✦ Lay It Out Like the Pros
And the results o f this style sheet, with the HTML previo usly given, c an be seen in Figure 33-6.
Figure 33-6: Using the float and clear properties properly to achieve desired results
The position Property The fo urth o f the five pro perties yo u c an use to c o ntro l po sitio ning with CSS is the position pro perty. The position pro perty takes o ne o f three values:
✦ normal. This is the default value. No rmal po sitio n simply means the rules yo u have learned thus far abo ut CSS apply to yo ur element, and it renders in a po sitio n based o n the values yo u assign to it and the values o f the previo us no rmal elements.
✦ relative. This means relative to the po sitio n the element wo uld have if it were defined as a static ally po sitio ned element. All c hildren elements are po sitio ned with this new relative po sitio n as their starting po int. When po sitio ning elements with the relative po sitio n, o verlaying o r o bsc uring o ther elements is po ssible.
✦ absolute. When yo u define an element as abso lutely po sitio ned, it is no t inc luded in the c alc ulatio ns used to po sitio n o ther elements o n the page. The element is simply put where yo u tell it to be put. All c hildren elements o f this element are po sitio ned relatively to this abso lute po sitio n. When using abso lute po sitio ning, it is po ssible to o verlay o r o bsc ure o ther elements.
Chapter 33 ✦ Understanding CSS Positioning Options
The z-index Property The z-index pro perty is a wo nderful additio n to CSS. It enables yo u to po sitio n elements in the third dimensio n: depth. Why wo uld yo u want to po sitio n elements with the z-index pro perty?
✦ To layer graphic s (eac h o f whic h are links), to save spac e, o r to c reate an interesting visual effec t
✦ To layer text o ver an image ✦ To hide graphic s fo r use later, using JavaSc ript, when yo u c an simply c hange the z-index o f an o bjec t and have it magic ally appear
Understanding Relative Positioning In CSS, relative po sitio ning has two po ssible meanings. Mo st Web designers think o f relative po sitio ning as when they po sitio n an element using the flo at pro perty (fo rmerly the valign and align attributes) o r by c hanging the margins o r padding o n an element to sc o o t it o ne way o r ano ther. Generally speaking, re lative po sitio ning is po sitio ning the element using any means o ther than abso lute po sitio ning. All the pro perties yo u have learned abo ut CSS in this c hapter and in previo us c hapters have been abo ut relative po sitio ning, whic h CSS2 no w c o nfusingly c alls static po sitio ning. To make matters mo re interesting, CSS intro duc ed the position pro perty, whic h yo u c an set to re lative . This enables yo u to mo ve an element by so me o ffset fro m the po sitio n at whic h it wo uld have been po sitio ned if yo u had allo wed the bro wser to po sitio n it using all the previo us pro perties yo u defined fo r it and fo r prec eding elements. To unc o nvo lute the previo us sentenc e, these are the plain-English steps the bro wser go es thro ugh to po sitio n an element no t defined as abso lutely po sitio ned:
1. Calc ulate the internal size o f the bo x asso c iated with eac h element 2. Calc ulate the size o f eac h element’s bo x, inc luding padding, bo rders, and margins
3. Calc ulate the po sitio n o f eac h element’s bo x o n the page based o n the amo unt o f spac e taken up by eac h previo us bo x If yo u c ho o se to set the value o f the po sitio n pro perty to re lative , then the bro wser takes a fo urth step to c alc ulate the element’s po sitio n. After c alc ulating the starting po int fo r that bo x, the bro wser uses the relative o ffset yo u have indic ated to c alc ulate a new po sitio n, relative to that starting po int.
389
390
Part V ✦ Lay It Out Like the Pros
Understanding Absolute Positioning When yo u po sitio n an element with abso lute po sitio ning, the bro wser o nly takes the first two steps previo usly listed. After it has c alc ulated the size o f the bo x, it renders that bo x exac tly where yo u tell it. Yo u risk o verlaying o ther elements, if yo u are no t c areful, but it c an be used to c reate stunning layo ut effec ts.
Combining Relative and Absolute Positioning Yo u c an c o mbine relative and abso lute po sitio ning in CSS, but yo u must do so tho ughtfully o r yo u will end up with yo ur text running o ver yo ur graphic s, o r yo ur graphic s o verlaying yo ur text. The easiest way to c o mbine relative and abso lute po sitio ning is to define the first element o n yo ur page — say, an image o f kno wn dimensio ns — as abso lutely po sitio ned near the to p-left o f the page, o r wherever yo u want it po sitio ned, and then to define the rest o f yo ur page as being relative to that o ffset (the dimensio ns o f the abso lutely po sitio ned element). Other o ptio ns fo r c o mbining relative and abso lute po sitio ning inc lude po sitio ning an element to the right o r left o f the bo dy o f yo ur page and limiting the width o f the rest o f the elements in yo ur page by using the width attribute. Yo u learn mo re spec ific applic atio ns o f bo th relative and abso lute po sitio ning in Chapter 35.
From Here CrossReference
Jum p to Chapter 47 and learn about the Docum ent Object Model (DOM), w hich is essential to dynam ic HTML. Proceed to Chapter 34 to learn about positioning and sizing graphics.
Summary In this c hapter yo u learned advanc ed CSS. Yo u learned the five essential layo ut pro perties: display, float, clear, position, and z-index. Yo u learned ho w relative po sitio ning differs fro m static po sitio ning and ho w they bo th differ fro m abso lute po sitio ning. Yo u also learned ho w to c o mbine relative and abso lute po sitio ning.
✦
✦
✦
33 C H A P T E R
Understanding CSS Positioning Options
✦
✦
✦
✦
In This Cha pter The display pro perty The flo at pro perty
I
n the last few c hapters o f Part IV, yo u learned muc h o f what yo u need to kno w to use CSS. In this c hapter, yo u learn abo ut po sitio ning o ptio ns available to yo u in CSS. This c hapter fo c uses o n the five pro perties that give yo u c o mplete c o ntro l o ver ho w yo ur elements are po sitio ned o n the page. The po sitio ning pro perties — display, float, clear, position, and z-index — give yo u the po wer to po sitio n yo ur text and graphic s relatively, abso lutely, o r using so me c o mbinatio n o f the two .
The clear pro perty The po sitio n pro perty The z-index pro perty Understanding relative po sitio ning Understanding abso lute po sitio ning
The display Property The display pro perty is o ne yo u already take fo r granted. All elements have a display pro perty. Yo u c an use the default display pro perty o r set yo ur o wn. Yo u c an also use the display pro perty to make elements appear and disappear o n yo ur page. Dynamic HTML, whic h is just JavaSc ript and CSS with the Do c ument Objec t Mo del, takes advantage o f the display pro perty to have o bjec ts appear and disappear witho ut relo ading the page. There are 17 valid values fo r the display pro perty:
✦ block. All block elements have a default display value o f blo c k. Yo u c an make an inline element behave like a block element by setting the value o f the display pro perty to blo c k.
✦ inline. All inline elements have a default display value o f inline. Yo u c an, o f c o urse, c hange this.
Co mbining relative and abso lute po sitio ning
✦
✦
✦
✦
382
Part V ✦ Lay It Out Like the Pros
✦ list-item. List items are so rt o f a hybrid between block elements and inline elements. Yo u pro bably no tic ed the c hapter that disc usses lists beats aro und the bush o n what type o f element lists and list items are. A list item is treated as a block element with an added list-item marker.
✦ compact. This value c reates either blo c k o r inline bo xes, depending o n the c o ntext o f its use. Pro perties apply to run-in and c o mpac t bo xes based o n their final status (inline o r blo c k level).
✦ marker. This value dec lares generated c o ntent befo re o r after a marker bo x. This value sho uld o nly be used with :before and :after pseudo -elements that are attac hed to blo c k-level elements. In o ther c ases, this value is interpreted as inline.
✦ none. An element with a display value set to no ne do es no t render o n the page. The bo rder, if there is any aro und the element, is no t rendered either. The element do esn’t take up any spac e o n the page; thus, it do esn’t affec t the layo ut o f any o ther elements. Finally, any c hild elements o f the element who se display value is set to no ne are no t rendered (they inherit this display value), e ve n if their o wn display values are explic itly set to so mething o ther than no ne. CrossReference
Chapter 48, w hich covers JavaScript, explains w hy you m ight set the display property to none.
✦ table, inline-table, table-row-group, table-column, table-column-group, tableheader-group, table-footer-group, table-row, table-cell, and table-caption. These values c ause an element to behave like a table element (subjec t to table restric tio ns).
✦ run-in. No elements have a default value o f run-in. Setting the display value o f an element to run-in has this effec t: If the fo llo wing element is no t o f type blo c k, is flo ating, o r is po sitio ned abso lutely, the run-in element renders as a block element. Otherwise, the run-in element renders as if it were part o f the fo llo wing element, whic h means inline with the fo llo wing element. This do esn’t wo rk in Versio n 5 o r earlier bro wsers.
H6.run-in { display: run-in; font-variant: bold; } H6:after.run-in { content: “. “; }
Chapter 33 ✦ Understanding CSS Positioning Options
Run-in.
Run-in. No elements have a default value o f run-in. Setting the display value o f an element to run-in has the effec t yo u see in this example.
The float Property It is no t unusual to want to arrange yo ur page so that o ne o r mo re elements, mo st c o mmo nly images, appear next to (rather than abo ve o r belo w) o ther elements. The fo llo wing HTML and CSS c reate the effec t yo u see in Figure 33-1:
IMG.icon { padding: 20px; float: left; }
Chapter 33 Examples
Chapter 33 Examples
The float pro perty has three values: left, right, and no ne. Setting the value o f the float pro perty to no ne (the default value) results in the element no t flo ating at all. In the previo us example, the page wo uld instead be rendered as seen in Figure 33-2.
383
384
Part V ✦ Lay It Out Like the Pros
Figure 33-1: Using the float property to w rap text around an im age
Figure 33-2: Setting the float property to none results in no floating
Chapter 33 ✦ Understanding CSS Positioning Options
The clear Property The clear pro perty wo rks in c o njunc tio n with the float pro perty. While the float pro perty is applied to the o bjec t yo u want to wrap aro und, the clear pro perty is applied to the o bjec t yo u want to do the wrapping. The default value fo r the clear pro perty is no ne . This means bo th the right and the left sides o f the element are allo wed to have a flo ating o bjec t next to them. In the fo llo wing example, there are two ic o n c lasses. One po sitio ns an image as flo ating to the left o f the no nflo ating element. The o ther po sitio ns an image as flo ating to the right o f the no nflo ating element: in this c ase, the P element. No tic e that bo th the images must appear be fo re the no nflo ating element. If they do n’t, the no nflo ating element o nly wraps aro und the first image and the sec o nd image appears o n a line by itself after the no nflo ating element.
IMG.icon { padding: 20px; float: left; } IMG.icon2 { padding: 20px; float: right; } P { clear: none; }
Chapter 33 Examples
The results o f the prec eding example c an be seen in Figures 33-3 and 33-4. The same example is sho wn in bo th Netsc ape and Internet Explo rer so yo u c an see that bo th bro wsers render the same thing slightly differently. Spec ific ally, Internet Explo rer seems no t to respec t the padding pro perty. Netsc ape graduates the text aro und the image.
385
386
Part V ✦ Lay It Out Like the Pros
Figure 33-3: Using the float and the clear properties together (in Netscape)
Figure 33-4: Using the float and the clear properties together (in Internet Explorer)
Chapter 33 ✦ Understanding CSS Positioning Options
In Figure 33-5, the clear pro perty o f the no nflo ating element ( P) is set to left. This prevents anything fro m flo ating to the left o f the P element. In this example, ho wever, bec ause bo th images (being the same image) are the same height, the sec o nd image (with a c lass o f ic o n2) flo ats to the right o n the page, parallel to the first image.
Figure 33-5: Floating w ith the clear property set to left
The results in Figure 33-5 are no t exac tly what were intended. If what was wanted was fo r the sec o nd image to flo at to the right o f the text and the first image to be po sitio ned abo ve the text, then the float pro perty o f the first image must also be turned o ff (set to no ne, c o mmented o ut, o r deleted fro m the style sheet). The resultant style sheet wo uld lo o k like this:
IMG.icon { padding: 20px; /* float: left; */ } IMG.icon2 { padding: 20px; float: right; } P { clear: left; }
387
388
Part V ✦ Lay It Out Like the Pros
And the results o f this style sheet, with the HTML previo usly given, c an be seen in Figure 33-6.
Figure 33-6: Using the float and clear properties properly to achieve desired results
The position Property The fo urth o f the five pro perties yo u c an use to c o ntro l po sitio ning with CSS is the position pro perty. The position pro perty takes o ne o f three values:
✦ normal. This is the default value. No rmal po sitio n simply means the rules yo u have learned thus far abo ut CSS apply to yo ur element, and it renders in a po sitio n based o n the values yo u assign to it and the values o f the previo us no rmal elements.
✦ relative. This means relative to the po sitio n the element wo uld have if it were defined as a static ally po sitio ned element. All c hildren elements are po sitio ned with this new relative po sitio n as their starting po int. When po sitio ning elements with the relative po sitio n, o verlaying o r o bsc uring o ther elements is po ssible.
✦ absolute. When yo u define an element as abso lutely po sitio ned, it is no t inc luded in the c alc ulatio ns used to po sitio n o ther elements o n the page. The element is simply put where yo u tell it to be put. All c hildren elements o f this element are po sitio ned relatively to this abso lute po sitio n. When using abso lute po sitio ning, it is po ssible to o verlay o r o bsc ure o ther elements.
Chapter 33 ✦ Understanding CSS Positioning Options
The z-index Property The z-index pro perty is a wo nderful additio n to CSS. It enables yo u to po sitio n elements in the third dimensio n: depth. Why wo uld yo u want to po sitio n elements with the z-index pro perty?
✦ To layer graphic s (eac h o f whic h are links), to save spac e, o r to c reate an interesting visual effec t
✦ To layer text o ver an image ✦ To hide graphic s fo r use later, using JavaSc ript, when yo u c an simply c hange the z-index o f an o bjec t and have it magic ally appear
Understanding Relative Positioning In CSS, relative po sitio ning has two po ssible meanings. Mo st Web designers think o f relative po sitio ning as when they po sitio n an element using the flo at pro perty (fo rmerly the valign and align attributes) o r by c hanging the margins o r padding o n an element to sc o o t it o ne way o r ano ther. Generally speaking, re lative po sitio ning is po sitio ning the element using any means o ther than abso lute po sitio ning. All the pro perties yo u have learned abo ut CSS in this c hapter and in previo us c hapters have been abo ut relative po sitio ning, whic h CSS2 no w c o nfusingly c alls static po sitio ning. To make matters mo re interesting, CSS intro duc ed the position pro perty, whic h yo u c an set to re lative . This enables yo u to mo ve an element by so me o ffset fro m the po sitio n at whic h it wo uld have been po sitio ned if yo u had allo wed the bro wser to po sitio n it using all the previo us pro perties yo u defined fo r it and fo r prec eding elements. To unc o nvo lute the previo us sentenc e, these are the plain-English steps the bro wser go es thro ugh to po sitio n an element no t defined as abso lutely po sitio ned:
1. Calc ulate the internal size o f the bo x asso c iated with eac h element 2. Calc ulate the size o f eac h element’s bo x, inc luding padding, bo rders, and margins
3. Calc ulate the po sitio n o f eac h element’s bo x o n the page based o n the amo unt o f spac e taken up by eac h previo us bo x If yo u c ho o se to set the value o f the po sitio n pro perty to re lative , then the bro wser takes a fo urth step to c alc ulate the element’s po sitio n. After c alc ulating the starting po int fo r that bo x, the bro wser uses the relative o ffset yo u have indic ated to c alc ulate a new po sitio n, relative to that starting po int.
389
390
Part V ✦ Lay It Out Like the Pros
Understanding Absolute Positioning When yo u po sitio n an element with abso lute po sitio ning, the bro wser o nly takes the first two steps previo usly listed. After it has c alc ulated the size o f the bo x, it renders that bo x exac tly where yo u tell it. Yo u risk o verlaying o ther elements, if yo u are no t c areful, but it c an be used to c reate stunning layo ut effec ts.
Combining Relative and Absolute Positioning Yo u c an c o mbine relative and abso lute po sitio ning in CSS, but yo u must do so tho ughtfully o r yo u will end up with yo ur text running o ver yo ur graphic s, o r yo ur graphic s o verlaying yo ur text. The easiest way to c o mbine relative and abso lute po sitio ning is to define the first element o n yo ur page — say, an image o f kno wn dimensio ns — as abso lutely po sitio ned near the to p-left o f the page, o r wherever yo u want it po sitio ned, and then to define the rest o f yo ur page as being relative to that o ffset (the dimensio ns o f the abso lutely po sitio ned element). Other o ptio ns fo r c o mbining relative and abso lute po sitio ning inc lude po sitio ning an element to the right o r left o f the bo dy o f yo ur page and limiting the width o f the rest o f the elements in yo ur page by using the width attribute. Yo u learn mo re spec ific applic atio ns o f bo th relative and abso lute po sitio ning in Chapter 35.
From Here CrossReference
Jum p to Chapter 47 and learn about the Docum ent Object Model (DOM), w hich is essential to dynam ic HTML. Proceed to Chapter 34 to learn about positioning and sizing graphics.
Summary In this c hapter yo u learned advanc ed CSS. Yo u learned the five essential layo ut pro perties: display, float, clear, position, and z-index. Yo u learned ho w relative po sitio ning differs fro m static po sitio ning and ho w they bo th differ fro m abso lute po sitio ning. Yo u also learned ho w to c o mbine relative and abso lute po sitio ning.
✦
✦
✦
34 C H A P T E R
Positioning Graphics and Text
✦
✦
✦
✦
In This Cha pter Specifying the lo catio n o f an imag e
I
n this c hapter, yo u learn mo re tric ks to give yo u c o ntro l o ver yo ur page’s layo ut using CSS and HTML to gether. Spec ific ally, yo u learn ho w to have an image appear in the lo c atio n o f yo ur c ho ic e. This c hapter explains ho w to po sitio n yo ur text where yo u want it to appear and ho w to wrap yo ur text aro und flo ating graphic s. Many examples help jo g yo ur o wn c reativity.
Specifying Image Location In the previo us c hapters, yo u learned eno ugh CSS to spec ify where o n the page an image sho uld be lo c ated. In fac t, yo u learned mo re than o ne way to do this.
Using frames One way to ensure that yo ur image ends up where yo u want it is to use frames. Co nsider plac ing an image in the upper righthand c o rner o f the sc reen. If yo u use frames, yo u c an be sure the graphic will never mo ve. Yo ur HTML might lo o k like this:
Defining text po sitio ns Flo ating text aro und an imag e Flo ating an imag e next to text
✦
✦
✦
✦
392
Part V ✦ Lay It Out Like the Pros
In the prec eding example, yo ur image, c alled image.gif, sho uld be exac tly 200 × 200 pixels. By setting the sc ro lling attribute to no , yo u are assured that a sc ro ll bar wo n’t be to the right o f yo ur image. By setting the framebo rder attribute to zero fo r bo th the c o lumns in the first ro w o f the page, yo u are assured a bo rder wo n’t be aro und the banner o r aro und the image next to the banner.
Using CSS with absolute positioning Ano ther way to spec ify an image’s po sitio n is to use the CSS po sitio n pro perty with a value o f abso lute. Yo u c an use this metho d to po sitio n o ne o r mo re graphic s o n the page. The pro blem with this tec hnique is that it requires c areful planning to make sure the elements po sitio ned as static (o r relative) do n’t run o ver yo ur abso lutely po sitio ned element — in this c ase, an image. Yo u c an also use abso lute po sitio ning to po sitio n subtle graphic s in a c ase where yo u want the text run right ac ro ss the images. Co nsider the fo llo wing CSS:
IMG.no1 { position: absolute; top: 200; right: auto; bottom: auto; left: 350; } IMG.no2 { position: absolute; top: 800; right: auto; bottom: auto; left: 350; } Bo th images have abso lute po sitio ning fro m the to p-left o f the bro wser windo w. All images that use either o f the two c lasses no1, and no2, will take their po sitio ning fro m the c lass. The resulting page lo o ks like Figure 34-1. No tic e yo u o nly see o ne image. Bec ause the abso lute po sitio n o f the sec o nd image ( no2) is 800 pixels do wn the page and the viewable area is less than that, the sec o nd image is o nly visible when yo u sc ro ll do wn the page.
Using CSS with relative positioning Figure 34-2 uses relative po sitio ning to plac e the image to the left o f the text.
Chapter 34 ✦ Positioning Graphics and Text
Figure 34-1: This absolutely positioned im age has text overlaying the im age.
Figure 34-2: Relative positioning places the im age to the left of the body of text.
393
394
Part V ✦ Lay It Out Like the Pros
Lo o k at the fo llo wing style sheet and no tic e the BODY element is fo rmatted with a 200-pixel left-hand bo rder. This leaves ro o m to relatively po sitio n the image next to the text. What abo ut all that white spac e abo ve the paragraph? This is bec ause when yo u use relative po sitio ning fo r o ne element, all subsequent elements are po sitio ned based o n that element’s no rmal po sitio n, no t its new, relative po sitio n. What do es this mean? It means the bro wser leaves spac e fo r the image abo ve the paragraph o f text, even tho ugh the image is po sitio ned ne xt to the paragraph o f text. If yo u have multiple paragraphs, this c o uld be ugly.
P.thisone { position: normal; } IMG.relative { position: relative; left: -190; top: 150; } BODY { margin-left: 200; }
Using CSS to float the image If the flo at pro perty had been used instead, the result wo uld have been Figure 34-3.
Figure 34-3: The float property w raps the text around the im age.
Chapter 34 ✦ Positioning Graphics and Text
No tic e the text wraps aro und the image, rather than giving yo u a c lean left margin. Either lo o k has its plac e, depending o n what yo u desire. The CSS fo r Figure 34-3 fo llo ws:
IMG.icon { float: left; } P { margin-left: 15px; }
Defining Text Positions Ho w c an yo u put text where yo u want it? Yo u have several fo rmatting c ho ic es. Yo u c an fo rmat yo ur text by mo difying the padding and margin o f the text element itself, as in Figure 34-4.
Figure 34-4: Text form atted w ith m argins and padding
The CSS that fo llo ws was used to c reate the simple effec ts yo u see in Figure 34-4:
P { margin-top: 1cm; line-height: 200%; font-family: “Book Antiqua”; padding: 0 2cm; }
395
396
Part V ✦ Lay It Out Like the Pros
Changing the BODY element Ano ther o ptio n yo u have fo r fo rmatting yo ur page — so the text appears where yo u want it — is to c hange the fo rmatting o f the BODY element. Figure 34-5 uses BODY element fo rmatting.
Figure 34-5: Text form atting w ith the BODY elem ent
Figure 34-5 was c reated with the fo llo wing CSS:
BODY { margin-left: 1in; } If yo u wanted to add page dec o ratio ns to the left margin, yo u c o uld put it in the o ne-inc h, left-hand margin. Or, yo u c o uld put an abso lutely po sitio ned graphic , with a negative ho rizo ntal po sitio n, in that spac e.
Positioning text with relative positioning Yo u might need to pull text o ut o f the bo dy o f the page fo r so me reaso n. Figure 34-6 uses relative po sitio ning to pull a paragraph o f text o ut o f the bo dy o f the page and draw attentio n to it.
Chapter 34 ✦ Positioning Graphics and Text
The fo llo wing CSS was used to c reate Figure 34-6:
BODY { margin-right: 1.5in; } P.pull { position: relative; padding: 1em 1em 1em 3em; left: 150px; top: auto; border-left: red .25cm solid; border-top: red 1px solid; border-bottom: red 1px solid; }
Figure 34-6: Text form atted w ith relative positioning
Floating an Image Next to Text In Figure 34-7, yo u c an see the same bo ring text and the same bo ring images are rearranged, so the text flo ats aro und the image, first to the right o f the image and then to the left.
397
398
Part V ✦ Lay It Out Like the Pros
The CSS used to c reate this effec t fo llo ws:
IMG.left { float: left; margin-left: 1.5cm; margin-right: 10pt; } IMG.right { float: right; margin-right: 1.5cm; margin-left: 10pt; }
Figure 34-7: Text floating around im ages
The flo at pro perty is no t perfec tly implemented in either Internet Explo rer 5 o r Netsc ape 4.7. Generally, Internet Explo rer suppo rts mo re o f the CSS pro perties. So me c o mbinatio ns o f pro perties give strange and unpredic table results, so yo u need to test yo ur wo rk c arefully.
Floating both the text and the image Figure 34-8 is the result o f applying the flo at pro perty to bo th the P elements and the IMG elements. In Internet Explo rer, this c o mbinatio n has no visible effec t
Chapter 34 ✦ Positioning Graphics and Text
and the result lo o ks exac tly the same as Figure 34-7, where the flo at pro perty is o nly applied to the IMG element. As yo u c an see, Netsc ape do es no t handle this c o mbinatio n well.
Figure 34-8: Netscape has problem s w ith the float property being applied to both the P elem ent and the IMG elem ent.
Floating only the text Neither bro wser wants to have the flo at pro perty assigned to the text. Bo th bro wsers want to have the flo at pro perty assigned to the IMG element. The result o f applying the flo at element to the text element (in this c ase, the P element) varies by bro wser, but is equally unappealing in bo th bro wsers, as c an be seen in Figures 34-9 and 34-10.
The order of the HTM L matters If yo u use the same CSS that was effec tive in Figure 34-7, but c hange the HTML so the IMG element appear afte r bo th P elements, then yo u get different and unsatisfac to ry results, as yo u c an see in Figures 34-11 and 34-12.
399
400
Part V ✦ Lay It Out Like the Pros
Figure 34-9: Netscape can’t handle floating w hen the float property is applied to the text, rather than to the IMG elem ent.
Figure 34-10: Internet Explorer doesn’t even try to float anything w hen the float property is applied to the text, rather than to the im age.
Chapter 34 ✦ Positioning Graphics and Text
Figure 34-11: Netscape chokes if the IMG elem ent is listed in your HTML after the P elem ent.
Figure 34-12: Internet Explorer doesn’t seem to understand that the IMG elem ent should float next to the preceding P elem ent, even w hen the IMG elem ent w ill be floating to the right of the P elem ent.
401
402
Part V ✦ Lay It Out Like the Pros
From Here CrossReference
Jum p to Chapter 37 and learn how to create still graphics for the Web. Proceed to Chapter 35 and learn m ore cool CSS positioning tips and tricks.
Summary In this c hapter, yo u learned ho w to po sitio n text and graphic s using a variety o f tec hniques, inc luding frames, the po sitio n pro perty, the flo at pro perty, c hanging margins and padding o f text blo c ks, and c hanging margins o f the BODY element. Yo u also learned so me o f the implementatio n sho rtc o mings o f the two leading bro wsers: Internet Explo rer 5 and Netsc ape 4.7.
✦
✦
✦
35 C H A P T E R
Cool CSS Positioning Tips and Tricks
✦
✦
✦
✦
In This Cha pter Creating co lumns o f text
I
n this c hapter, yo u see mo re CSS po sitio ning tric ks. Spec ific ally, yo u learn ho w to lay o ut yo ur page in ways that simply weren’t po ssible befo re CSS. Yo u learn ho w to c reate newspaper c o lumns. Yo u see ho w (finally!) yo u c an superimpo se text o ver graphic s to title yo ur image o r to anno tate yo ur image. Yo u also learn ho w to c reate pull quo tes. This c hapter assumes yo u have read (and understo o d) all previo us c hapters abo ut CSS.
Creating Columns of Text Yo u c an use CSS to c reate c o lumns o f text. Fo r a brief mo ment in time, o ne draft o f the CSS2 spec ific atio n inc luded a pro perty fo r real newspaper c o lumns. It enabled yo u to c reate text c o lumns that dynamic ally resized themselves to fit o n the page. It dec ided ho w muc h o f the text sho uld go in the first c o lumn and ho w muc h sho uld go in subsequent c o lumns, so eac h c o lumn was the same length. Unfo rtunately, this pro perty (c alled columns), alo ng with a ho st o f related pro perties that permitted c usto mizatio n o f c o lumns, has been dro pped fro m the CSS2 spec ific atio n. It is being c o nsidered, under the c atc hy name Multi-co lumn layo ut in CSS, fo r inc lusio n in CSS3, the next versio n o f CSS, whic h is still in wo rking draft o n a c o mpo nent-by-c o mpo nent basis. Fo rtunately, yo u c an still c reate c o lumns o f text with CSS, but yo u simply must do mo re o f the wo rk yo urself. To c reate c o lumns o f text, use the DIV element (yo u will rec all this is
Superimpo sing text and g raphics Creating pull quo tes
✦
✦
✦
✦
404
Part V ✦ Lay It Out Like the Pros
used to fo rmat and gro up multiple blo c k-level elements). Yo u also need mo st o f the fo llo wing pro perties in yo ur style sheet:
✦ width. This pro perty tells the bro wser ho w wide to make eac h c o lumn. Yo u c an use a perc entage o r a value. Generally, using a perc entage is safer, in c ase the bro wser windo w isn’t o pen in full-sc reen mo de.
✦ float. This pro perty puts the text c o lumn either o n the right o r the left. Even tho ugh the o nly o ffic ial values available to yo u fo r this pro perty are right, left, o r no ne, Internet Explo rer do es suppo rt a c enter value fo r this pro perty.
✦ border. If yo u want to put a bo rder between yo ur c o lumns o f text, yo u c an use o ne o r mo re o f the bo rder pro perties to do this.
✦ margin. Yo u might need either margins o r padding to fo rmat yo ur text c o lumns to yo ur satisfac tio n.
✦ padding. Padding c an help pro vide white spac e between the c o lumn o f text and the bo rder, if yo u use o ne.
✦ text-align. Yo u c an use the text-align pro perty to fully justify yo ur text, so neither the left no r the right edge o f the text is jagged. If yo u want the text to lo o k like newspaper text, yo u definitely want to set text-align to justify. Figure 35-1 sho ws two sample c o lumns c reated using CSS.
Figure 35-1: Creating text colum ns w ith CSS
Chapter 35 ✦ Cool CSS Positioning Tips and Tricks
The HTML used to c reate these c o lumns is simple:
Chapter 35 Examples
The CSS used to c reate the c o lumns is a bit mo re interesting:
DIV.left { width: 40%; text-align: Justify; float: left; padding-right: 0.3in; border-right: solid thin; margin-left: 1cm; } DIV.right { width: 40%; text-align: Justify; float: right; padding-left: 0.25in; margin-right: 1cm; } No tic e o nly the left c o lumn has a bo rder. Yo u c o uld just as easily have put the bo rder o n the left-hand side o f the right c o lumn. In either c ase, yo u must be c areful no t to use the margin pro perty to c reate white spac e o n the side o n whic h yo u have the bo rder. Use padding o n that side instead (remember, the bo rder is drawn between the margin and the padding). Netsc ape 4.7 do esn’t suppo rt this implementatio n o f the float pro perty.
Superimposing Text and Graphics The z-index pro perty, mentio ned briefly in Chapter 33, is just the tic ket fo r layering text and graphic s, o nly text, o r o nly graphic s. In Figure 35-2, the z-index pro perty is used to superimpo se text — in this c ase, a c aptio n o n an image.
405
406
Part V ✦ Lay It Out Like the Pros
Figure 35-2: Text superim posed on a graphic
Again, the HTML is simple:
This Team’s rims provided by:
The CSS uses the z-index pro perty, whic h layers the element with the lo wer z-index value o n to p o f elements with higher z-index values.
IMG.under { position: absolute; top: 10; left: 20; z-index: 300; } P.over { position: absolute; z-index: 100; font-size: 18pt;
Chapter 35 ✦ Cool CSS Positioning Tips and Tricks
font-family: sans-serif; top: 100; left: 20; color: Fuchsia; } The z-index pro perty is no t implemented in Internet Explo rer 5.
Creating Pull Quotes No t muc h has been written abo ut c reating pull quo tes, but they c an be an attrac tive additio n to yo ur Web page. Pull quo te s c an draw attentio n to a few key wo rds o r sentenc es that summarize a tho ught, thus giving the visito r a quic k idea o f the po int o f the page. This is espec ially impo rtant if a lo t o f text is o n the page. Web visito rs have bec o me used to gleaning the message o f the page fro m a c o mbinatio n o f things, o f whic h text is o nly a small part. So me visito rs wo n’t sit still to read an entire page o f text unless yo u c an grab them with a snappy quo te. Pull quo tes c an do this fo r yo u. Figure 35-3 sho ws an effec tive use o f c o lumns and pull quo tes to gether.
Figure 35-3: Pull quotes used in com bination w ith colum ns
407
408
Part V ✦ Lay It Out Like the Pros
The HTML, as yo u’ve bec o me used to seeing, is simple:
Pull Quotes Example
The CSS is mo re c o mplic ated:
DIV.left { width: 35%; text-align: Justify; float: left; padding-right: 0.2in; border-right: solid thin; margin-left: 1cm; } DIV.right { width: 45%; text-align: Justify; float: right; padding-left: 0.3in; margin-right: 1cm; } IMG.icon { float: left; margin-left: .2in; margin-right: .2in; } P.pull {
Chapter 35 ✦ Cool CSS Positioning Tips and Tricks
font: 18pt Helvetica blue; border-top: thin blue solid; border-bottom: thin blue solid; } The DIV.left and DIV.right rules sho uld lo o k familiar. The IMG.icon rule also has no thing new. No tic e the CSS fo r the pull c lass o f the P element do esn’t use any advanc ed CSS pro perties. No tic e, to o , the flo at value o f the DIV.left rule is le ft. Also no tic e the float pro perty o f the IMG.icon rule is le ft. Bec ause the DIV element c o ntains the IMG element (in the previo us HTML), this means yo u c an flo at an element within ano ther flo ated element. No ne o f this wo rks in Netsc ape 4.7, due to its lac k o f suppo rt fo r the float element. Figure 35-4 sho ws ho w Netsc ape handles this example.
Figure 35-4: Netscape’s lack of support for the float property leaves this page unintelligible.
From Here CrossReference
Go to Chapter 39 to learn to design Im agem aps. Jum p to Chapter 47 for an introduction to Dynam ic HTML. Proceed to Chapter 37 and begin creating still graphics for the Web.
409
410
Part V ✦ Lay It Out Like the Pros
Summary This c hapter has given yo u so me ideas o f the interesting ways yo u c an use the CSS pro perties yo u learned in the previo us c hapters. It intro duc ed layering o f text and graphic s with the z-index pro perty. It sho wed yo u ho w to c reate text c o lumns with the width and float pro perties. It also demo nstrated ho w to c reate pull quo tes to draw attentio n to a phrase o r sentenc e fro m a bo dy o f text. Yo u are no w fully armed to write CSS. Part VI sho ws yo u ho w to add senso ry exc itement and interac tivity.
✦
✦
✦
36 C H A P T E R
Structuring M ultipage Sites
✦
✦
✦
✦
In This Cha pter
N
o w it’s time to mo ve fro m defining the message o f yo ur site to the delivery o f that message o n Web pages. In this c hapter, we disc uss the variety o f c ho ic es yo u have to implement a multipage site and the pro s and c o ns o f eac h c ho ic e. We talk abo ut the pitfalls to avo id when c reating multipage sites. This c hapter disc usses the types o f o rganizatio n and the arc hitec tures available to yo u when yo u build a multipage site. Navigatio n also figures pro minently in this c hapter. If yo u are go ing to have mo re than o ne page in yo ur site, yo u need to have a lo gic al, intuitive, c o nsistent way fo r yo ur visito rs to get aro und it. Finally, we disc uss maintaining yo ur site.
Possibilities and Problems of M ultipage Sites Mo st Web sites are implemented ac ro ss multiple pages. Isn’t that the great thing abo ut the Web? Yo u c an break up yo ur c o ntent by type and gro up it to gether, so if visito rs to yo ur site o nly want to kno w ho w to o rder spare parts fo r the exerc ise equipment yo u manufac ture, they needn’t read thro ugh all yo ur marketing literature and the entire servic e manual. Go o d and bad things exist abo ut breaking yo ur c o ntent into multiple pages: bo th fo r yo u, as the Webmaster, and fo r yo ur visito rs. First, let’s lo o k at the pro s and c o ns fo r yo ur visito rs (bec ause tho se sho uld rec eive greater weight in yo ur c alc ulus).
Po ssibilities and pro blems o f multipag e sites Dividing the site Dividing co ntent Site architecture Pro viding navig atio n aids Maintaining a multipag e site Bo nus: Maintaining a really larg e W eb site
✦
✦
✦
✦
412
Part V ✦ Lay It Out Like the Pros
The Pros of multipage sites for your visitors Yo ur visito rs c an (theo retic ally) find what they want witho ut having to read thro ugh everything o n yo ur site. It is a great feeling to go to a site with a c lear idea o f what yo u want and to find it within two o r three c lic ks, even when yo u have never been to that site befo re. Visito rs will return to suc h a site o ften. A site is ric her with multiple pages. There is mo re c o ntent to c ho o se fro m. A welldo ne multipage site gives visito rs the c ho ic e o f kno wing a little o r a lo t abo ut the to pic in whic h they are interested. All the info rmatio n visito rs need is there. While visito rs c ertainly do n’t want all the info rmatio n at o nc e, they may eventually want all the info rmatio n. One o f the nic e things abo ut the Web is suppo sed to be that yo u do n’t have to wait o n ho ld to get answers.
The Cons of multipage sites for your visitors Navigatio n c an be c o nfusing. What may be o bvio usly c lear direc tio ns to yo u may no t even be no tic ed by visito rs, espec ially first-time visito rs. So metimes subtle imagemaps (graphic s with ho t spo ts that, when c lic ked, take yo u so mewhere else, just like hypertext), whic h may be o bvio us to the designer, may no t be at all o bvio us to visito rs. This is so mething yo u c an avo id with go o d design. Figures 36-1 and 36-2 sho w two Web sites, o ne with subtle navigatio nal to o ls and o ne with very c lear navigatio nal to o ls. Definition
Imagemap. An imagemap is an im age w ith clickable regions. Each clickable region acts as a hyperlink. Plenty of free or cheap softw are exists to help you convert an im age into an im agem ap. This tool is built in to m any HTML editors.
CrossReference
For an in-depth exam ination of im agem aps, including instructions for creating one, see Chapter 39.
Lo ading time c an bec o me a pro blem with multipage sites. If visito rs have to wait fo r big, c umberso me graphic s to lo ad fo r eac h page, they may well get impatient. Fo rtunately, tec hnic al and design so lutio ns exist to help avo id this pro blem, whic h we disc uss later. Printing c an be mo re c o mplic ated. If the c o ntent yo u have split into multiple pages is so mething yo u imagine peo ple may want to print, and they have to go to mo re than o ne page to print the entire thing, then dividing the c o ntent into multiple pages is a hassle fo r yo ur visito rs. Of less impo rt, but c ertainly wo rth mentio ning, are the pro s and c o ns o f develo ping a multipage Web site to yo u, the Webmaster.
Chapter 36 ✦ Structuring M ultipage Sites
Figure 36-1: Can you find the navigational tools on this site? Perhaps too subtle. © Poetry Daily.
Figure 36-2: How about on this site? Much m ore obvious, don’t you think?
413
414
Part V ✦ Lay It Out Like the Pros
The Pros of developing a multipage site Yo u c an break up yo ur c o ntent into manageable piec es. Fo r mo st sites, this is go ing to be nec essary. The questio n yo u must answer thro ugh the rest o f this c hapter is: Ho w do I break up the c o ntent? Breaking up yo ur c o ntent is great if a team is develo ping yo ur site. Eac h Web page is sto red in a separate file, so if yo u had several peo ple writing to the same file, yo u’d have a mess. Dividing the wo rk amo ng the team members is muc h easier when the site is also divided. Updating yo ur c o ntent is easier. Different pages require different update frequenc ies. Muc h o f the site yo u sho uld be able to leave alo ne fo r mo nths at a time (the “Co ntac ting Us” page, fo r example), whic h leaves yo u mo re time to update the pages that do need wo rk.
The Cons of developing a multipage site If yo u aren’t fo c used o n yo ur message and yo ur visito rs’ needs, yo u c o uld end up breaking c o ntent unnec essarily. This is a majo r inc o nvenienc e fo r yo ur visito rs, who wo n’t kno w intuitively where to go to find what they need. Maintenanc e o f multipage sites requires mo re o rganizatio n. Yo u are go ing to have mo re files to mo nito r. Espec ially if yo u are wo rking with a team, yo u need to have go o d o rganizatio nal skills and even to o ls that fac ilitate o rganizatio n to make sure no thing falls between the c rac ks and yo u do n’t have two peo ple o verlaying eac h o ther’s wo rk. CrossReference
Chapter 8 has detailed inform ation about team and site m anagem ent tools.
Dividing the Site Ho w do yo u divide yo ur c o ntent? Inc luded in this questio n is ho w much do yo u divide yo ur c o ntent? The tric ky part is dec iding ho w to break up yo ur c o ntent and ho w to indic ate to yo ur visito rs that the c o ntent yo u have available is available. This is o ne o f the two main questio ns yo u want to have answered by the end o f this c hapter. The o ther main questio n is: Ho w do yo u pro vide navigatio n aro und yo ur site? First, we address dividing yo ur c o ntent. Yo u c an divide yo ur c o ntent in three ways, assuming it needs to be divided at all. These are as fo llo ws:
✦ By o riginatio n o f c o ntent ✦ By type o f c o ntent ✦ By visito r type
Chapter 36 ✦ Structuring M ultipage Sites
By origination of content If yo ur o rganizatio n is large eno ugh to have multiple departments, then yo u may think o f dividing yo ur c o ntent by where the c o ntent c o mes fro m o r the func tio nal gro up that o wns that c o ntent. In this appro ac h, yo ur Web site o rganizatio n reflec ts yo ur o rganizatio nal c hart to so me degree. Figure 36-3 sho ws an example o f an o rganizatio nal c hart.
Over the Web Organization Chart President
Sales and M arketing
Customer Service
Technical Support
Human Resources
Finance
Sales
Payroll
M arketing
Accounting
Production
Research
Figure 36-3: An organizational chart
It may make sense to divide the site by func tio nal unit. In the c ase o f Over the Web, the Web site may be o rganized as sho wn in Figure 36-4. Just bec ause o nly o ne bo x exists fo r an item (say, pro duc t listings) do esn’t mean there is o nly o ne page; it’s just easier to represent it that way fo r this example. Links, whic h simply aren’t apparent in this type o f site map, wo uld be ac ro ss the c hart. Fo r example, “Co ntac ting us” may merit its o wn link o n the highest level; yo u’d indisputably want to link to it fro m at least the “Online sho pping” page (in c ase visito rs have questio ns befo re they o rder), the Press page, and the Jo b listings page. This is also true with “Info rmatio n abo ut upc o ming versio ns,” whic h is listed under Researc h; marketing wo uld c ertainly want to link to that. Dividing yo ur site by where the c o ntent o riginates is no t a bad way to go , but read thro ugh the o ther two systems befo re yo u c o mmit to it. Fo r large o rganizatio ns, this may be the o nly way to manage yo ur c o ntent reaso nably. If yo u use links effec tively, this type o f o rganizatio n c an appear intuitive and seamless. If yo u use links po o rly, o r if c o mmunic atio n between departments (o r Web builders in different departments) is po o r, it c an lo o k like the right hand do esn’t kno w what the left hand is do ing.
415
416
Part V ✦ Lay It Out Like the Pros
By type of content Ano ther way to o rganize yo ur site is by type o f c o ntent. This o rganizatio nal sc heme o ften results in a similar site map to the previo us system o f site o rganizatio n, by func tio nal unit o f yo ur o rganizatio n. The differenc e in breaking up yo ur c o ntent by type is that yo u are less interested in where the info rmatio n fo r the c o ntent c o mes fro m than what type o f info rmatio n it is. Fo r example (fro m the prec eding example), the financ e department is the plac e where strategic allianc es are bro kered. They are the o nes who make these arrangements, but who wo uld think to lo o k there? Figure 36-5 reflec ts this new info rmatio n.
Over the Web Site M ap
Welcome page
Sales
M arketing
Technical Support
Human Resources
Finance
Product listings
Lists of features
FAQs
Job listings
Financial reports
Information about purchasing
Specials and bundles
Contacting us
Testimonials of happy employees
Investor information
Online shopping
Upgrade information
Research
Organizational chart
Happy client testimonials
Aw ards and positive review s
Press page w ith press releases
Figure 36-4: A site m ap based on the preceding organizational chart
W hite papers
Information about upcoming versions
Chapter 36 ✦ Structuring M ultipage Sites
Even if the marketing department has a link to the Financ e page o r the Strategic allianc es page, yo u have to wo nder if that is adequate pro minenc e fo r this info rmatio n. If the marketing department isn’t invo lved in arranging these allianc es, then they pro bably wo n’t be enthusiastic abo ut pro mo ting them; hec k, they may no t even be aware o f them! Ano ther o bvio us plac e to questio n the lo gic o f the site o rganizatio n, sho wn in Figure 36-5, is in the separatio n o f sales fro m marketing. Wo uldn’t it make sense that a features list wo uld be so mething yo u’d want to see o n the way fro m Pro duc t listings to Online sho pping?
Over the Web Organizational Chart President
Sales and M arketing
Customer Service
Technical Support
Human Resources
Finance
Sales
Payroll
M arketing
Accounting
Production
Research
Strategic alliances
Figure 36-5: This organizational chart reflects that the finance departm ent negotiates strategic alliances.
If this site were no w to be o rganized by type o f info rmatio n, instead o f o rigin o f info rmatio n, then Figure 36-6 reflec ts what the site map wo uld lo o k like.
By visitor type Ano ther way to o rganize yo ur site is by yo ur visito rs’ interests. Remember them? We always c o me bac k to them eventually and so will yo u. Can yo u break yo ur visito rs into gro ups? Say, members and no nmembers? That’s to o easy. Here are so me o ther examples: end users, pro grammers, and o ther interested parties; do c to rs and patients; ac tivists and c itizens; c lients, po tential c lients, and o thers. Whatever divisio n yo u c o me up with, o the rs will always be the last gro up in the list. This is simply the nature o f the Web. Yo u c an’t predic t who is go ing to sho w up o n yo ur site.
417
418
Part V ✦ Lay It Out Like the Pros
Over the Web Site M ap Welcome page
Product information and ordering
Press page
FAQs
Contacting us
Specials and bundles
Happy client testimonials
Aw ards and positive review s
Information about upcoming versions
Upgrade information
Product listings
Lists of features
Online shopping
Information about purchasing
Figure 36-6: Organization by type of content
Human Resources
Finance
W hite papers
Job listings
Financial reports
Testimonials of happy employees
Investor information
Organizational chart
Chapter 36 ✦ Structuring M ultipage Sites
To c o ntinue with this example, Over the Web has dec ided to c o nsider breaking up their site by visito r type. They have bro ken their visito rs into the fo llo wing gro ups: c usto mers (o r peo ple who are interested in bec o ming c usto mers), the press, jo b hunters, investo rs, pro grammers, and o thers. Bec ause kno wing what o the rs want to see is impo ssible, they wo n’t have their o wn pages. Figure 36-7 sho ws an attempt at reo rganizing the site alo ng these lines.
Dividing Content Ho w muc h info rmatio n go es o n a page? Even if yo u have determined whic h o f the previo us mo dels suits yo ur site best, yo u still may need to break up c o ntent within eac h sec tio n as well. Within what we represented as the Press page in the prec eding example, will everything go o n o ne page o r will there be multiple pages? Ho w do yo u dec ide? So me o f the fac to rs yo u need to c o nsider are as fo llo ws:
✦ What info rmatio n do visito rs need to see at o nc e? Do n’t think in terms o f the length o f the material; think in terms o f the use o f the material. Ho w do yo u antic ipate the info rmatio n being used? Mo st o f the time, these dec isio ns are between having o ne lo ngish page and breaking the same material into multiple pages. If yo u think mo st o f the peo ple who c o me to the first part o f yo ur material will pro c eed in a linear manner thro ugh the material, then save them the tro uble and put all the material o n o ne page.
✦ Will visito rs be printing this info rmatio n? If yo u want yo ur visito rs to be happy with their experienc e o f visiting yo ur site, do n’t anno y them by dividing info rmatio n they may want to print. Sure, so me peo ple print everything and yo u c an’t plan aro und them, but so me pages just lend themselves to printing. One example o f this is a review o f a bo o k o r a so ftware pac kage. Ano ther is instruc tio ns. Who wo uld want to print o nly half a set o f instruc tio ns?
✦ As yo u pro vide the info rmatio n visito rs need, are there po ints where visito rs may want to go mo re than o ne plac e? If yes, then sto p the page and give the visito r c ho ic es o f plac es to go . If no , then c o ntinue the page.
✦ What abo ut the no tio n yo ur visito rs sho uld never have to sc ro ll? This is a c razy idea. Sure, yo u want the sc reen that visito rs see to lo o k c o mplete, but this do esn’t mean every time yo u have eno ugh text to fill a sc reen, yo u sho uld fo rc e the visito r to c lic k and wait to link to what is really o nly a c o ntinuatio n o f the same material. User Interfac e Engineering ( http://world.std.com/ ~uieweb) did a study that sho wed visito rs do n’t mind sc ro lling to get to the info rmatio n they are seeking.
419
420
Part V ✦ Lay It Out Like the Pros
Over the Web Site M ap Welcome page
Customers
Specials and bundles Happy client testimonials
Press
Job hunters
Investors
Job listings
Financial reports
Testimonials of happy employees
Investor information
Aw ards and positive review s
Information about upcoming versions Upgrade information Product listings Lists of features Online shopping
Information about purchasing
FAQs
Contacting us
Figure 36-7: A site m ap by visitor type
Organizational chart
Programmers
Chapter 36 ✦ Structuring M ultipage Sites
Site Architecture We’ve already to uc hed o n site arc hitec ture, but it deserves mo re attentio n. What is the arc hitec ture o f yo ur site go ing to be? Bec ause we are c o nfined to a two dimensio nal spac e, the previo us site maps all lo o k hierarc hic al. That is simply the easiest way to represent a site. In fac t, a site map may lo o k mo re like the o ne represented in Figure 36-8.
Happy client testimonials
Aw ards and positive review s
Customers
Specials and bundles
Press
Information about upcoming versions
Welcome Investors Job hunters Financial reports
Investor information
Organizational chart
Upgrade information Job listings Programmers Testimonials of happy employees
Figure 36-8: Mapping your site in a nonhierarchical w ay is m essy.
Site arc hitec ture has to do with the way that pages link to eac h o ther. On o ne extreme, there is a linear site arc hitec ture, where yo u to rture yo ur visito rs by fo rc ing them to c lic k a link to get to ano ther page, where there still are no c ho ic es. On the o ther extreme, there is the c o mpletely anarc hic al arc hitec ture, where pages link to eac h o ther witho ut any struc ture behind the links — c all it stre am-o fco nscio usne ss arc hitec ture. In the middle, yo u have hierarc hic al sites. We disc uss all three o f these in the fo llo wing sec tio ns.
421
422
Part V ✦ Lay It Out Like the Pros
Linear architecture: The forced march Hypertext is suppo sed to give readers the c o ntro l to dec ide what they want to learn abo ut next and when they want to kno w mo re. Only a c o ntro l freak wo uld wo rk in this freedo m-lo ving medium and then try to deny visito rs their rights as Web surfers. Peo ple do n’t espec ially like to sit thro ugh presentatio ns. When yo u arrange yo ur site with linear arc hitec ture, this is what yo u fo rc e yo ur visito rs to do . Line ar archite cture assumes that pretty muc h everyo ne wants to see pretty muc h everything. There are times when linear arc hitec ture may be appro priate fo r a po rtio n o f yo ur site. Suppo se yo u have a site that, amo ng o ther things, has a virtual museum exhibit. In mo st museum exhibits, the material is arranged in a partic ular o rder fo r a partic ular reaso n. Ho w might the site map lo o k fo r this kind o f arc hitec ture? See Figure 36-9.
M useum Site M ap Welcome page Type title here
M embership information
How to join List of sponsors
Hours of operation and directions
M useum Shop
Exhibits
List of exhibits History behind exhibit Exhibit begins Item 1 Item 2
Item 3 Item 4, etc. W here to find more information
Figure 36-9: Site m ap including a linear section
Information about upcoming exhibits
Etc.
Chapter 36 ✦ Structuring M ultipage Sites
The key to using linear arc hitec ture is to no t apply it to the entire site. Certain areas o f a site may lend themselves to a linear appro ac h, but it is inc o nc eivable that the entire site sho uld be a fo rc ed marc h. Other times yo u may need to use a linear arc hitec ture are when giving quizzes (a quiz to determine whether yo u are left-brained o r right-brained) and when giving a virtual to ur (o f the Blue Ridge Mo untains o n Sc enic Drive in Virginia).
Hierarchical architecture Hie rarchical archite cture depends o n the idea o f gro uping c o ntent by so me c riteria, and then pro viding a list o f the members o f the gro up. Eac h item in a gro up c an also be a gro up, but yo u c an get c arried away with this if yo u are no t c areful. Eventually, yo ur visito rs want to c o me to so mething o ther than a list o f items. They want to c o me to real c o ntent. Real c o ntent is so mething mo re substantive than a list o f plac es to go (unless yo ur site is a transit site and then this do esn’t apply). Mo st sites use a hierarc hic al arc hitec ture fo r the framewo rk. All the previo us examples use a hierarc hic al arc hitec ture.
Hierarc hic al arc hitec ture is a useful way to o rganize yo ur site. It is relatively easy to map and to divide a hierarc hic al site fo r team develo pment and maintenanc e. Best o f all, visito rs understand the idea o f a hierarc hic al site, where eac h subsequent page has a greater level o f detail until, eventually, they find the material they were seeking.
Avoid extreme devotion to hierarchy Slavish adherenc e to hierarc hic al arc hitec ture c an be a pro blem. Visito rs sho uld no t have to c lic k mo re than two o r three times to get to a page where it is c lear to them they are at least in the neighbo rho o d o f the material they need. What makes yo u have a po sitive experienc e o n a site? Yo ur perc eptio n. If yo u fe e l like yo u c an find the info rmatio n yo u want — based o n the navigatio nal c o ntro ls visible to yo u o n the Welc o me Page o r yo ur previo us visits to this site — and within two o r three c lic ks yo u get to the neighbo rho o d where yo u believe the info rmatio n sho uld be and then two c lic ks later, yo u find it, yo u have a po sitive experienc e with that site. Yo u do n’t feel like yo u wasted yo ur time (o r wo rse yet, that the y wasted yo ur time). If yo u keep c o ming to lists that either do n’t have the level o f detail yo u need o r a vo c abulary yo u rec o gnize, then yo u get frustrated and leave. Visito rs sho uldn’t have to c lic k fo ur o r five times to feel they are finally in the right area. Isn’t this why site searc hes are so po pular? When yo u go to a site where yo u do n’t kno w if they have what yo u want, yo u c lic k Searc h o n the Welc o me page. On the Searc h page, yo u type yo ur keywo rds and c lic k Find. Then yo u see the list o f pages. That was two c lic ks. Yo ur keywo rds may have been o verly bro ad and yo ur searc h may no t have been effec tive, but, within two c lic ks, yo u feel yo u c an find what yo u c ame to find o r yo u learn the site do esn’t have what yo u were lo o king fo r and yo u go elsewhere.
423
424
Part V ✦ Lay It Out Like the Pros
Visito rs failing to find what they want o n a site, by the way, is no t a disaster. Yo ur visito rs c an have a po sitive experienc e o n yo ur site even if they do n’t find what they want, as lo ng as they quic kly realize they aren’t go ing to find it, and they are c o nfident they aren’t missing it o nly bec ause o f the site’s o rganizatio n. When yo ur visito rs begin to think, “It must be here so mewhere, I just c an’t find it,” c lic k aro und yo ur site fo r 20 minutes lo o king fo r it, and then finally leave, this has no t been a po sitive experienc e!
Anarchy So und emanc ipating? Fo rget it. Anarc hy o nly wo rks fo r really small sites. An anarchical hie rarchy (a c o ntradic tio n in terms?) is based o n the idea that o rganizatio n isn’t nec essary and visito rs o nly want to wander thro ugh the site, no t lo o king fo r anything in partic ular. They c an c lic k any link they find, but no guarantee exists they c an ever get bac k to a page they visited, unless they c lic k the bac k butto n the c o rrec t number o f times. This feeling o f gro undlessness that anarc hy c reates is no t po sitive fo r visito rs. They aren’t familiar with this feeling and it assumes visito rs have no thing better to do than wander aimlessly aro und yo ur site. It may wo rk if yo ur audienc e c o nsists o f c o llege students with free Internet ac c ess and a need to avo id studying, but unless yo u are really c lever with this appro ac h, it will fail and so will yo ur site.
A seamless web Ho w, then, do yo u c reate the feeling that yo ur site is a seamless web o f related c o ntent, the page visito rs want is o nly a c lic k o r two away, and visito rs will be able to find this c o ntent again? Yo u need to find the right c o mbinatio n o f the vario us arc hitec tures fo r yo ur c o ntent and yo u need go o d, c o nsistent navigatio nal to o ls. The fo llo wing rules will help:
✦ Have a search option on your site. This requires that yo ur site be indexed. So ftware that indexes sites is inc luded with many Web servers (espec ially NT Web servers). Unfo rtunately, installing indexing so ftware o n UNIX servers is a bit o f a trial. If yo u have an internal server, ask yo ur systems administrato r abo ut this o ptio n. If yo u have an ISP, ask them. Espec ially as yo ur site gro ws, yo ur visito rs will benefit greatly fro m the ability to searc h yo ur site. Being able to searc h if yo u keep arc hival info rmatio n o n yo ur site is also useful. Often arc hival info rmatio n is o nly available by searc h (it is no t linked into the c urrent material o n yo ur site).
✦ Have navigational controls in the same place on every page. We disc uss this further in the next sec tio n. It is that impo rtant.
Chapter 36 ✦ Structuring M ultipage Sites
✦ Don’t be afraid to link across divisions. Linking fro m a page full o f highly tec hnic al info rmatio n abo ut yo ur pro duc t to a page o f jo b listings in yo ur c o mpany makes perfec t sense if yo ur c o mpany needs peo ple who are highly tec hnic al. Info rmatio n abo ut c o ntac ting yo ur c o mpany (inc luding the mailing address) sho uld be available fro m lo ts o f plac es; do n’t expec t visito rs to remember they c an get to it fro m yo ur Welc o me Page. Remember: Links are free; yo ur visito rs’ time is no t. Bec ause o f all these links ac ro ss different areas, having yo ur files o rganized ac c o rding to so me fo rmal system (as disc ussed in Chapter 4) is espec ially impo rtant if yo u have a team wo rking o n yo ur site. Otherwise, yo ur team members may rearrange their o wn files, no t realizing they just bro ke all yo ur links.
✦ Select an architecture and be consistent. Visito rs want to kno w what to expec t. Whic hever arc hitec ture yo u selec t, be c o nsistent and make it o bvio us to visito rs. They do n’t want to learn different site navigatio n o n eac h page.
Providing Navigational Aids No w it’s time to think abo ut visito rs again. We wo n’t let yo u fo rget them fo r a while. Whic hever arc hitec ture yo u selec t, yo ur jo b is to make getting aro und yo ur site easy fo r visito rs. They need to kno w ho w to get to what they seek, ho w to get bac k to the Welc o me page, and ho w to find what they seek o n subsequent visits. Yo u c an use several to o ls to make the pro c ess o f navigating aro und yo ur site as painless as po ssible fo r yo ur visito r. Let’s start with the ideal: In the ideal wo rld, yo ur site wo uld be able to read visito rs’ minds (o r read so me so rt o f c o nfiguratio n file their bro wsers pro vide) to give them a Welc o me page that sho wed exac tly what they were seeking. Yo u c an’t do this to day, but no tec hnic al reaso n exists why yo u c o uldn’t do it (if no t the mind-reading part, at least the c o nfiguratio n file part) in a few years. Mo re realistic ally, yo u c an pro vide so me o r all o f the fo llo wing devic es to make navigatio n intuitive and easy fo r yo ur visito rs:
✦ Table of contents. Easy eno ugh, right? Using c lient-side sc ripting tec hniques (yo u learn abo ut these later, and they are o nly available in HTML 4), yo u c an even make yo ur table o f c o ntents e xpand and re tract. This means if visito rs c lic k a sec tio n heading, they see a listing o f the c o ntents o f that sec tio n, right o nsc reen, witho ut go ing elsewhere. If they c lic k a different sec tio n heading, the details o f the first sec tio n they c lic ked retrac ts and the new sec tio n expands. What a great way to give yo ur visito rs the info rmatio n they need, c o nserve sc reen real estate (mo re o n this later), and avo id making users bo unc e all o ver the plac e!
425
426
Part V ✦ Lay It Out Like the Pros
✦ Search function. We talked abo ut this previo usly. It isn’t muc h extra wo rk to index yo ur site and pro vide fo r searc hing. Yo u c an find plenty o f free o r inexpensive to o ls to do this if yo ur Web server do esn’t inc lude site indexing. Yo u want to make c ertain the searc h is available fro m every page. Remember: Links are free.
✦ Site Map. This o ne is a little bit tric kier to implement. Yo u need to think abo ut a way to sho w — graphic ally — where things are o n yo ur site. This is do ne mo st elegantly with JavaSc ript, but it c an be diffic ult.
✦ Consistently placed navigational bar or buttons. Of all o f these devic es, this is the easiest to implement. Nearly every dec ent site has navigatio nal butto ns o r bars. Visito rs expec t them to stay in the same plac e fro m o ne sc reen to ano ther. Do n’t surprise them.
✦ Drop-down list of places to go. This is a great way to save page real estate. Yo u c an inc lude an eno rmo us list o f plac es to go , o r a sho rt o ne, and it takes up the same amo unt o f spac e: o ne line the width o f the widest entry in yo ur list. Yo u c an use this appro ac h fo r links to sec tio ns o f yo ur site o r fo r links to yo ur pro duc t info rmatio n.
M aintaining a M ultipage Site Yo u need to start thinking abo ut many maintenanc e issues. A reaso nably c o mprehensive list fo llo ws:
✦ Schedule face-lifts to the site. While we haven’t talked abo ut the lo o k o f yo ur site yet, yo u need to make c ertain yo u update yo ur lo o k perio dic ally. Yo u do n’t want to c hange it just bec ause yo u disc o vered a new fo nt yo u like, but yo u may want to c hange it when yo ur o rganizatio n makes c hanges to marketing literature. Yo u’ll also want to c hange yo ur site to take advantage o f the latest tec hno lo gies and lo o ks being used by o ther c o o l peo ple o n the Web.
✦ Run link-checking software on a regular schedule. If yo ur site has mo re than a do zen pages, yo u’ll want to take advantage o f link-c hec king so ftware (see Figure 36-10). This pro duc t tests o ut every link in yo ur site and repo rts bac k with a list o f bro ken links. Ac quiring this so ftware, learning it, and running it o n a regular sc hedule is wo rth yo ur peac e o f mind.
✦ Test your site daily or find an agent to do it and to notify you if it is down. If yo ur site is ho sted elsewhere and yo u do n’t have reaso n to visit yo ur site daily, ho w will yo u kno w whether yo u are up and running o r dead in the water? A number o f ways exist to c hec k yo ur site and to make sure it is up. The easiest, but least reliable, is to go to it yo urself. Remember, every time an agent c hec ks to see whether yo ur site is up, it c o unts as a hit!
Chapter 36 ✦ Structuring M ultipage Sites
Figure 36-10: A report from link-checking softw are
✦ Keep your index up-to-date so the search is always accurate. If yo u are go ing to index yo ur site to pro vide a searc h func tio n, then yo u must be sure yo u have the index func tio n running at so me regular interval so yo ur searc h func tio n is always up to date. The index fo r a site with c o nstant c hanges sho uldn’t be maintained manually bec ause it’s a hassle. Figure 36-11sho ws Co ld Fusio n’s Verity Indexing, an auto matic way to index a dynamic site.
✦ Review and revise your content on a scheduled basis so it always sounds fresh. Do n’t take this fo r granted. Lo ts o f Webmasters publish c o ntent and fo rget abo ut it. Even a mo nth after yo u have published a page, yo u may have fo rgo tten the details o f what it says. Set aside time to review all yo ur c o ntent o n a regular basis. Is it any wo nder maintaining a Web site is so expensive?
✦ Keep your competitors’ or alliances’ information up-to-date. Pro viding a c o mpariso n c hart with features o f yo ur pro duc t and yo ur c o mpetito rs’ pro duc ts is no t generally fro wned upo n, but it is bad fo rm fo r yo ur info rmatio n abo ut yo ur c o mpetito rs’ pro duc ts to be o ut-o f-date. Peo ple will wo nder what o ther info rmatio n is inc o rrec t. If yo u are go ing to inc lude info rmatio n abo ut yo ur c o mpetito rs’ pro duc ts, keep it up!
427
428
Part V ✦ Lay It Out Like the Pros
Figure 36-11: Cold Fusion’s Verity Indexing
Bonus: M aintaining a Really Large Web Site Yo u may be getting in really deep. If yo u are o r yo u think yo u may eventually be respo nsible fo r maintaining a tho usand-page Web site, then yo u need to start thinking abo ut two things: ho w will yo u manage the info rmatio n and ho w will yo u manage the peo ple who do the wo rk? So me prac tic es yo u may want to implement are as fo llo ws:
1. Create a Central Web Team. This team will be wo rking o n the Web site full-time. 2. Have all design dec isio ns, all pro c edural c hanges, and all o rganizatio nal dec isio ns o riginate with the Central Web Team. Yo u need to set a prec edent right away that every page c an’t be unique. HTML 4 suppo rts yo ur dec isio n to c o ntro l the lo o k o f the site by pro viding yo u with style sheets. Create yo ur style sheets at this level.
Chapter 36 ✦ Structuring M ultipage Sites
3. Have c o ntent o riginate with distributed Web develo pers who are c lo ser to the c o ntent. These are basic ally lo aners to the Central Web Team. We’ll c all them the Distribute d We b Te am.
4. Have meetings o f bo th gro ups to gether. Yo u need to keep the Distributed Web Team info rmed abo ut new po lic ies yo u institute, any c hanges to servers o r ac c o unts, and pro c edures yo u implement. Yo u also want to be respec tful o f their time bec ause yo u aren’t their real bo ss and yo u want them to want to do the wo rk fo r yo u.
5. Use e-mail to no tify the Distributed Web Team o f c hanges to the lo o k and to pro c edures. Create a mailing list to no tify the Distributed Web Team o f c hanges. Co nsider having a mailing list where they c an ask eac h o ther questio ns and help eac h o ther.
6. Have written pro c edures and standards fo r publishing a page fo r the Distributed Web Team. Tell them eno ugh, but do n’t tell them mo re than they need to kno w. These are peo ple who have o ther respo nsibilities. If yo u make the Web maintenanc e part o f their jo bs to o big o f a pain (with to o muc h mail and to o many meetings), then they will put it o ff and avo id yo u. Inc lude info rmatio n abo ut linking to style sheets in yo ur written instruc tio ns, with an example — o r better yet, give them a c o py o f this bo o k.
7. Organize ac c o unts and permissio ns o n yo ur Web server so peo ple c an’t ac c identally delete o r o verlay eac h o ther’s files. What files are c alled, where they go , and ho w they get there must be part o f yo ur written pro c edures. Publish yo ur written pro c edures to a page o n yo ur Intranet so peo ple c an c hec k o n things witho ut bo thering yo u and so new members o f the Distributed Web Team c an get up to speed quic kly.
8. Fo llo w the pro c edures yo urself that yo u impo se o n the Distributed Web Team. No c heating. Yo u wo n’t exac tly inspire the trust and enthusiasm o f the Distributed Web Team if yo u do n’t have to fo llo w the rules yo urself.
From Here CrossReference
Jum p to Chapter 32 for a refresher on the essentials of Web page design. Refer to Chapter 8 and find the HTML editor that’s right for you. Proceed to Chapter 37 to learn about creating still graphics for the Web.
429
430
Part V ✦ Lay It Out Like the Pros
Summary We c o vered a lo t o f gro und in this c hapter. Yo u learned the pro s and c o ns o f develo ping a multipage site, effec tive ways to o rganize yo ur site fo r easy navigatio n, and intelligent ways to break up yo ur c o ntent into pages. Yo u also learned abo ut site arc hitec ture: go o d and bad ways to use hierarc hy, as well as times when yo u may want to mix in linear arc hitec ture into yo ur hierarc hy. Yo u learned abo ut the basic s o f navigatio nal aids to make the jo urney thro ugh yo ur Web site easy and intuitive fo r yo ur visito rs. We also c o vered the basic s o f site maintenanc e fo r mo st sites and, as a bo nus, fo r really big sites.
✦
✦
✦
37 C H A P T E R
Creating Still Graphics for the Web
✦
✦
✦
✦
In This Cha pter Understanding g raphics file fo rmats
Y
o u have been wo rking with images fo r abo ut 400 pages no w. In this c hapter, yo u learn ho w to cre ate images. Yo u learn abo ut yo ur c ho ic es fo r file fo rmats. Yo u also learn abo ut c o lo r depth (bit depth) and what yo u c an do — between file fo rmat selec tio n and bit-depth reduc tio n — to shrink the size o f yo ur file so it do wnlo ads quic kly. This c hapter also sho ws yo u ho w to c reate graphic s using two po pular to o ls, ho w to c apture graphic s yo u like fro m elsewhere, ho w to c reate image previews, and ho w to c reate transparent GIFs.
Understanding co lo r depth Enhancing do wnlo ading speed Creating g raphics Capturing g raphics Pro g ressive JPEG s and interlaced G IFs
Understanding Graphics File Formats Web bro wsers suppo rt — to so me degree — three graphic s file fo rmats: GIF, JPEG, and PNG. All three o f these graphic s file fo rmats use so me fo rm o f c o mpressio n to sto re yo ur image.
Why compression? Unc o mpressed images c an be large. Co nsider Table 37-1, whic h c o mpares image dimensio ns, number o f c o lo rs, and file size fo r so me sample unc o mpressed images. As yo u c an see, with file sizes like this, yo u wo uld have to limit yo urself to mighty tiny images, o r two -c o lo r, suc h as blac k and white, images. Or, yo u c o uld c o mpress the files.
Using transparent G IFs
✦
✦
✦
✦
434
Part VI ✦ Adding Sensory Excitement and Interactivity
Table 37-1 Uncompressed Image File Size Comparison by Image Dimensions and Number of Colors Dimensions (in Inches)
Colors
File size
1 ×1
2
9K
1 ×1
256
9K
1 ×1
16.7 m illion
18K
2 ×2
2
16K
2 ×2
256
24K
2 ×2
16.7 m illion
63K
3 ×3
2
16K
3 ×3
256
49K
3 ×3
16.7 m illion
139K
Figures 37-1 to 37-9 sho w these images with c o mpressio n. Even tho ugh these are o nly blac k and white images, to lo o k go o d, they still require a lo t o f shades o f gray. Figure 37-1: This 1 ×1-inch im age uses only tw o colors: black and w hite
Figure 37-2: The sam e 1 × 1-inch im age using 256 colors: all shades of gray
Figure 37-3: The sam e 1 × 1-inch im age using 16.7 m illion colors
Chapter 36 ✦ Creating Still Graphics for the Web
Figure 37-4: This 2 × 2-inch im age uses only tw o colors: black and w hite
Figure 37-5: The sam e 2 × 2-inch im age using 256 colors —obviously a big im provem ent
Figure 37-6: The sam e 2 × 2-inch im age using 16.7 m illion colors; notice there is no color striping as in the previous im age
Figure 37-7: This 3 × 3-inch im age uses tw o colors
Figure 37-8: The sam e 3 × 3-inch im age using 256 colors
435
436
Part VI ✦ Adding Sensory Excitement and Interactivity
Compression options When yo u implement file c o mpressio n, yo u either have to thro w away so me info rmatio n abo ut the image o r find a way to sto re the existing info rmatio n abo ut the image in a mo re intelligent manner. GIF files thro w away so me c o lo r info rmatio n. JPEG files thro w away so me info rmatio n abo ut the image itself. PNG files sto re the info rmatio n using a mo re intelligent algo rithm.
GIF GIF was the earliest fo rmat in use in inline images o n the Web. Versio n 1 bro wsers c o uld o pen GIF images inline, but required that JPEG images be o pened o ut-o f-line. GIF uses a c o mpressio n sc heme — c alled LZW co mpre ssio n — that predates Co mpu Serve, even tho ugh yo u might see it c alled Co mpuServe GIF. Co mpuServe implemented LZW c o mpressio n, thinking it was in the public sphere and then fo und o ut it was pro prietary. A lo t o f lawyers so rted it o ut. Figure 37-9: The sam e 3 × 3-inch im age using 16.7 m illion colors, w hich looks nicest, but m akes too large of a file size
Ho w do es GIF wo rk? Simply, GIF indexes images to an 8-bit palette. The system palette is 256 c o lo rs. Befo re yo u c an save yo ur file in GIF fo rmat, the utility yo u are using simply makes its best guess at mapping all yo ur c o lo rs to o ne o f the 256 c o lo rs in an 8-bit palette. Is a reduc tio n in c o lo r depth a pro blem? That depends. GIF uses dithering to ac hieve c o lo rs between two c o lo rs o n the palette. Even with dithering, ho wever, GIF images o f a sunset have stripes o f c o lo r, where a smo o th gradatio n wo uld be mo re natural. GIF images also tend to have mo re c arto o nish c o lo rs bec ause flesh to nes aren’t part o f the palette. A GIF image o f a drawing, say, o f a c hec kerbo ard, ho wever, will lo o k just fine. CrossReference
See Chapter 38 for a lesson in creating anim ated GIFs. Transparent GIFs are discussed at the end of this chapter.
Definition
System Palette. The system palette is the 256 colors your m onitor is able to display if you set your video board only to show 256 colors. These colors differ from a PC to a Mac.
Chapter 36 ✦ Creating Still Graphics for the Web
JPEG JPEG takes a different appro ac h. JPEG, in c ase yo u are c urio us, stands fo r the Jo int Pho to graphic Expe rts Gro up, the name o f the gro up that c reated the standard. With JPEG, yo u get to keep all yo ur c o lo rs, but yo u do n’t get to keep all the data abo ut the image. What kinds o f images lend themselves to being c o mpressed with JPEG? A tree. If yo u take a pho to o f a pine tree, the ac o rns are in spec ific plac es, but when the image is c o mpressed and dec o mpressed (o pened o n yo ur Web page), the c o mputer has to appro ximate where tho se ac o rns went, bec ause it had to thro w away so me o f the data. Is this a pro blem? No t with mo st pho to s o f mo st pine trees. Fac es also take well to JPEG bec ause the c o lo rs are all there; fac es in GIF c an lo o k unnatural bec ause o f the c o lo r lo ss. Every generatio n 3 and higher bro wser c an handle inline JPEGs. JPEGs are also ideal fo r sho wing gradient filled graphic s (when the c o lo r c hanges gradually fro m o ne c o lo r to ano ther). The same graphic wo uld suffer eno rmo usly under the GIF c o mpressio n bec ause all tho se in-between c o lo rs wo uldn’t be there. What suffers under JPEG c o mpressio n? Text, sc hematic drawings, and any line art. Of c o urse, with JPEG, yo u c an selec t the level o f c o mpressio n (usually either as a perc entage o r as Maximum, High, Medium, o r Lo w). Yo u generally want to use the maximum c o mpressio n level yo ur image c an handle witho ut lo sing image quality. Yo u wo n’t kno w ho w muc h c o mpressio n yo ur image c an handle witho ut lo ss until yo u try it at different levels o f c o mpressio n.
PNG The Po rtable Ne two rk Graphics, o r PNG fo rmat, was develo ped exc lusively fo r the Web and is in the public do main. The PNG fo rmat takes advantage o f a c lever way o f sto ring the info rmatio n abo ut the image so yo u do n’t lo se c o lo r and yo u do n’t lo se image quality; it is a lo ssless fo rmat. The o nly drawbac k is, bec ause the standard is so new, o nly fo urth-generatio n and later bro wsers suppo rt PNG graphic s. Eventually, PNG will replac e GIFs fo r many c o lo r-ric h still image files. Only GIFs c an suppo rt animatio n and transparenc y. Definition
Lossy versus lossless. File form ats that im plem ent com pression schem es that discard inform ation about the im age are called lossy file form ats. Both GIF, w hich discards color inform ation, and JPEG, w hich discards im age inform ation, are lossy file form ats. File form ats that don’t discard any inform ation about an im age are called lossless. PNG is a lossless com pression schem e.
Understanding Color Depth In the c o mputer wo rld, everything is blac k o r white, o n o r o ff. Co mputers o perate in the base two system, so when c reating c o lo rs, yo ur c ho ic es o f c o lo rs are base two numbers. A bit is a representatio n o f o n o r o ff (1 o r 0). One-bit c o lo r uses a two c o lo r palette (21). Two -bit c o lo r uses a fo ur-c o lo r palette (22). Eight-bit c o lo r uses a 256-c o lo r palette (28). Thirty-two -bit c o lo r uses a 16.7-millio n-c o lo r palette (232).
437
438
Part VI ✦ Adding Sensory Excitement and Interactivity
Definition
Browser-safe color palette. Betw een the tw o system palettes, there are 216 colors in com m on. This is called the 216-browser-safe palette. By lim iting your graphics to colors from this palette, you can be sure the brow ser w on’t have to guess or dither to achieve the color you w ant.
Yo u might be thinking: Two co lo rs: that’s no t so bad. An artist can do a lo t with two co lo rs; think o f the ways yo u can ble nd the m. Unfo rtunately, this isn’t ho w c o mputers wo rk. When yo u selec t a c o lo r palette, yo u get o nly the c o lo rs in that palette, no t any blends o f c o lo rs in that palette. When yo u c reate an image, yo u want to balanc e the quality o f the image against the file size o f the image. When yo u send an image file o ver the Internet to a Web page, yo u send either info rmatio n abo ut the palette o r yo u send the ac tual palette. With GIF files, yo u send a c o lo r lo o k-up table (CLUT) with the image. With JPEG files, yo u send a palette. As yo u c an imagine, this makes the files c o nsiderably larger.
Enhancing Downloading Speed The bandwidth c o nservatio n so c iety was c reated to help with these pro blems. Yo u c an find their useful Web site at www.infohiway.com/faster/index.html. What c an yo u do to ensure yo ur pages do wnlo ad quic kly? There are a few things:
✦ Limit image file sizes. ✦ Limit the number o f images. ✦ Reuse images as muc h as po ssible so images c an be lo aded fro m c ac he. ✦ Use frames so o nly part o f the bro wser windo ws need to relo ad. ✦ Use text rather than images, where po ssible; see Figure 37-10 fo r an example o f c hanging the c o lo rs o f c ells in a table to appro ximate a graphic image.
Image file sizes Yo u c an limit image file sizes
✦ by using the maximum c o mpressio n yo ur image will take ✦ by using the smallest bit-depth yo ur image c an stand ✦ by minimizing the dimensio ns o f yo ur image o n the page Test yo ur pages at 640 × 480, 800 × 600, and 1024 × 768 to see ho w they will lo o k to different visito rs. Often an image that renders well at 1024 × 768 and do esn’t do minate the page may lo o k huge and o verbearing at 640 × 480.
Chapter 36 ✦ Creating Still Graphics for the Web
Figure 37-10: Use a table w ith text instead of a graphic to create visually appealing navigational tools.
Number of images Ho w many images is the right number? Yo u may be surprised to learn that so metimes very small images with white spac e between them lo ad faster than o ne large image. Take advantage o f white spac e to c o ntribute to yo ur images. Yo u c an use two intelligent tec hniques to get mo re image fo r the byte. By c hanging the bac kgro und c o lo r to matc h the bac kgro und c o lo r o f yo ur images, yo u c an keep yo ur images smaller. By anti-aliasing the text against that bac kgro und to blend the edges into the bac kgro und c o lo r, yo u c an ac hieve the lo o k o f o ne large graphic with multiple small — and fast to lo ad — images.
Reuse images Reusing images is as simple as having a single graphic fo r “ho me” o n all yo ur pages. Have a single bullet graphic (if yo u c an’t stand to use the standard bullet) fo r every bullet o n every page. Why do es this help yo ur pages lo ad faster? Yo ur bro wser c hec ks to see whether an image it needs is already in c ac he and lo ads the image fro m c ac he, if it c an. This reduc es the number o f bytes that ac tually needs to be do wnlo aded.
439
440
Part VI ✦ Adding Sensory Excitement and Interactivity
Use frames Ho w c an using frames speed do wnlo ad time? After the initial frameset lo ads, the bro wser will usually be lo ading o ne new frame at a time. Also , bec ause the images are pro bably part o f the banner and/ o r the navigatio nal to o ls, the frame that do es relo ad is less likely to be image-intensive. Tip
By putting all or m ost of the im ages into one of your fram es and the m ostly textbased content into your m ain fram e, you can save visitors from having to load the im ages m ore than once. After the initial load, subsequent loads w ill be faster.
Use text rather than images Yo u’ve read this elsewhere in the bo o k. Yo u c an use tric ks to make text lo o k so mewhat like an image. Co nsider Figure 37-10, fo r example. Instead o f using a graphic with bo xes and butto ns in the left frame (this is a frameset page) fo r navigatio n, it uses a table with eac h c ell assigned a different bac kgro und c o lo r. Yo u c an assign eac h c ell a different text c o lo r. Yo u c an even assign eac h c ell a different fo nt, if that wo uld c o ntribute to the message o f the navigatio nal to o ls.
Creating Graphics If yo u want to c reate to p-no tc h graphic s, the to o l o f c ho ic e amo ng pro fessio nals is Ado be Pho to sho p, available fo r the Mac , the PC, and the SGI c o mputer (see Figure 37-11). Freeware and shareware so ftware pro grams also are available that perfo rm subsets o f the func tio ns perfo rmed by Pho to sho p. Pho to sho p LE, the lite versio n, ships with many sc anners.
Essential functions What sho uld yo ur graphic s pac kage be able to do ? Fo r existing images, suc h as pho to graphs, yo u want to sharpen, blur, and perfo rm so me spec ial effec ts o n the image (fo r example, po sterize, swirl, and mo saic ). Fo r images yo u c reate o n the sc reen, yo u want to c reate yo ur o wn c usto m palette (so yo u c an send as few c o lo rs as yo u need). Yo u also need so me basic artist to o ls, suc h as a paintbrush, a penc il, a spray c an, and a magnifying glass fo r magnifying part o f the image to see it better. Regardless o f whether the image is made by hand o r based o n a pho to graph o r c lipart, yo u need the fo llo wing c apabilities:
✦ to reduc e the bit-depth o f any image yo u want to save as GIF ✦ to index the c o lo r o f the image so yo u c an save the image to GIF
Chapter 36 ✦ Creating Still Graphics for the Web
Figure 37-11: Adobe Photoshop
✦ to save the image as an interlac ed GIF ✦ to save the image as a transparent GIF ✦ to save the image as a PNG file ✦ to save the image as a pro gressive JPEG, whic h is disc ussed at the end o f this c hapter Definition
Progressive JPEG. Progressive JPEGs are a nice addition to a Web page. They w ork the sam e as interlaced GIFs. Before the entire im age has been dow nloaded, you can begin to see the im age. Then the im ages slow ly com e into focus.
Free alternatives If yo u aren’t ready to c o mmit to a $500 so ftware pac kage to get all these great func tio ns, yo u c an wo rk with a number o f small, free so ftware pac kages and servic es that do many o f the things previo usly listed fo r yo u. On the Web, yo u c an find sites that turn yo ur TIF file into a GIF, o r make yo ur GIF an interlac ed GIF. The trade-o ff is the time. Finding, learning, and using a variety o f small pac kages to so lve all yo ur imaging needs o bvio usly takes lo nger than learning o ne pac kage and using it o n yo ur deskto p.
441
442
Part VI ✦ Adding Sensory Excitement and Interactivity
Capturing Graphics What abo ut taking graphic s yo u like fro m ano ther site? This is generally no t an o kay thing to do . Unless yo u have explic it permissio n fro m the c reato r o f the images — say, yo u are taking graphic s fro m a site that makes free images available o r yo u have written permissio n fro m the o wner o f the site — yo u are essentially stealing the images fro m the legitimate o wner. Images are intellec tual pro perty and are pro tec ted by c o pyright laws. Mo st peo ple wo n’t take yo u to c o urt, but yo u are still a thief. Just bec ause an image is o n a Web page do esn’t mean it is in the public do main. Yes, it gets do wnlo aded o nto yo ur o wn c o mputer (into c ac he), and, yes, yo ur bro wser gives yo u the ability to save the image as a lo c al file (using the right mo use butto n o r pro lo nged c lic king o n a Mac ), but it still do esn’t mean yo u o wn the image o r the right to use the image. If yo u see so mething yo u like o n ano ther page, write to the page o wner and ask if he o r she o wns the image and if yo u c an use it. Chanc es are, the o wner will be flattered by yo ur request. Be sure that perso n o wns the image o r permissio n wo n’t mean anything (if the image was sto len fro m so mewhere else).
Progressive JPEGs and Interlaced GIFs Onc e upo n a time o n the Web, yo u had to wait fo r an image to finish lo ading befo re yo u knew what it was. To day, yo u c an save yo ur files using the pro gressive JPEG fo rmat o r the interlac ed GIF fo rmat and watc h the image c o me into fo c us as it lo ads. The advantage to this appro ac h is a visito r to yo ur site kno ws ro ughly what an image is befo re the entire image has do wnlo aded. If do wnlo ad times are lo ng, say, due to a po o r Internet c o nnec tio n, the visito r to the site c an ac tually take a link o ff the page befo re the image has finished lo ading witho ut having missed anything. Finally, these two image fo rmats are go o d bec ause the visito r partic ipates in the do wnlo ad time. Instead o f waiting fo r the page to do wnlo ad — sitting idly by — the visito r waits fo r the page to do wnlo ad while watc hing the images bec o me c learer. This is mo re o f a reward fo r waiting — and less o f a sense o f waiting — fo r the visito r. The sense o f “c o ming into fo c us” that these types o f images pro vide is the result o f the way the images are sto red. Pro gressive JPEGs and interlac ed GIFs do wnlo ad o nly every eighth line at first, then every fo urth line, then every sec o nd line, and then, finally, the o dd-numbered lines. The result is the image go es fro m blurry to fo c used. Yo u c reate a pro gressive JPEG o r an interlac ed GIF by saving it into this fo rmat. In Pho to sho p, when yo u save a file as a GIF file, it asks yo u whether yo u want the file to be no rmal o r interlac ed (see Figure 37-12). Freeware pac kages are also available that c o nvert yo ur regular JPEGs and GIFs into pro gressive JPEGs and interlac ed GIFs.
Chapter 36 ✦ Creating Still Graphics for the Web
Figure 37-12: Adobe Photoshop asks you w hether you w ant your GIF file to have row s interlaced or norm al.
Using Transparent GIFs Transparent GIFs are a wo nderful inventio n that enable yo ur image to blend into yo ur bac kgro und o r to flo at o ver yo ur page. The effec t o f a transparent GIF o n a page c an be magic al. By setting the page bac kgro und c o lo r to the same c o lo r as the o utline o f the image o r to o ne o f the c o lo rs o f the image, transparent GIFs c an c o ntribute a light, airy lo o k to a page. Transparent GIFs enable yo u to c ho o se o ne o r mo re c o lo rs that will no t appear. Whatever c o lo r yo u set as the transparent c o lo r, depending o n ho w yo u do it, will be transparent when rendered in the bro wser. This c an result in the c ut-o ut parts o f letters also being c lear — say, the ho le in the middle o f an O. The danger to this effec t is if yo u have a part o f yo ur image that sho uld be white — say, the whites o f a c arto o n c harac ter’s eyes, and yo u set the transparent c o lo r to white and put the image o n a yello w bac kgro und — then the c arto o n c harac ter will lo o k like he has jaundic e o r hepatitis (yello w whites to his eyes).
443
444
Part VI ✦ Adding Sensory Excitement and Interactivity
From Here CrossReference
Jum p to Chapter 41 and learn how to add video to your Web pages. You can learn to create anim ated graphics by jum ping to Chapter38
Summary In this c hapter, yo u learned mo st o f what yo u sho uld kno w to use images in yo ur pages. Yo u learned abo ut the c o mpressio n c ho ic es yo u have fo r images. Yo u learned abo ut c o lo r palettes and bit depth. This c hapter also disc ussed c lever tric ks fo r inc reasing the do wnlo ad speed o f yo ur page, suc h as using frames and reusing images. Yo u learned a few things abo ut c reating graphic s and the to o ls yo u c an use to do this. Yo u also were warned abo ut c o pyright issues related to using graphic s fro m o ther peo ple’s sites. Yo u learned abo ut pro gressive JPEGs and interlac ed GIFs, abo ut transparent GIFs, and abo ut to o ls fo r c reating these interesting types o f images.
✦
✦
✦
38 C H A P T E R
Creating Animated Graphics for the Web
C
reating an animated image fo r the Web is inc redibly simple. Tho se banner ads yo u see with animatio n are bo th simple to c reate and relatively small to lo ad, c o mpared to o ld-fashio ned animatio ns. This c hapter takes yo u thro ugh what yo u need to kno w to c reate animated GIFs (the mo st po pular type o f animatio n o n the Web). It also disc usses o ther o ptio ns yo u have fo r mo re so phistic ated animatio ns.
Introducing Animated GIFs Animated GIFs are an easy way to add mo tio n to yo ur Web page witho ut any pro gramming, using o nly the simplest o f to o ls. Animated GIFs are like slide sho ws. The steps invo lved are simple:
1. Plan the animatio n. 2. Create the individual frames o f the slides in yo ur favo rite image c reatio n to o l.
3. String yo ur images to gether into a lo ng “filmstrip” using a GIF animatio n to o l.
4. Mo dify the animated GIF pro perties, suc h as palette info rmatio n, number o f times yo u want the images to lo o p (o nc e, 20 times, o r c o ntinuo usly), and image size.
✦
✦
✦
✦
In This Cha pter Intro ducing animated G IFs Planning yo ur animatio n Creating the animatio n Using an animated G IF Edito r Including an animated G IF o n yo ur pag e Testing yo ur animatio n Mo re animatio n o ptio ns
✦
✦
✦
✦
446
Part VI ✦ Adding Sensory Excitement and Interactivity
5. Expo rt yo ur animated GIF fro m the animatio n to o l to a .GIF file. 6. Add yo ur animatio n to yo ur HTML using the IMAGE element.
Planning Your Animation As with anything else, planning is essential to c reating effec tive animated GIFs. Suppo se yo u wanted to animate a stic k figure jumping up into the air, and then landing and do ing a flip. Bec ause yo u want this to be a lo o p, yo u also need to get the stic k figure bac k to the starting po int grac efully, so the lo o p c an begin again. Ho w many images do yo u need? Figure 38-1 is the starting po int.
Figure 38-1: This is the starting point for stick-art anim ation.
Then the figure must squat to get so me mo mentum fo r a big jump. Figures 38-2 and 38-3 c apture the squat and the jump.
Figure 38-2: The stick figure squats.
Figure 38-3: The stick figure jum ps.
Chapter 38 ✦ Creating Animated Graphics for the Web
Ho w sho uld the stic k figure land? The easiest thing wo uld be to land the stic k figure bac k in the squat fro m whic h it started and use this as the beginning mo tio n fo r the big flip. Figure 38-2 c an be reused fo r the landing po sitio n. This means it is time fo r the flipping figures. Figures 38-4 and 38-5 sho w the flip.
Figure 38-4: The stick figure begins its flip.
Figure 38-5: The stick figure continues its flip.
Again, the stic k figure needs to land. Fo rtunately, the squatting figure c an be reused, by just mo ving the squatting c harac ter o ver to the right in yo ur image edito r. The standing figure (Figure 38-1) c an also be mo ved to the right in yo ur image edito r to make the stic k figure stand where it sho uld have landed. The two figures c reated are sho wn in Figures 38-6 and 38-7.
Figure 38-6: The stick figure lands.
Figure 38-7: The stick figure com pletes its flip.
447
448
Part VI ✦ Adding Sensory Excitement and Interactivity
If an animated GIF weren’t a lo o p, the animatio n wo uld end there. But bec ause the c harac ter needs to get bac k to the beginning, ano ther squat and the two flipping frames, in reverse o rder, o f c o urse, will return it to the beginning.
Creating the Animation Creating the animatio n requires a bit o f artistic talent and a lo t o f imaginatio n. Just as when yo u were a c hild and yo u c reated flip bo o ks o f animatio n, eac h image sho uld be o nly a slight variatio n o f the previo us image. Yo u want to be c areful no t to use to o muc h mo tio n in yo ur animatio n bec ause the size o f the file gro ws as the number o f still images in yo ur animatio n gro ws. By limiting the dimensio ns o f the images and the bit-depth, ho wever, yo u c an help limit the size o f the file. Note
Your anim ated GIF has frames. Within each fram e there can be one or m ore images. You can create interesting effects by changing the size of the im age in the fram e to m ake it appear to be getting closer or farther aw ay.
Yo u want to fo llo w so me guidelines when c reating yo ur animatio ns:
✦ Keep all frames the same size. ✦ Keep c o lo rs to a minimum. ✦ Limit the amo unt o f mo tio n fro m o ne image to the next. ✦ Limit the number o f frames. As with anything else, yo u need to plan yo ur animatio n c arefully so the effec t yo u desire is ac hieved in a reaso nable number o f images. When yo u expo rt the animatio n fro m the animatio n to o l, yo u c an spec ify the file to be a vertic al ro w o f images o r a ho rizo ntal ro w o f images. The effec t c an be different depending o n whic h direc tio n yo u c ho o se. Bec ause the previo us example uses simple stic k figures, c reating the animatio n is pretty fast.
Using a GIF Animation Editor Plenty o f useful GIF animatio n edito rs are available. Yo u c an do a searc h o n the Web to find the mo st rec ent to o ls available. At o ne site, yo u c an c reate yo ur o wn animated GIF banner with text o f yo ur c ho ic e. An easy and relatively inexpensive to o l is Gamani’s GIF Mo vie Gear (see Figure 38-8). It is $30 shareware available fro m www.gamani.com. It takes c are o f all the
Chapter 38 ✦ Creating Animated Graphics for the Web
settings yo u might want to manipulate, witho ut requiring yo u to learn anything tec hnic al abo ut animated GIFs. Everything takes plac e in well-do c umented dialo g bo xes.
Figure 38-8: GIF Movie Gear m akes creating anim ated GIFs easy.
On the CD-ROM
You can find a 30-day version of GIF Movie Gear 2.63 on the CD-ROM in the back of this book.
In Figure 38-8, the animated GIF uses the seven still frames sho wn in Figures 38-1 to 38-7. So me o f them are reused, whic h saves time in c reating the images. The filmstrip is c reated as a ho rizo ntal strip bec ause the ac tio n o f the animatio n is mo stly ho rizo ntal. It c o uld have been just as easily set as a vertic al strip. Yo u c an do everything fro m o ptimizing the palette to sizing the frames to setting the number o f lo o ps using GIF Mo vie Gear. Yo u c an preview yo ur animated GIF right in Mo vie Gear. When yo u are satisfied, yo u c an expo rt the file to a .GIF file fo r use in yo ur Web pages.
449
450
Part VI ✦ Adding Sensory Excitement and Interactivity
Including an Animated GIF on Your Page Inc luding an animated GIF o n yo ur page is just like inc luding any o ther GIF o n a page. Yo u use the IMG element. The fo llo wing HTML is all yo u need to inc lude the GIF, whic h is inc luded o n the CD-ROM:
Yo u c o uld also make this animated GIF a link to ano ther page by inc luding the IMG element within an A element.
Testing Your Animation As with everything else o n yo ur page, yo u want to test yo ur animatio n fro m yo ur bro wser and fro m a variety o f o ther bro wsers, to make sure it wo rks as yo u expec t. Yo u also want to run yo ur page thro ugh Bo bby, whic h is disc ussed in Chapter 24, to make sure the do wnlo ad time fo r yo ur page with the animatio n is reaso nable. Finally, yo u want to be sure to use the alt attribute o f the IMG element so visito rs lo o king at yo ur page with a bro wser that do esn’t suppo rt animated GIFs kno w what they are missing.
M ore Animation Options Yo u c an use o ther tec hniques to add animatio n to yo ur page. So me o f yo ur o ptio ns inc lude
✦ Sho c kwave/ Flash ✦ Mo vies ✦ Java applets ✦ Ac tiveX c o ntro ls
Shockwave/ Flash Sho c kwave and Flash are a pro prietary animatio n system o wned by Mac ro media. To c reate a sho c kwave o r a flash file, yo u need to use either Autho rware o r Direc to r. To play a sho c kwave o r a flash file, yo ur site visito rs need to have a spec ial plug-in lo aded. CrossReference
Chapter 42 discusses Shockw ave and Flash in m ore detail.
Chapter 38 ✦ Creating Animated Graphics for the Web
M ovies Ano ther way to add mo tio n to yo ur page is to add a mo vie. The pro blem with mo st mo vie files is they tend to be c o nsiderably larger than animated GIF files. This means they take a lo t o f time to do wnlo ad — altho ugh yo u c an do things to get them to start playing befo re they c o mplete the do wnlo ad — and they take up a lo t o f spac e o n yo ur server. Mo vies will run in mo st bro wsers witho ut any additio nal plug-ins. CrossReference
Chapter 41 discusses video in m ore detail.
Java applets If yo u are c o mfo rtable with pro gramming, yo u might find Java to yo ur liking. With Java, yo u c an c reate mo re than just simple animatio ns. Generally, when yo u wo rk with Java, yo u wo rk with a dataset and so me ac tio ns o n a dataset. The previo us stic k figure animatio n wo uldn’t be well-suited to a Java animatio n. Java files tend to be small, but so metimes run slo wly. Additio nally, the visito r to yo ur site must have a Java-enabled bro wser. CrossReference
Chapter 43 discusses Java Applets in m ore detail.
ActiveX controls Ac tiveX c o ntro ls c an give yo u lo ts o f interesting animatio n effec ts witho ut a lo t o f wo rk. The o nly real wo rk invo lved is lo c ating them. Plenty o f Ac tiveX c o ntro ls are available (free o r fo r a small fee). Onc e yo u find them, yo u inc lude the referenc e to them in yo ur HTML and visito rs to yo ur site — if their bro wsers c an handle it — c an see yo ur interesting animatio n effec ts with relatively little wo rk. The do wnside o f Ac tiveX c o ntro ls is they install so ftware direc tly o n the visito r’s c o mputer. Cautio us visito rs wo n’t give yo ur page permissio n to install the c o ntro l. CrossReference
Chapter 42 discusses ActiveX controls in m ore detail.
From Here CrossReference
Jum p to Chapter 41 and learn about creating video for the Web. Jum p to Chapter 42 and learn about plug-ins you can use to spice up your Web page. Proceed to Chapter 39 and learn about designing and im plem enting im agem aps.
451
452
Part VI ✦ Adding Sensory Excitement and Interactivity
Summary In this c hapter yo u learned ho w to c reate animated GIFs fo r yo ur page. Yo u need a basic image edito r (anything that c an c reate an image and save it as a GIF), a GIF animatio n edito r, and so me imaginatio n. The mo st impo rtant thing is planning yo ur animatio n well, so it wo rks as yo u expec t. Yo u also learned abo ut alternatives fo r adding animatio n and mo tio n to yo ur page.
✦
✦
✦
39 C H A P T E R
Designing and Implementing Imagemaps
✦
✦
✦
✦
In This Cha pter Intro ducing imag emaps
I
magemaps are images with c lic kable regio ns under them. An imagemap c an be a wo nderful way to make a visually appealing page interac tive. Or, it c an be slo w-to -lo ad and c o nfusing, if no t do ne pro perly. This c hapter helps yo u to do it right. Yo u learn abo ut bo th server-side and c lient-side imagemaps. Yo u also learn abo ut the to o ls yo u c an use fo r c reating imagemaps. Finally, yo u learn abo ut testing yo ur imagemaps and adding alternative text to inc rease their effec tiveness.
Introducing Imagemaps Imagemaps wo rk by having an image with defined regio ns under the image. Eac h o f tho se regio ns is asso c iated with a link just as with the o ther linking elements, suc h as LINK and A. The bro wser o r the server c alc ulates the regio ns under the image based o n the shape asso c iated with eac h regio n, the dimensio ns o f the regio n, and the anc ho r po int o f the regio n, whic h is where the regio n starts — usually fro m the upper lefthand c o rner o f the image. Imagemaps c an be effec tive ways o f c o mmunic ating info rmatio n witho ut exc essive relianc e o n text, po ssibly making a site ac c essible to peo ple fo r who m English is a fo reign language o r to small c hildren. This theo ry breaks do wn if yo ur site design inc ludes any destinatio n pages that rely o n text in English, whic h almo st all sites do . In any c ase, yo u c an use a large site
Imag emap desig n Server-side versus client-side imag emaps Develo ping g raphics fo r imag emaps Using an imag emap edito r The anato my o f an imag emap Adding alternate text
✦
✦
✦
✦
454
Part VI ✦ Adding Sensory Excitement and Interactivity
map fo r a single transit page, but yo u risk inc urring the ire o f yo ur visito rs if yo u put to o many large, slo w-to -lo ad imagemaps o n yo ur site.
Imagemap Design An imagemap c an be a valuable additio n to yo ur site o r it c an be an anno yanc e to yo ur site visito r. Ho w do yo u kno w whic h? Yo u c an review so me questio ns to see if yo ur applic atio n o f an imagemap is likely to elic it favo rable respo nses o r to anger visito rs.
1. Did you keep the imagemap size to a minimum? Yo u might be thinking yo u want yo ur initial imagemap to fill a sc reen. What size sc reen? Yo u c ertainly want to design fo r a 640 × 480 sc reen, to keep the image size do wn and to guarantee everyo ne c an see the who le image. Even if yo ur image is well c o mpressed, yo u are still talking abo ut a large image. Why no t use o ne o r mo re smaller images with so me white spac e between them and plenty o f white spac e aro und the margins o f the page?
2. Can you navigate around your site another way, other than the imagemap? Yo u definitely want to make sure ano ther way exists. The simplest and least glamo ro us way is to enc lo se the names o f the pages yo u are linking to within square brac kets [like this].
3. Can people with their browsers set not to load images still navigate through your site? This relates to the previo us questio n. In the wo rst c ase, yo u will have visito rs to yo ur site who do n’t see any o f yo ur images. Can they navigate?
4. Is it obvious what the hot regions of your imagemaps link to? Think o f the average sign fo r a ladies ro o m in a nic e gro c ery sto re. It usually has the wo rd wo me n (wanting no t to o ffend wo men who aren’t ladies?), an illustratio n o f a wheelc hair, and an illustratio n o f a baby in a diaper. What do es this tell yo u? Previo usly the sign also had a stic k figure with a skirt o n, but that went the way o f the wo rd ladie s. Tho se illustratio ns tell yo u the bathro o m is wheelc hairac c essible and it has a c hanging statio n fo r babies. These signs are as c lear as c an be. The images that are part o f the ho t regio ns o f yo ur imagemaps need to be just as c lear. If yo u have any do ubt that yo ur ho t regio ns ac c urately and adequately c o nvey their destinatio ns, do user testing. Find peo ple who aren’t part o f the Web design gro up, who aren’t nec essarily experts o n yo ur pro duc t line, and watc h them c lic k aro und. Can they find what they want right away?
5. Is there alt text for each hot region? The alt attribute sho uld be po pulated fo r eac h regio n so if visito rs have any do ubt where a link go es, they c an plac e their c urso rs o ver the regio n and read the alt text.
Chapter 39 ✦ Designing and Implementing Imagemaps
Server-Side Versus Client-Side Imagemaps Imagemaps c an either run o n the bro wser o r o n the server. They lo o k identic al, regardless o f where the pro c essing takes plac e. In the earlier days o f the Web, when mo st Web pages were published by systems administrato rs o r UNIX gurus, serverside imagemaps were the thing to do . To day, when mo st pages are published by c lients o f ISPs, server-side imagemaps are a nightmare fo r systems administrato rs. The preferred metho d o f delivering an imagemap is with a c lient-side imagemap. Se rve r-side image maps usually require ro o t permissio n to write to files shared by everyo ne o n the server. Yo u c an see why that mo del do esn’t sc ale well. Server-side imagemaps also put so me pro c essing that c an be delegated to the visito r’s c o mputer bac k o n the server. This do esn’t fit the mo del o f distributed c o mputing mo st systems administrato rs are pursuing. Clie nt-side image maps are easy to c reate and plenty o f free o r inexpensive to o ls c an help yo u c reate them. The info rmatio n the bro wser needs is all inc luded in the HTML o r in a separate file referred to by the HTML. The imagemapping to o l c reates this fo r yo u based o n the regio ns yo u draw o n the image. CrossReference
Som e of the HTML editors review ed in Chapter 8 have im agem apping tools built into them .
Developing Graphics for Imagemaps What kinds o f images lend themselves to bec o ming imagemaps? Yo u c an use any kind o f image, with any shape o f ho t regio ns, but the mo re c o mplex the shapes o f yo ur regio ns, the mo re wo rk yo u must do mapping the image. The impo rtant thing is the regio ns give site visito rs a c lear idea o f where they are linking to . There is an applic atio n o f imagemaps yo u might no t have c o nsidered. So me sites use narro w to o lbars with links to the essential pages o n their sites. Figure 39-1 is an example o f suc h a to o lbar. The to o lbar in Figure 39-1 is small and attrac tive. It fits c o nveniently between the heading o f a page o r the banner o f a page, if there is o ne, and the c o ntent. The to o lbar c an also be plac ed at the bo tto m o f the page, to fac ilitate navigatio n.
Figure 39-1: This is a toolbar as an im agem ap.
455
456
Part VI ✦ Adding Sensory Excitement and Interactivity
Using an Imagemap Editor Plenty o f inexpensive imagemapping to o ls are available. One nic e o ne is Mapedit, by Bo utell.Co m. This is shareware that c an be do wnlo aded as a 30-day trial versio n and as o f this writing c an be purc hased fo r $25. It runs o n just abo ut every platfo rm inc luding Windo ws 95/ 98/ NT, Mac , and UNIX varieties. Figure 39-2 sho ws Mapedit in use.
Figure 39-2: Mapedit creates clickable regions under your im ages. Definition
The m ajor draw back to the w ay Mapedit w orks is it only opens .htm , .htm l, and .asp files, even though plenty of other file extensions m ight actually be Web pages (such as .cfm , .cgi, and so forth). If a lot of your Web pages have an extension other than .htm l, .htm , or .asp, you w ill w ant to find a different im agem apping program .
With Mapedit, yo u define regio ns right o n to p o f yo ur image using either a c irc le drawing o bjec t, a rec tangle drawing o bjec t, o r a free-fo rm drawing to o l. Fo r eac h regio n yo u define, yo u have a dialo g bo x that requests the URL fo r the link, alt text fo r a text desc riptio n o f the link destinatio n, and a target name, if the destinatio n o f the link is suppo sed to po pulate a frame.
Chapter 39 ✦ Designing and Implementing Imagemaps
The M AP Element Essential to c reating an imagemap are the MAP element and the AREA element. The MAP element tells the imagemap, “this is where info rmatio n abo ut c lic kable regio ns begins.”
Map Start Tag:
Required
Content:
AREA elements
End Tag:
Required
Attributes:
title, id, class, style, lang, dir name: required; c o ntains name asso c iated with the usemap attribute o f the IMG element alt: alternate text
The AREA Element The AREA element defines the regio ns within the imagemap that link to o ther pages.
Area Start Tag:
Required
Content:
Empty
End Tag:
Fo rbidden
Attributes:
id, class, lang, dir: defined elsewhere shape: “rec t”; so me bro wsers suppo rt o ther shapes, but this is the o nly o ne in the HTML 4.01 spec coords: c o o rdinates that define the beginning po int o f the shape and the dimensio ns o f the shape href: URL o f the link nohref: Bo o lean attribute that indic ates there is no link tabindex, accesskey: see Chapter 21 accesskey: ac c essibility key c harac ter onfocus: the element go t the fo c us onblur: the element lo st the fo c us alt: alternate text (rec o mmended) events: see Chapter 48
457
458
Part VI ✦ Adding Sensory Excitement and Interactivity
The Anatomy of an Imagemap Fo r the to o lbar image in Figure 39-1, the HTML lo o ks like this:
Yo u sho uld rec o gnize so me o f the elements. To begin with, an A element is at the very to p. Within this is the IMG element fo r the graphic used, whic h is the same o ne yo u see in Figure 39-1. There is also an ismap attribute, whic h is Bo o lean (meaning if it is present, it is o n; o therwise it is o ff), whic h indic ates this is the image fo r an imagemap. The next attribute, usemap, gives the URL o f the map to be used. Yo u’ve seen the po und sign (#) befo re. It indic ates the map to be used is lo c ated within the c urrent do c ument. It c o uld just as easily have given a file name o r any o ther valid URL. Finally, there is the alt attribute, whic h yo u definitely want to use.
Adding Alternate Text As yo u have just read, it is impo rtant to inc lude text in the alt attribute, desc ribing where eac h o f yo ur links leads. This isn’t the plac e to give the URL; this isn’t useful. This is the plac e to give a sho rt text desc riptio n o f what will be fo und at that page. Where sho uld yo u inc lude alternate text? In the AREA element fo r eac h link and again in the IMG element. The IMG element’s alt text will be sho wn whenever the c urso r is po sitio ned at a po int that isn’t part o f o ne o f the ho t regio ns. If the c urso r is o ver a ho t regio n, the alt text fo r that AREA element will be displayed.
From Here CrossReference
Go to Chapter 42 and learn about incorporating plug-ins. Jum p to Chapter 43 and learn about adding Java applets. Proceed to Chapter 40 and learn about producing and adding sounds.
Chapter 39 ✦ Designing and Implementing Imagemaps
Summary In this c hapter, yo u learned all abo ut imagemaps. The mo st impo rtant thing abo ut imagemaps isn’t where the ho t regio ns are; it’s what the image c o ntains to direc t visito rs to the c o rrec t links. This c hapter gave yo u so me guidelines fo r designing imagemaps. It also explained ho w to design graphic s to meet these guidelines. Yo u learned abo ut c lient-side imagemaps, server-side imagemaps, and why systems administrato rs muc h prefer yo u use c lient-side imagemaps. Yo u learned abo ut using an imagemap edito r and abo ut the impo rtanc e o f adding alternate text. Finally, yo u learned abo ut the MAP and AREA elements and the anato my o f an imagemap.
✦
✦
✦
459
40 C H A P T E R
Producing and Adding Sounds
✦
✦
✦
✦
In This Cha pter
A
dding so unds to yo ur Web pages is no t partic ularly diffic ult. There are advantages to adding so und to yo ur pages, but equally go o d reaso ns exist no t to put so und in yo ur pages. This c hapter talks abo ut ho w digital audio wo rks, what so und fo rmats wo rk o n the Web, ho w audio c o mpressio n wo rks, ho w streaming audio differs fro m regular audio , ho w to o btain and rec o rd so und files, ho w to use so und editing so ftware, and, finally, ho w to add so und to yo ur page with the OBJECT element and the EMBED element.
Understanding Digital Audio Digital audio tries to represent so und, whic h is inherently analo g (being a wave), with o nes and zero s. When yo u digitize so und waves, yo u take samples o f the wave at c ertain intervals. Just as yo u selec t the quality o f images yo u sc an by setting the reso lutio n, yo u c an selec t the prec isio n o f the so und c aptured by setting the bit-depth o f the so und file. Eight-bit so und divides the spec trum into 256 levels. Sixteen-bit so und gives yo u 65,536 levels. There is also 32-bit so und, but it do es no t run o ver the Web and it is no t highly ac c essible to c lient wo rkstatio ns bec ause so few truly 32-bit so und c ards exist. The quality o f so und yo ur c o mputer pro duc es is dependent o n five things:
1. The quality o f equipment used to rec o rd the so und 2. The bit-depth o f the rec o rded so und 3. The frequenc y o f sampling (sample rate) 4. Whether the so und is rec o rded in mo no o r stereo (the number o f c hannels)
5. The quality o f equipment in the mac hine playing the so und bac k
Understanding dig ital audio Intro ducing so und file fo rmats Intro ducing streaming audio O btaining so und files Reco rding so und files Editing so und files Co mpressing so und files Adding so und files to yo ur pag e
✦
✦
✦
✦
462
Part VI ✦ Adding Sensory Excitement and Interactivity
As with images and o ther types o f multimedia files, the quality has to be balanc ed against the file size. Yo u want to deliver the maximum quality so und fo r the minimum file size. Co mpressio n c an help to so me degree.
Recording equipment Several fac to rs figure into the quality o f the so und yo u rec o rd. One is the rec o rding enviro nment. If yo u are go ing to rec o rd vo ic e, yo u’ll want to rec o rd in a ro o m with go o d ac o ustic s. Yo u also need to be sure the bit-depth o f the rec o rding equipment is at least as high as the bit-depth at whic h yo u are rec o rding. A smart system wo n’t even let yo u try to rec o rd 16-bit stereo so und o n an 8-bit mo no system.
Recording bit-depth The bit-de pth o f the so und rec o rding indic ates ho w prec isely the so und that o c c urs at the mo ment o f sampling is rec o rded. As with c o lo r palettes, the number o f so unds yo u c an c ho o se fro m is limited to the palette yo u selec t. Fo r 8-bit so unds, the sampled so und will be o ne o f 256. Fo r 16-bit so und, the sampled so und will be o ne o f 65,536 so unds. Table 40-1 sho ws bit-depth and sample rates fo r c o mmo n types o f digitized so und.
Table 40-1 Sample Rates and Bit-Depth for Common Types of Digitized Sound Quality
Sample Rate (kHz)
Bits per Sample
M ono/ Stereo
Uncompressed Data Rate (Kbps)
Telephone
8
8
Mono
8
AM Radio
11.025
8
Mono
11.0
FM Radio
22.050
16
Stereo
88.2
CD
44.1
16
Stereo
176.4
DAT
48
16
Stereo
192.0
Sample rate Sample rates are measured in kilo hertz (kHz). The mo re frequently yo u sample so und, the higher the sample rate, and the mo re yo ur digitized so und will matc h the o riginal so und. Of c o urse, the mo re frequently yo u sample, the mo re info rmatio n yo u have to sto re, resulting in a larger file size.
Chapter 40 ✦ Producing and Adding Sounds
M ono versus stereo The differenc e between mo no and stereo is the number o f so und c hannels in the file. Fo r stereo , there is exac tly twic e as muc h data. Why do es twic e as muc h data exist? Bec ause yo u are sending two c hannels o f info rmatio n: o ne fo r the left speaker and o ne fo r the right speaker. Do yo u want to use stereo so und? This depends o n two things: file size and likely equipment o f the end user. Do yo u expec t site visito rs to have stereo playbac k equipment? If no t, it do esn’t matter. The real questio n is whether the so und yo u are delivering is audio fo r its o wn sake, in whic h the so und quality really matters, o r whether the so und is part o f so mething bigger, in whic h c ase, mo no is pro bably fine.
Playback equipment All this business abo ut bit depth, sample rates, and mo no versus stereo do n’t mean muc h if the peo ple trying to play bac k yo ur so und have o ld o r lo w-quality so und c ards. If peo ple playing bac k yo ur so und do n’t have a 16-bit so und c ard, they c an’t po ssibly play bac k all 65,536 so unds in the 16-bit spec trum. Their c o mputers will auto matic ally c ho o se the next c lo sest so und fro m the 256 so unds in the 8-bit spec trum. Bad speakers and a slo w pro c esso r — that c an’t re-c reate the so und at the pro per sample rate — c an also result in inferio r so und quality.
Introducing Sound File Formats Fo ur so und fo rmats frequently used o n the Web inc lude the fo llo wing:
✦ .WAV is the o riginal Windo ws file fo rmat. Altho ugh it used to be pro prietary to Windo ws, yo u c an ac tually play it no w under any o f the newer bro wsers, even o n a Mac o r o n UNIX.
✦ .AIF (o r .AIFF) stands fo r Audio Interc hange File Fo rmat. This c o mmo n audio file fo rmat is also c ro ss-platfo rm, but do esn’t take advantage o f any c o mpressio n.
✦ .AU is the o riginal Sun standard; it enables yo u to make tiny so und files. ✦ .MPEG and MPEG Audio Layer 3 (.MP3) are part o f the MPEG2 standard. With it, yo u c an c reate small files while maintaining a pretty high so und quality. It is no npro prietary. Yo u c an ac hieve c o mpressio n rates o f 1:10 o r 1:12 with CD-quality so und. On the do wnside, it do es require a spec ial player. A streamwo rks player will play streamed files. A lo t o f rec o rd c o mpanies are using the MPEG fo rmat bec ause yo u c an put CD-quality files o n the Web. Yo u also need spec ial so ftware to c o mpress yo ur audio files into .MP3 fo rmat.
463
464
Part VI ✦ Adding Sensory Excitement and Interactivity
Other ways exist to put so und o n the Web, inc luding Sho c kwave, RealAudio , and Quic kTime, but they are pro prietary. They require plug-in so ftware (as do es .MP3, altho ugh it is no npro prietary), whic h c an inc o nvenienc e yo ur site visito rs eno ugh that they might no t bo ther to get the plug-in o r to try to hear the audio files yo u put so muc h time into c reating.
Introducing Streaming Audio Streaming audio has c aught o n so well that no w everyo ne wants to c all their pro duc t stre aming. Co nsequently, two po ssible things are meant by the term stre aming audio . Bo th kinds o f streaming audio enable the visito r to yo ur site to begin hearing the audio file befo re it finishes do wnlo ading, whic h is the usual way yo u listen to audio files o n the Web. The first invo lves a spec ial server that delivers the audio o ver the Web using a pro prietary pro to c o l (no t HTTP) to get it to the deskto p. It also requires a spec ial plugin fo r the bro wser. The mo st po pular streaming audio server o n the market is the RealAudio server. Yo u c an learn mo re abo ut it and abo ut the tec hno lo gy in general at the RealAudio Web site at www.realaudio.com. The o ther kind o f streaming audio do es take advantage o f the HTTP pro to c o l, so fo r lac k o f a better name, it is c alled HTTP Stre aming. Streaming audio is a big impro vement o ver traditio nal audio , bec ause the so und file c an begin to play befo re it has c o mpleted do wnlo ading. No rmally, a so und file wo n’t begin playing until the entire file has do wnlo aded. This was part o f the reaso n fo r the initial impatienc e with audio o n the Web. Ho w do es streaming audio wo rk? When yo u save a file fo r streaming, all the basic file fo rmat info rmatio n is fro nt-lo aded in the file. This means the first things the bro wser c o mputer rec eives abo ut the audio file is eno ugh info rmatio n to begin playing immediately. In a no nstreaming file, the audio file info rmatio n is spread o ut alo ng the length o f the file, so the rec eiving c o mputer c an’t begin to play the file until the entire file is do wnlo aded. If yo u are go ing to use either kind o f streaming audio , yo u might also have to make c hanges to the MIME type o n yo ur server. Chec k with yo ur systems administrato r to see if yo ur server c an handle the MIME type yo u will be using.
Chapter 40 ✦ Producing and Adding Sounds
Obtaining Sound Files Yo u c an legally o btain public do main digital music at so me sites, but many o f the so urc es yo u might c o nsider using c an get yo u into tro uble with lawyers. Yo u may no t o btain so und files by c apturing music o ff yo ur favo rite CDs, the radio , o r c assettes. Yo u may o btain so und files by rec o rding yo ur o wn music al wo rks o r yo ur o wn vo ic e, o r by purc hasing lic ensed pro duc tio n music o r so und effec ts. Will yo u get c aught if yo u use music yo u o btain illegally o r yo u even o wn legally, but yo u distribute illegally (and this is what yo u are do ing when yo u publish music , even music fro m rec o rdings yo u’ve purc hased) o n the Web? Pro bably. There are Web agents — so ftware pro grams that c rawl aro und the Web lo o king fo r so und files belo nging to different rec o rding c o mpanies — and these agents have been suc c essful at lo c ating illegally distributed music being published by even the mo st harmless o rganizatio ns. Being hassled by a big-name law firm in New Yo rk City with a c ease-and-desist o rder is o nly half the tro uble. If yo u are using music bec ause yo u think it adds so mething spic y to yo ur site — say, the theme music fro m Missio n Impo ssible — it will be o bvio us to visito rs to yo ur site, unless yo ur site appears affiliated with the mo vie in so me way, that yo u have sto len the music and are using it illegally. Do es this make yo ur site lo o k pro fessio nal? No .
Recording Sound Files If yo u c ho o se to use a pro fessio nal so und-editing to o l, suc h as So und Edit 16, yo u c an rec o rd direc tly into that. Or, yo u c an use whatever so und-rec o rding so ftware c o mes installed with yo ur so und c ard. Yo u do need a so und c ard and an input jac k o r CD-ROM. Bec ause yo u kno w yo u sho uldn’t rec o rd music o ff yo ur CD, yo u wo n’t ac tually be using any music fro m yo ur CD c o llec tio n, but yo u might be using clip so unds, whic h are like c lip art in that yo u c an reuse them if yo u purc hase the CD o n whic h they are distributed. Figure 40-1 sho ws the sc reen fo r So und Edit 16 when yo u are rec o rding so und. Yo u c an set the sample rate, the bit-depth, and mo no versus stereo . The c o ntro ls fo r rec o rd, sto p, pause, and so fo rth sho uld lo o k familiar, if yo u have ever played a CD o n yo ur c o mputer.
465
466
Part VI ✦ Adding Sensory Excitement and Interactivity
Figure 40-1: Recording sound w ith Sound Edit 16
Editing Sound Files and Adding Filters So und-editing so ftware, unlike image-editing so ftware, isn’t usually c heap o r free. One free pac kage runs o n the Mac , c alled So undHac k, whic h do es a respec table jo b. One o f the mo re reaso nably-pric ed pac kages is So und Edit 16, by Mac ro media. What c an yo u do with yo ur so und files? Yo u c an add no ise, remo ve no ise, and add filters to c reate effec ts suc h as if yo u were singing the natio nal anthem in a fo o tball stadium (o r in spac e!). So und Edit 16 makes it easy to add spec ial effec ts to yo ur so und files. Just as easy is remo ving lo ud breath so unds fro m a vo ic e rec o rding and adding pauses. Figure 40-2 sho ws o ne o f the filters yo u c an apply in So und Edit 16.
Compressing Sound Files Onc e yo u have made all the trade-o ff dec isio ns abo ut yo ur audio files, bit depth, sample rate, and mo no versus stereo , yo u c an still use c o mpressio n to reduc e the file size. Many c o mpressio n sc hemes are available. Pro bably the two seen mo st o ften are MPEG Audio Layer 3 (also kno wn as MP3) and RealAudio .
Chapter 40 ✦ Producing and Adding Sounds
Figure 40-2: Adding effects w ith Sound Edit 16
RealAudio is pro prietary, but is widely used and the c o mpressio n to o l is free, as is the plug-in. MP3 is no t pro prietary. The MPEG standard is pro bably the future o f free audio o n the Web. Their Web site ( www.mpeg.org) is a treasure tro ve o f info rmatio n abo ut audio c o mpressio n and video c o mpressio n, alo ng with to o ls fo r delivering bo th o n the Web. Other c o mpressio n standards exist, but they are no t as c o mpatible ac ro ss platfo rms and yo ur site visito rs might have tro uble playing the files bac k.
Adding Sound Files to Your Page Yo u have two c ho ic es fo r adding so und to yo ur page with HTML: Yo u c an add inline so und, whic h starts to play as so o n as yo ur page lo ads, o r yo u c an add o ut-o f-line so und that plays as a result o f so me ac tio n o n the part o f the visito r.
Inline sound The o ffic ial HTML 4 spec ific atio n indic ates that inline so und sho uld be c reated with the OBJECT element, but as o f public atio n o f this bo o k, the OBJECT element did no t wo rk to deliver so und in any o f the majo r bro wsers. Yo u c an add inline so und using the EMBED element (whic h is deprec ated, but wo rks with all majo r bro wsers), with the value o f the src attribute being the URL fo r the so und file. Yo u’ll also want to
467
468
Part VI ✦ Adding Sensory Excitement and Interactivity
use the loop attribute to indic ate ho w many times to play the so und in the bac kgro und. If yo u want the so und to play ad nauseam, yo u c an set the value o f lo o p to infinite (whic h sho uld pro bably be ad nause um to make it c lear to Web autho rs that this is the effec t o f playing a lo o p o f so und an infinite number o f times).
Or, the o ffic ial way, with the OBJECT element:
This is an annoying beep.
Out-of-line sound The alternative to inline so und is the preferred metho d o f delivering so und, whic h is delivering so und o nly when the visito r to yo ur page requests it. Many rec o rd sto res o n the Web let yo u play snippets fro m so ngs o n albums they are selling. It wo uldn’t make sense to sho w a list o f albums (based o n yo ur selec tio n c riteria) and then start playing snippets fro m all the so ngs fro m all the albums in a ro w. Out-o fline so und gives the visito r to yo ur site the o ptio n to listen to yo ur audio file o r to bro wse in silenc e. Adding o ut-o f-line so und to yo ur page is as simple as using the A element and po inting to the so und file with the href attribute.
Listen to me singing Blue Christmas at the Meadowlands
From Here CrossReference
Jum p to Chapter 42 and learn about plug-ins and ActiveX controls. Proceed to Chapter 41 to learn how to create video and add it to your page.
Summary In this c hapter yo u learned ho w digital audio wo rks, what the variables are that make fo r a better o r a wo rse rec o rding, and why even the best rec o rding may play bac k po o rly o n a visito r’s c o mputer. Yo u learned abo ut so und file fo rmats and why streaming audio is a go o d idea. Yo u also endured a stern lec ture abo ut why yo u sho uldn’t use unautho rized so und files, even if yo u think yo u c an get away with it.
Chapter 40 ✦ Producing and Adding Sounds
This c hapter disc ussed So und Edit 16, whic h yo u c an use bo th to rec o rd and edit the so und, alo ng with adding effec ts and filters. As with mo st multimedia o bjec ts, yo u must understand quality dec isio ns, sample rate, and bit depth to deliver the best quality so und fo r the smallest file size to yo ur site visito rs. Finally, yo u learned abo ut yo ur two o ptio ns fo r adding so und to yo ur Web page, and why o ut-o f-line is pro bably the better appro ac h.
✦
✦
✦
469
41 C H A P T E R
Producing and Adding Video
✦
✦
✦
✦
In This Cha pter
D
igital video has made tremendo us strides in the last five years. This is a c o mplex sc ienc e that do esn’t lend itself to a tho ro ugh explanatio n in o ne sho rt c hapter. While this c hapter intro duc es yo u to the fundamentals o f digital video , the list o f what it do esn’t c o ver is almo st as lo ng as the list o f what it do es c o ver. This c hapter defines the terms yo u will c o me ac ro ss in making buying dec isio ns abo ut video hardware and so ftware. Mo re impo rtant, this c hapter is full o f referenc es to o ther mo re c o mprehensive so urc es, mo st no tably, magazines that inc lude up-to -the-minute reviews o f hardware and so ftware. The sho rt versio n is if yo u are serio us abo ut putting highquality video o n yo ur Web site, yo u must either devo te a tremendo us amo unt o f time and a lo t o f mo ney to the undertaking o r yo u sho uld hire a c o mpany dedic ated to video c o mpressio n to take yo ur edited analo g video and c o nvert it into a Web-ready fo rmat. If yo u simply want to pro duc e the kind o f video — small frame size and c ho ppy — yo u see o n mo st Web pages, this c hapter gets yo u started nic ely. In any c ase, yo u need to kno w the vo c abulary and the anato my o f digital video .
Intro ductio n to dig ital video The anato my o f dig ital video Intro ducing video file fo rmats Intro ducing streaming video Intro ducing video co mpressio n schemes Capturing analo g video Editing dig ital video Adding video files to yo ur pag e Invaluable reso urces
Introduction to Digital Video Video is by nature an analo g pro duc t. Co nverting analo g video into o nes and zero s has always been fraught with c hallenges. With still images, yo u have a similar pro blem: ho w to sto re c o lo rs and shapes as o nes and zero s in as little spac e as po ssible, while retaining as c lear a c o py o f the o riginal image as po ssible. With video yo u have the added dimensio n o f mo vement.
✦
✦
✦
✦
472
Part VI ✦ Adding Sensory Excitement and Interactivity
With film, mo tio n is c reated by sho wing a series o f still images in rapid suc c essio n. The mo re images in a given time interval, the mo re fluid the mo tio n. If yo u start with c lear still images and add fluid mo tio n, yo u have to p-quality video o r film. When digitizing video , yo u have to c o nsider the size o f the frame and the number o f c o lo rs (2 if just blac k and white, 256, o r even 1.7 millio n), as in c apturing still images. Just as with film, yo u also have to dec ide ho w many still images will be seen in a given interval o f time. With digital video , yo u also must think abo ut c o mpressio n o f the images and the mo tio n. That c o mpressio n c an take two fo rms: c o mpressio n within eac h frame o r c o mpressio n between frames.
Expectations If yo u spend a lo t o f time o n the Web, yo ur expec tatio ns are pro bably pretty humble. Yo u’ll settle fo r po stage-stamp-size video that plays relatively smo o thly. This is what mo st sites deliver to day. Fo rtunately, the c urrent state o f video c o mpressio n and delivery c an help yo u deliver better video than this. A number o f exc ellent pro duc ts are available fo r deskto p c o mputing to help yo u pro duc e results at better than the po stage-stamp level fo r a c o nsumer’s budget. The reso urc es listed at the end o f this c hapter po int yo u to the state-o f-the-art tec hno lo gy.
Garbage in, garbage out As with many o ther c o mpo nents, with video , the quality o f the digital video yo u pro duc e is highly c o rrelated with the quality o f the analo g with whic h yo u have to begin. While yo u c an take high-quality analo g video and still pro duc e junk in digital fo rm, yo u c an’t take bad analo g video and pro duc e c lear, sharp digital video .
The Anatomy of Digital Video Digital video takes advantage o f the best o f imaging tec hno lo gies and a thing o r two fro m audio tec hno lo gies. Digital video , at its mo st basic level, is a c o llec tio n o f still images that are sequenc ed. Intelligent c o mpressio n sc hemes exist that yo u c an apply to allo w the video to be c o mpressed bo th within eac h frame and between frames. The pro blem with digital video has always been the c o mpressio n versus file size trade-o ff. If the file is to o big, the c o mputer trying to play the file will be unable to play the frames at the rate they were intended to play. If the file is c o mpressed to o muc h, the c o mputer wo n’t have the po wer to dec o mpress in real time, pro duc ing the same playbac k pro blem.
Chapter 41 ✦ Producing and Adding Video
Regardless o f ho w yo u c o mpress video files, c apturing and editing video c an require huge wedges o f disk spac e fo r even the sho rtest snippet o f video . Video c apture, editing, and c o mpressio n require spec ial hardware and so ftware no t o ften fo und o n regular deskto p c o mputers. Three fac to rs dic tate video quality: frame rate, frame size, and c o mpressio n tec hno lo gy. Co mpressio n tec hno lo gies are disc ussed in their o wn sec tio n later in this c hapter.
Frame rate The frame rate is measured in frames per sec o nd. Full-mo tio n video is c o nsidered 30 frames per sec o nd (fps). Films are 29.75 fps. Mo st video sho wn o ver the Web plays at 15 fps. The mo re frames yo u sho w per sec o nd, the larger the file yo u need to send, but the smo o ther the mo tio n.
Frame size The frame siz e is measured in pixels and indic ates the amo unt o f sc reen spac e yo ur mo vie will fill. Co mmo n frame sizes are 80 × 60, 160 × 120, 176 × 144, 240 × 180, 320 × 240, and 352 × 288. Video delivered o ver the Web is rarely 640 × 480 o r full-sc reen bec ause the file sizes bec o me pro hibitive. This kind o f video is usually reserved fo r CD-ROMs o r DVD.
Introducing Video File Formats Few video fo rmats wo rk o n the Web. These inc lude the fo llo wing:
✦ .MOV. This is the o riginal mo vie fo rmat o f the Web. It isn’t o wned by anyo ne and it do esn’t require any spec ial plug-ins to play it bac k. On the do wnside, it also do esn’t use go o d c o mpressio n, so file sizes c an be large.
✦ .QT. The Quic kTime arc hitec ture is o wned by Apple c o mputers. Playbac k requires a spec ial plug-in, whic h yo u pro bably already have o n yo ur Mac , but yo u have to do wnlo ad o n yo ur PC.
✦ .MPG. MPEG, the standard set by the Mo tio n Pic ture Experts’ Gro up, is pro bably the best, no npro prietary standard available fo r video o n the Web. Co mpressing yo ur video as MPG will take a while, but the results c an be pretty impressive.
473
474
Part VI ✦ Adding Sensory Excitement and Interactivity
Introducing Streaming Video Streaming video wo rks just like streaming audio . When yo u c o mpress video no rmally, the video file c o ntains all the mo vie info rmatio n, frame by frame, fo r the entire mo vie in o rder. In parallel with this info rmatio n is info rmatio n abo ut the file: the file type, the file size, and c o mpressio n info rmatio n. The pro blem with no rmal video c o mpressio n is that, fo r the bro wser to begin to play the mo vie, it has to rec eive all the info rmatio n abo ut the file first. Streaming video mo ves all the info rmatio n abo ut the file to the fro nt o f the file. This means the first info rmatio n the bro wser rec eives is the info rmatio n it needs to get the c o mputer ready to play a mo vie. Onc e the ac tual mo vie starts to do wnlo ad, the bro wser is ready to start playing the mo vie as it arrives. Obvio usly, if the file is to o big o r if the frame rate c an’t be met by the do wnlo ad speed, then the mo vie wo n’t play bac k pro perly. Used pro perly, ho wever, streaming video c an be a valuable additio n to yo ur Web site.
Video Compression Schemes Essentially two kinds o f video c o mpressio n exist: intraframe and interframe. Intraframe co mpre ssio n takes advantage o f the kind o f c o mpressio n used with images. It c o mpresses eac h frame as well as it c an. Inte rframe co mpre ssio n ac tually c o mpresses between frames. The amo unt o f gue ssing yo u let the c o mputer do between frames affec ts ho w smo o thly the video plays bac k. This also affec ts the size o f the file. Obvio usly, if yo u c an dro p half the frames and still have a dec ent video , yo ur file size will be muc h smaller.
Capturing Analog Video Capturing analo g video requires so me playbac k devic e, suc h as a VCR if yo ur so urc e video is o n VHS tape, o r a c amc o rder if yo ur so urc e video was rec o rded that way. Capturing analo g video also requires video in jac ks o n the video bo ard o f yo ur c o mputer. Yo u may need to purc hase a spec ial video -c apture bo ard fo r yo ur c o mputer, altho ugh mo re and mo re video c ards are c o ming with video -c apture c apability. The video -c apture bo ard will likely take S-video , an 8-pin mini DIN c o nnec to r, o r an RCA pho no jac k. Capturing digital video is so mething o f an art. Depending o n the so ftware yo u use, yo u have to adjust fro m 2 to abo ut 30 settings in the so ftware. Yo u also want to make sure yo ur disk is defragmented o r, better yet, that yo u have a separate hard drive yo u c an refo rmat between eac h sessio n o f video c apture. Capturing video
Chapter 41 ✦ Producing and Adding Video
c an take up a lo t o f hard drive spac e. So metimes yo u’ll want 30 frames fro m o ne part o f a tape and then ano ther 30 fro m ano ther part. Finding the exac t starting and ending frames c an require c apturing far mo re video and then editing it.
Editing Digital Video Editing digital video is definitely the fun part. One relatively easy-to -use so ftware pac kage is Ado be Premiere, available fo r bo th Mac into sh and Windo ws. When editing, yo u c an add interesting (o r anno ying) transitio ns fro m o ne frame to the next. Figure 41-1 sho ws a list o f transitio ns.
Figure 41-1: Adobe Prem iere enables you to choose the transitions.
Ano ther feature yo u want yo ur video -editing so ftware to have is titling c apabilities. Yo u might want to add sc ro lling c redits at the end o r a title at the beginning. Figure 41-2 sho ws the mo vie being titled in Premiere. Finally, when yo u are do ne with yo ur editing, yo u kic k o ff the c o mpressio n pro c ess (see Figure 41-3) and go ho me fo r the night. Frequently the c o mpressio n will take o vernight. The length o f time it takes depends o n the po wer o f yo ur c o mputer, the type o f c o mpressio n, the length o f the video , and the frame rate.
475
476
Part VI ✦ Adding Sensory Excitement and Interactivity
Figure 41-2: Titling w ith Prem iere
Figure 41-3: Making com pression selections in Prem iere
Chapter 41 ✦ Producing and Adding Video
Adding Video Files to Your Page Video is usually added as o ut-o f-line video , meaning to see the video , the site visito r must take an ac tio n. Ho wever, yo u c an c reate inline video , whic h is added with the OBJECT element. The OBJECT element is disc ussed in depth in the next c hapter. Out-o f-line video is added with the familiar A element. Examples fo r bo th fo llo w:
Inline movies Sorry you can’t see this movie. It is pretty cool.
Out-of-line movies Click here to see a cool movie
Invaluable Resources AV Video Multimedia Pro duc er ( www.kipinet.com/av_mmp/index.html) is available by subsc riptio n o r o n newsstands. Digital Video ( www.dv.com) is available by subsc riptio n o r o n newsstands. Video graphy ( www.videography.com) is available by subsc riptio n o r o n newsstands. Advanc ed Imaging ( www.advancedimagingmag.com) is available by subsc riptio n.
From Here CrossReference
Go to Chapter 43 to learn how to add Java applets. Proceed to Chapter 42 to begin incorporating plug-ins and ActiveX controls.
477
478
Part VI ✦ Adding Sensory Excitement and Interactivity
Summary In this c hapter yo u learned ho w digital mo vies wo rk, what parameters c o ntribute to the quality and size o f mo vie files, and ho w video c o mpressio n wo rks. Yo u learned abo ut c apturing and editing video and abo ut inc luding video in yo ur Web sites. Many alternative ways to c reate video o n yo ur page require plug-ins. These are disc ussed in Chapter 42.
✦
✦
✦
42 C H A P T E R
Incorporating Plug-Ins and ActiveX Controls
✦
✦
✦
✦
In This Cha pter Reviewing the O BJECT element
P
lug-ins o ffer yo u the ability to add many diverse types o f media to yo ur Web pages. Many o f the deskto p so ftware pac kages yo u may use daily have plug-ins that enable the results o f yo ur wo rk to be seen o n the Web. Far to o many types o f plug-ins exist fo r this c hapter to list all o f them. Netsc ape was first o n the sc ene with plug-ins. Ac tiveX c o ntro ls are Mic ro so ft’s answer to plug-ins. Ac tiveX c o ntro ls, while they run under Netsc ape as well, were designed to add func tio nality to Internet Explo rer 3 and higher. Just like plug-ins, befo re visito rs to yo ur site c an use an Ac tiveX c o ntro l o n yo ur Web page, they must do wnlo ad it. What kind o f func tio nality c an Ac tiveX c o ntro ls add to yo ur page? Nearly any kind yo u c an imagine and pro gram. Ac tiveX c o ntro ls are written in regular pro gramming languages, using o ne o f the Mic ro so ft So ftware Develo pment Kits (SDKs). Many Ac tiveX c o ntro ls are available at no c o st. Others c an be lic ensed fro m the develo pers. Many reso urc es are o n the Web fo r finding bo th these kinds o f c o ntro ls. If yo u still c an’t find the o ne yo u want, yo u c an write o ne yo urself.
Reviewing the OBJECT Element The OBJECT element is o ne o f the mo st versatile elements in HTML. Yo u c an use it to inc lude inline graphic s, audio , video , Java applets, and plug-ins in yo ur page. Even tho ugh it has many attributes, yo u rarely need mo re than a few fo r any
Ho w plug -ins wo rk Plug -in pluses and minuses Adding plug -ins Testing yo ur plug -in Co nfig uring yo ur server Intro ducing ActiveX ActiveX pluses and minuses Understanding the ActiveX security mo del Finding ActiveX co ntro ls Inco rpo rating ActiveX co ntro ls Defining o ptio ns (parameters) G etting aro und the Mac pro blem Testing yo ur co ntro l
✦
✦
✦
✦
480
Part VI ✦ Adding Sensory Excitement and Interactivity
instanc e o f the element. Bec ause this bo o k aims to be c o mprehensive, yo u c an find the c o mplete OBJECT element definitio n in Chapter 19. The main attributes yo u need in o rder to inc lude inline plug-ins with the OBJECT element are data and type. Fo r example, to inc lude an inline VRML mo del, yo u wo uld use the fo llo wing HTML:
Too bad you don’t have a VRML plug-in. You can find one at the Netscape plug-in download center.
Visito rs to yo ur site wo uld have to have a plug-in that rec o gnized the MIME type “wo rld/ wrl.”
How Plug-Ins Work It’s like magic . Yo u do wnlo ad a plug-in and yo u install it. Then yo u c o me ac ro ss a page with an applic atio n requiring that plug-in and vo ilà! Yo ur bro wser runs that applic atio n just as if that func tio nality was built into the bro wser. Ho w do es the bro wser kno w whic h plug-in to use? The answer is MIME types. Yo ur c o mputer has a list o f MIME types it rec o gnizes. Where do es this list c o me fro m? Every time yo u install a so ftware pac kage, yo ur c o mputer adds this MIME type to the list. It uses this same list to assign a spec ial ic o n to a file when yo u lo o k at a file listing. In Netsc ape, yo u c an define a new MIME type manually, by go ing into Edit ➪ Preferenc es ➪ Applic atio ns. In Figure 42-1, yo u see a list o f MIME types. A MIME type c o nsists o f the file extensio n (so the c o mputer kno ws whic h files to asso c iate with this MIME type o n a PC o r o n UNIX), the c atego ry o f file (audio , video , applic atio n, image, and so fo rth), and the applic atio n that sho uld be used to o pen the file. Fo r Mac s, there aren’t any file extensio ns. In Internet Explo rer, yo u ac tually set the MIME types and define new MIME types in the o perating system, fro m any file listing (see Figure 42-2). If yo u go into an Explo rer windo w (right-mo use c lic k the Start butto n and c ho o se Explo re), and then selec t View ➪ Optio ns and c lic k the File Types tab, yo u see a list o f valid MIME types fo r yo ur c o mputer.
Chapter 42 ✦ Incorporating Plug-Ins and ActiveX Controls
Figure 42-1: Setting MIME types m anually in Netscape
Figure 42-2: Setting MIME types m anually for Internet Explorer
481
482
Part VI ✦ Adding Sensory Excitement and Interactivity
Plug-In Pluses and M inuses Plug-ins c an be a ric h additio n to yo ur site. They add interesting visual stimuli and are relatively quic k to develo p. As yo u read previo usly, adding an inline plug-in to yo ur page is as simple as adding the OBJECT element. Adding an o ut-o f-line plug-in to yo ur page uses the familiar A element. Plug-ins c an do so muc h, so easily, why wo uld a Web autho r want to avo id them at all? The majo r drawbac k to plug-ins is that visito rs to yo ur site might dec ide no t to do wnlo ad the plug-in and wo uld miss whatever exc iting visual/ aural stimuli yo u prepared fo r them. If a large po rtio n o f the message o n yo ur page is c o ntained in a file requiring a plug-in, then yo u risk failing to c o mmunic ate that message to muc h o f yo ur audienc e. Plug-ins are best used in intranets, where yo u have so me c o ntro l o ver (o r at least a kno wledge o f) the setup o f eac h o f the c o mputers likely to visit yo ur page. The o ther relatively safe enviro nment in whic h to use a plug-in is o n a site where the same info rmatio n is o ffered in ano ther fo rmat, say, text. Many news sites rely primarily o n text to c o nvey their messages, but o ffer video o r audio to supplement the message o f the text. Yo u want to avo id a page design where the o nly element o n the page is yo ur plug-in. This anno ys peo ple who do n’t have the plug-in, espec ially if yo u haven’t pro vided eno ugh info rmatio n to c o nvinc e them that they sho uld go to the tro uble o f getting the plug-in and installing it. Make sure to pro vide a direc t link to the site pro viding the plug-in, so peo ple do n’t have to searc h fo r the plug-in.
Adding Plug-Ins Plug-ins c an be divided into several c atego ries: 3D and animatio n plug-ins, audio and video plug-ins, disc ipline-spec ific plug-ins, business plug-ins, image viewers, and presentatio n plug-ins. Often, the effec ts ac hieved with plug-ins c an be ac hieved equally well with either JavaSc ript o r Java. The drawbac k to using pro gramming, spec ific ally Java, is that the develo pment time is muc h lo nger than simply using a plug-in. Frequently yo u must purc hase additio nal so ftware to implement a plug-in. So metimes, yo ur systems administrato r must make c hanges to the server to ac c o mmo date new MIME types, bec ause the Web server must also be familiar with the MIME type.
Chapter 42 ✦ Incorporating Plug-Ins and ActiveX Controls
3D and animation plug-ins If yo u want to take advantage o f vec to r graphic s o r 3D mo dels, yo u need a plug-in fo r no w. Future versio ns o f bro wsers undo ubtedly will inc lude suppo rt fo r vec to r graphic s but, even then, no t all visito rs to yo ur site will have the latest bro wser.
Cosmo Worlds and World View The mo st po pular 3D plug-in is the o ne that has been aro und the lo ngest: Co smo Wo rlds by SGI. This runs o n PCs o r UNIX. If yo u want to display 3D mo dels o n a Mac , yo u c an use Wo rld View by Intervista. The no npro prietary standard yo u c an use to c reate 3D mo dels is VRML. Creating so phistic ated 3D mo dels witho ut so me so rt o f to o l is diffic ult and time c o nsuming. Co smo Create, also by SGI, is the mo st po werful to o l fo r c reating 3D mo dels in VRML, the mo st c o mmo nly used 3D mo deling language o n the Web.
Shockwave and Flash Sho c kwave and Flash are plug-ins by Mac ro media. No t surprisingly, these plug-ins suppo rt files c reated by Mac ro media’s o wn pro duc ts: Direc to r, Autho rware, and Flash (see Figure 42-3). Yo u c an c reate impressive interac tive animatio ns and applic atio ns with Autho rware and Direc to r. Flash c reates vec to r graphic s.
Figure 42-3: Shockw ave plays Director and Authorw are files.
483
484
Part VI ✦ Adding Sensory Excitement and Interactivity
Why wo uld yo u want to use Flash as a plug-in when yo u c an c reate graphic s that display inline witho ut any plug-ins? Vec to r graphic s are an effic ient way to deliver graphic s to the Web. In Depth
Vector graphics files are sm all because, instead of a file containing the im age, the file contains only the equations that create the im ages (rem em ber geom etry class?). Also, the graphics created by the equations are infinitely scalable w ithout any loss of quality. Expect to see m uch m ore of vector graphics on the Web as Version 5 brow sers support this form at for inline graphics.
Audio and video plug-ins Bo th audio and video c an be played by the Versio n 3 and 4 bro wsers witho ut any spec ial plug-ins. If yo u want to use fanc ier video o r audio to o ls, ho wever, inc luding real-time streaming video o r audio that takes advantage o f a spec ial server, yo u need a spec ial plug-in. The o ther reaso n to use a plug-in is to sho w Quic kTimeVR mo vies, whic h c an be an effec tive way to sho w an o bjec t in 3D o r to navigate aro und a spac e.
RealPlayer RealPlayer by RealNetwo rks, Inc . kills two birds with o ne sto ne. If yo u are using either the RealAudio server o r the RealVideo server, RealPlayer is all yo ur site visito rs need. Either o f these tec hno lo gies, while relatively expensive to implement, result in exc ellent image/ so und quality delivered in real-time witho ut tho se pesky do wnlo ad delays. Ano ther advantage to this tec hno lo gy is the bro wser c o mputer reuses c ac he when do wnlo ading the files. This means the entire video o r audio file do esn’t reside o n the visito r’s c o mputer at any given time, saving the visito r prec io us hard drive spac e.
NetShow NetSho w is ano ther streaming video applic atio n. NetSho w is seen mo re c o mmo nly o n sites designed to use the full suite o f elements o nly available to Internet Explo rer. NetSho w do es nearly as nic e a jo b as RealPlayer. The NetSho w server is available at no c o st fro m Mic ro so ft.
QuickTimeVR Quic kTimeVR is a video applic atio n that c o mpetes with bo th video pro duc ts and 3D mo deling pro duc ts. Quic kTime is the o riginal video tec hno lo gy used o n Mac s. Quic kTimeVR c an be effec tive at sho wing an o bjec t fro m any perspec tive. Say yo u
Chapter 42 ✦ Incorporating Plug-Ins and ActiveX Controls
are c reating an exhibit o f pro duc ts and yo u want peo ple to mo ve the o bjec ts so they c an lo o k at the o bjec ts fro m all sides. Ho w wo uld yo u do this? Yo u might c reate a mo vie o f the o bjec t as yo u mo ve it (o r mo ve aro und it, depending o n its size), but ho w fast sho uld yo u mo ve? What if visito rs want to linger at a c ertain perspec tive? Quic kTimeVR so lves all this by c reating a c ylinder o f images, wo ven to gether so viewers c an turn the c ylinder, lo o king at any angle, and then mo ve the o bjec t so they c an lo o k at any o ther angle. The same c an be do ne with pano ramas: Quic kTimeVR c an c reate a seamless view o f the Grand Canyo n fro m the middle. In additio n to giving viewers c o ntro l o ver the speed o f the “mo vie” and the navigatio n, Quic kTimeVR c reates relatively small files — c o mpared to real mo vies — so this is a winner fro m every perspec tive.
Discipline-specific plug-ins Fo r so me fields, suc h as c hemistry, inc redibly po werful plug-ins enable yo u to express an idea o r equatio n with suc h brevity, yo u just c an’t avo id using plug-ins. If yo ur disc ipline is so mething o ther than c hemistry, lo o k and see if there isn’t so me plug-in to make yo ur life easier befo re yo u embark o n a Java pro gram to so lve yo ur display pro blems. Chime by Chemsc ape is o ne o f these plug-ins. Yo u might no t need to represent mo lec ules, but if yo u did, this wo uld be the pro duc t to use. Go to www.mdli.com to do wnlo ad the to o l.
Business plug-ins Pro bably the single mo st po pular plug-in in use o n the Web is the Ac ro bat Reader, whic h displays Po rtable Do c ument Fo rmat (PDF) files. PDF is Ado be’s o wn fo rmat fo r saving fo rmatted files fo r printing. Who uses PDF files o n the Web? The IRS fo r o ne. Nearly any tax fo rm yo u c o uld po ssibly want is available o n the IRS Web site ( www.irs.gov). The beauty o f PDF is that the file c an be printed the way it was intended. If yo u take a fo rm and re-c reate it o n the Web (in HTML), yo u c an’t be sure where page breaks will fall. If yo u take a fo rm and c reate a PDF file with it, then everyo ne who o pens it c an print it to lo o k exac tly the same. To c reate PDF files, yo u need to purc hase o ne o f the Ado be pro duc ts that c reates PDF files. Ado be Ac ro bat ($249 as o f this writing) is the basic pac kage yo u need if yo u want to publish do c uments in PDF fo rmat. Figure 42-4 is an example o f what a PDF file wo uld lo o k like o n yo ur sc reen. If yo u already use Ado be Illustrato r to
485
486
Part VI ✦ Adding Sensory Excitement and Interactivity
c reate do c uments, yo u c an expo rt direc tly fro m Illustrato r into the PDF fo rmat. Fo r mo st do c uments, whic h yo u c reate in yo ur favo rite wo rd pro c esso r o r sc an in using o ptic al c harac ter rec o gnitio n (OCR), yo u need Ac ro bat. Using the Ac ro bat Writer, yo u c an “print” any do c ument to PDF fo rmat. If yo u have a do c ument in po stsc ript fo rmat, Distiller c o nverts it into PDF. Yo u c an even edit a file yo u have c o nverted into PDF fo rmat using Ado be Exc hange.
Figure 42-4: The IRS m akes m ost form s available in PDF form at on its Web site.
Testing Your Plug-In As with everything else yo u publish o n yo ur Web site, yo u sho uld test yo ur plug-ins extensively. Yo u want to test them fro m multiple platfo rms, using Internet Explo rer, Netsc ape, and AOL. In fac t, yo u pro bably want to test yo ur plug-in fro m a c o mputer that do esn’t already have the plug-in installed. This way, yo u c an go thro ugh the pro c ess many o f yo ur site visito rs will go thro ugh:
1. Arrive at your page and get notification you need a plug-in.
Chapter 42 ✦ Incorporating Plug-Ins and ActiveX Controls
2. Follow the link on your page to get the plug-in. This link sho uld o pen a new windo w so the visito r do esn’t lo se yo ur page. Tip
Use an A elem ent to link w ith the value of the target attribute set to “blank” to open a new w indow for the plug-in page.
3. Download and install the plug-in. Do es it require restarting the bro wser? Yo u want to kno w this so yo u c an tell the visito r to bo o kmark yo ur page befo re quitting the bro wser. Yo u might also want to tell the visito r o n yo ur page ho w lo ng a do wnlo ad takes and what is invo lved in installatio n.
4. Play the plug-in on your page. Do es it require relo ading the page? Yo u sho uld mentio n this so mewhere.
Configuring Your Server Fo r so me plug-ins, the server needs so me spec ial info rmatio n. Fo r the Chime plugin, fo r example, the server must be no tified so me spec ial MIME types exist. When yo u use a plug-in, be sure yo u have read all the do c umentatio n o n the plug-in site, so yo u kno w if any c hanges must be made to yo ur server. The o dd thing abo ut these server c hanges is, if yo u had played the same plug-in fro m a CD o n yo ur deskto p, yo u wo uldn’t need any new MIME types. No go o d rule exists abo ut when yo u will need to have yo ur systems administrato r make MIME type c hanges to yo ur server. Yo u have to read the do c umentatio n and do so me testing yo urself to see if yo ur plug-ins will play fro m yo ur server.
Introducing ActiveX Ac tiveX is Mic ro so ft’s so lutio n fo r letting Web develo pers add their o wn func tio nality to Internet Explo rer. Active X is a marketing name fo r a set o f tec hno lo gies based o n the Co mpo nent Objec t Mo del (COM). Ac tiveX c o ntro ls run under Netsc ape as well, but they require a Netsc ape Ac tiveX c o ntro l to do so . Pro grammers, writing in traditio nal sec o nd-generatio n languages, suc h as C, C++, Visual Basic , and Java, c an write Ac tiveX c o ntro ls. By taking advantage o f existing Objec t Linking and Embedding (OLE) arc hitec ture, Ac tiveX c o ntro ls are smaller than regular pro grams o r Java Applets, and they are o ptimized fo r do wnlo ad and exec utio n. In additio n, they register themselves o n the c lient c o mputer.
487
488
Part VI ✦ Adding Sensory Excitement and Interactivity
Unlike pages with plug-ins, pages with Ac tiveX c o ntro l initiate the do wnlo ad o f the Ac tiveX c o ntro l. The beauty o f this appro ac h is that visito rs to the page do n’t need to kno w anything abo ut anything. They c an simply ac c ept o r refuse the do wnlo ad. Lic ensing fo r Ac tiveX c o ntro ls c an be c o mplic ated. So me Ac tiveX c o ntro ls are freely distributable. So me require lic ensing fro m the autho r. In these c ases, yo u must get a lic ense file to plac e o n yo ur server so the Ac tiveX c o ntro l will run pro perly. Of c o urse, if yo u write yo ur o wn, yo u needn’t wo rry abo ut lic ensing issues.
ActiveX Pluses and M inuses Ac tiveX has its advantages o ver plug-ins. The biggest advantage is to the site visito r. Visito rs to the site needn’t kno w anything to ac c ept the Ac tiveX c o ntro l. All they need to do is c lic k the wo rd Acce pt to have the Ac tiveX c o ntro l do wnlo ad. Ac tiveX c o ntro ls exist that do n’t suppo rt spec ific c o mmerc ial tec hno lo gies. The vast majo rity o f Netsc ape plug-ins were written — like the Ac ro bat Reader and RealPlayer — to fac ilitate distributio n o f pro prietary media standards o ver the Internet. Ac tiveX c o ntro ls tend to fo c us mo re o n perfo rming a spec ific task (running a c lo c k, displaying a c alendar, sho wing a sto c k tic ker) than o n delivering tec hno lo gies. One do wnside o f Ac tiveX c o ntro ls is, while Ac tiveX c o ntro ls aren’t nec essarily diffic ult to implement, they are mo re c o mplic ated to implement than a plug-in. Ano ther disadvantage o f Ac tiveX c o ntro ls, whic h is the same as the disadvantage o f plug-ins, is that peo ple c an c ho o se no t to ac c ept the do wnlo ad o f the plug-in. When this happens, yo ur page might have a big ho le in it o r it might no t func tio n pro perly.
M ac Support The biggest m inus to ActiveX controls is they don’t run on Macs. If you are building an application for the Internet or, m ore specifically, for education, this is an insuperable obstacle to using ActiveX controls. You can do som ething to get around this m ajor hole in ActiveX design. See the section “Getting Around the Mac Problem ” later in this chapter.
Chapter 42 ✦ Incorporating Plug-Ins and ActiveX Controls
Understanding the ActiveX Security M odel Ho w safe is it to use Ac tiveX c o ntro ls? That depends. The Ac tiveX sec urity mo del relies o n the go o dwill o f the Ac tiveX c o ntro l pro grammer. Ac tiveX c o ntro ls are inherently dangero us. The Ac tiveX sec urity mo del enables the pro grammer to have full and free c o ntro l o f yo ur c o mputer. This makes Ac tiveX c o ntro ls po werful. They c an read, write, and edit files. This also makes Ac tiveX c o ntro ls po tentially ve ry dangero us. Bec ause Ac tiveX c o ntro ls have unrestrained ac c ess to yo ur c o mputer, no limit exists to the damage they c an do . There is no lo gging o f the ac tio ns Ac tiveX c o ntro ls take, so there is no way later to trac e whic h c o ntro ls, if any, c aused system pro blems yo u are having. The Mic ro so ft answer to the c avalier appro ac h Ac tiveX c o ntro ls take to sec urity is that all c o ntro ls will be digitally signed by the distributo r, and yo u, as the site visito r, have the po wer to ac c ept o r refuse c o ntro ls, based o n whether yo u trust the distributo r. Is this eno ugh? No . What if the pro grammer, who m yo u trust, ac c identally leaves a sec urity ho le o n yo ur system and ano ther site yo u go to kno ws abo ut this and takes advantage o f it? Onc e yo u ac c ept an Ac tiveX c o ntro l, it gets installed o n yo ur system and stays there. Any site yo u subsequently visit c an use this c o ntro l, even if yo u never granted it explic it permissio n to do so . What do es all this mean to yo u as a Web develo per? It means yo u sho uld be c areful abo ut using o ther Ac tiveX c o ntro ls yo u c o me ac ro ss — even if yo u think they’re perfec tly safe — bec ause yo u may unwittingly c o ntribute to pro blems o n yo ur visito rs’ c o mputers. It also helps yo u understand why so many peo ple who c o me to yo ur site c ho o se no t to ac c ept yo ur c o ntro ls. Visito rs need to lo o k after the integrity o f their o wn c o mputers. When c an this sec urity mo del be a go o d thing? If yo u are develo ping fo r an intranet, yo u c an write Ac tiveX c o ntro ls that perfo rm po werful ac tio ns o n c lient c o mputers, witho ut having to install that so ftware manually o n every c o mputer. Be sure to test yo ur c o ntro ls c arefully, espec ially if they affec t the file system at all.
Finding ActiveX Controls Chanc es are, yo u’ll start yo ur fo ray into using Ac tiveX c o ntro ls by using o nes o thers have written. Lo ts o f plac es exist o n the Web where yo u c an find so urc es o f c o ntro ls. So me o f these c o ntro ls have lic ensing c o sts asso c iated with them, but yo u c an find o ut abo ut this when yo u identify the c o ntro ls yo u want to use.
489
490
Part VI ✦ Adding Sensory Excitement and Interactivity
Do zens o f sites c o nsider themselves reso urc es fo r Ac tiveX c o ntro ls. One plac e to start is the Bro wser Watc h site ( http://browserwatch.internet.com/activex.html). Altho ugh yo u may find 20 sites that list c o ntro ls, yo u will find they all list basic ally the same c o ntro ls. Bro wser Watc h do es a nic e jo b o f direc ting yo u to the c o ntro l witho ut numbing yo ur senses with visual c lutter and advertising in the pro c ess. In Depth
Publicizing your own controls. If you find no one has w ritten the control you need and you are brave enough to take this on yourself, you m ight w ant to have your ow n control listed on these sites. Each site has its ow n form for subm itting your ActiveX control inform ation.
Incorporating ActiveX Controls Onc e yo u identify the Ac tiveX c o ntro l yo u want, yo u insert it with the OBJECT element. Even tho ugh o ver a do zen attributes exist fo r the OBJECT element, mo st o f the time yo u o nly need fo ur o f them. Yo u also need an indeterminate number o f PARAM elements.
In the previo us example, whic h inserts the c alendar Ac tiveX c o ntro l into yo ur Web page, o nly fo ur attributes o f the OBJECT element are needed.
Chapter 42 ✦ Incorporating Plug-Ins and ActiveX Controls
In the previo us example, whic h inserts the Sho c kwave Ac tiveX c o ntro l, again o nly fo ur attributes are needed. Tip
The classid attribute. Where do you get that long, nasty classid attribute? You get this inform ation, w hich is the unique identifier for that ActiveX control, from the ow ner of the control. Depending on the licensing of the control, you can som etim es copy the source of a control you find on a page you like. If licensing restrictions exist, then this approach w on’t w ork and the control w on’t run on your page.
Defining Options (Parameters) Ho w many parameters do yo u need fo r an Ac tiveX c o ntro l? This depends o n the c o ntro l. Fo r so me c o ntro ls, no parameters exist. Fo r o thers, there c an be ten o r mo re. Yo u c an find o ut abo ut the parameters yo u have to set wherever yo u find o ut abo ut the c o ntro l. Ho w do yo u set parameters? With the PARAM element.
Parameter Start Tag:
Required
Content:
Empty
End Tag:
Fo rbidden
Attributes:
id: do c ument-wide unique ID; o ptio nal name: name o f the parameter; defined by the Ac tiveX c o ntro l value: value asso c iated with the parameter spec ified by the name attribute valuetype: ho w to interpret the value: data o r ref o r o bjec t; data is the default, ref indic ates the value is a URL, o bjec t indic ates the ID o f ano ther o bjec t defined in this page type: MIME type o f parameter
Getting Around the M ac Problem The easiest thing yo u c an do is to nest OBJECT elements. Plac e the OBJECT yo u mo st want yo ur visito rs to use in the o utermo st OBJECT element. Then, after yo ur PARAM elements, plac e the next OBJECT element yo u wo uld want them to use. Finally, within yo ur last c ho ic e OBJECT element, yo u c an inc lude alternate text explaining what they are missing.
491
492
Part VI ✦ Adding Sensory Excitement and Interactivity