Head First Html with CSS and XHTML







Next Page


Book Cover

Head First HTML with CSS & XHTML

By Elisabeth Freeman, Eric Freeman

...............................................

Publisher: O'Reilly

Pub Date: December 2005

Print ISBN-10: 0-596-10197-X

Print ISBN-13: 978-0-59-610197-8

Pages: 694





Table of Contents  | Index



Overview


Tired of reading HTML books that only make sense after you're an expert? Then it's about time you picked up Head First HTML with CSS & XHTML and really learned HTML. You want to learn HTML so you can finally create those Web pages you've always wanted, so you can communicate more effectively with friends, family, fans and fanatic customers. You also want to do it right so you can actually maintain and expand your Web pages over time, and so your Web pages work in all the browsers and mobile devices out there. Oh, and if you've never heard of CSS, that's okay - we won't tell anyone you're still partying like it's 1999 - but if you're going to create Web pages in the 21st century then you'll want to know and understand CSS.



Learn the real secrets of creating Web pages, and why everything your boss told you about HTML tables is probably wrong (and what to do instead). Most importantly, hold your own with your co-worker (and impress cocktail party guests) when he casually mentions how his HTML is now strict, and his CSS is in an external style sheet.



With Head First HTML with CSS & XHTML, you'll avoid the embarrassment of thinking Web-safe colors still matter, and the foolishness of slipping a font tag into your pages. Best of all, you'll learn HTML and CSS in a way that won't put you to sleep. If you've read a Head First book, you know what to expect: a visually-rich format designed for the way your brain works. Using the latest research in neurobiology, cognitive science, and learning theory, this book will load HTML, CSS, and XHTML into your brain in a way that sticks.



So what are you waiting for? Leave those other dusty books behind and come join us in Webville. Your tour is about to begin.




"Elegant design is at the core of every chapter here, each concept

conveyed with equal doses of pragmatism and wit."

--Ken Goldstein, Executive Vice President, Disney Online




"This book is a thoroughly modern introduction to forward-looking

practices in web page markup and presentation."

--Danny Goodman, author of Dynamic HTML: The Definitive Guide



"What used to be a long trial and error learning process has

now been reduced neatly into an engaging paperback."

--Mike Davidson, CEO, Newsvine, Inc.



"I love Head First HTML with CSS & XHTML--it

teaches you everything you need to learn in a 'fun coated' format!"

--Sally Applin, UI Designer and Artist



"I haven't had as much fun reading a book (other than Harry Potter) in years. And your book finally helped me break out of my hapless so-last-century way of creating web pages."

--Professor David M. Arnow, Department of Computer and Information Science, Brooklyn College



"If you've ever had a family member who wanted you to design a website for them, buy them Head First HTML with CSS and XHTML. If you've ever asked a family member to design you a web site, buy this book. If you've ever bought an HTML book and ended up using it to level your desk, or for kindling on a cold winter day, buy this book. This is the book you've been waiting for. This is the learning system you've been waiting for."

--Warren Kelly, Blogcritics.org


Next Page




Previous Page

Next Page


Book Cover

Head First HTML with CSS & XHTML

By Elisabeth Freeman, Eric Freeman

...............................................

Publisher: O'Reilly

Pub Date: December 2005

Print ISBN-10: 0-596-10197-X

Print ISBN-13: 978-0-59-610197-8

Pages: 694





Table of Contents  | Index





Head First HTML with CSS and XHTML


Dedication


Praise for Head First HTML with CSS & XHTML


Authors of Head First HTML with CSS & XHTML


Intro


  Chapter 1.  The Language of the Web



Section 1.1.  The Web killed the radio star



Section 1.2.  What does the Web server do?



Section 1.3.  What does the Web browser do?



Section 1.4.  What you write (the HTML)...



Section 1.5.  What the browser creates...



Section 1.6.  there are no Dumb Questions



Section 1.7.  Your big break at Starbuzz Coffee



Section 1.8.  Creating the Starbuzz Web page



Section 1.9.  Creating an HTML file (Mac)



Section 1.10.  Creating an HTML file (Windows)



Section 1.11.  there are no Dumb Questions



Section 1.12.  Meanwhile, back at Starbuzz Coffee...



Section 1.13.  Saving your work...



Section 1.14.  Opening your Web page in a browser



Section 1.15.  Taking your page for a test drive...



Section 1.16.  Markup Magnets



Section 1.17.  1st Congratulations, you've just written your first HTML!



Section 1.18.  Are we there yet?



Section 1.19.  Another test drive...



Section 1.20.  Tags dissected...



Section 1.21.  there are no Dumb Questions



Section 1.22.  Meet the style element



Section 1.23.  Giving Starbuzz some style...



Section 1.24.  Cruisin' with style...



Section 1.25.  Exercise



Section 1.26.  Firside Chats



Section 1.27.  HTML cross



Section 1.28.  Markup Magnets Solution



Section 1.29.  Exercise Solutions


  Chapter 2.  Meeting the 'HT' in HTML



Section 2.1.  Head First Lounge , New and Improved



Section 2.2.  Creating the new lounge



Section 2.3.  What did we do?



Section 2.4.  What does the browser do?



Section 2.5.  Understanding attributes



Section 2.6.  Getting organized



Section 2.7.  Organizing the lounge...



Section 2.8.  Technical difficulties



Section 2.9.  Planning your paths...



Section 2.10.  Fixing those broken images...



Section 2.11.  HTMLcross



Section 2.12.  The Relativity Grand Challenge Solution


  Chapter 3.  Web Page Construction



Section 3.1.  From Journal to Web site, at 12mph



Section 3.2.  The rough design sketch



Section 3.3.  From a sketch to an outline



Section 3.4.  From the outline to a Web page



Section 3.5.  Test driving Tony's Web page



Section 3.6.  Adding some new elements



Section 3.7.  Meet the <q > element



Section 3.8.  ...and check out the test drive...



Section 3.9.  Five-Minute Mystery: The Case of the Elements Separated at Birth



Section 3.10.  Looooong Quotes



Section 3.11.  Adding a <blockquote >



Section 3.12.  Five-Minute Mystery Solved



Section 3.13.  The real truth behind the <q> and <blockquote> mystery



Section 3.14.  Fireside Chats



Section 3.15.  Meanwhile, back at Tony's site...



Section 3.16.  Of course, you could use the <p> element to make a list...



Section 3.17.  Constructing HTML lists in two easy steps



Section 3.18.  Taking a test drive through the cities



Section 3.19.  Putting one element inside another is called "nesting "



Section 3.20.  To understand the nesting relationships, draw a picture



Section 3.21.  Using nesting to make sure your tags match



Section 3.22.  So what?



Section 3.23.  BE the Browser



Section 3.24.  Who am I?



Section 3.25.  Element Soup



Section 3.26.  HTMLcross



Section 3.27.  BE the Browser Solution



Section 3.28.  Exercise Solutions: Who am I?


  Chapter 4.  A Trip to Webville



Section 4.1.  Getting Starbuzz (or yourself) onto the Web



Section 4.2.  Finding a hosting company



Section 4.3.  HELLO, my domain name is...



Section 4.4.  How can you get a domain name?



Section 4.5.  Moving in



Section 4.6.  Getting your files to the root folder



Section 4.7.  As much FTP as you can possibly fit in two pages



Section 4.8.  Back to business...



Section 4.9.  Mainstreet, URL



Section 4.10.  What is the HTTP Protocol?



Section 4.11.  What's an Absolute Path?



Section 4.12.  Behind the Scenes: How default pages work



Section 4.13.  How do we link to other Web sites?



Section 4.14.  Linking to Caffeine Buzz



Section 4.15.  And now for the test drive...



Section 4.16.  Five-Minute Mystery



Section 4.17.  Web page fit and finish



Section 4.18.  The title test drive...



Section 4.19.  Linking into a page



Section 4.20.  Using the <a> element to create a destination



Section 4.21.  How to link to destination anchors



Section 4.22.  Now that you've got your hands on their HTML...



Section 4.23.  Reworking the link in "index.html"



Section 4.24.  Five-Minute Mystery Solved



Section 4.25.  Linking to a new window



Section 4.26.  Opening a new window using target



Section 4.27.  The Target Attribute Exposed



Section 4.28.  HTMLcross


  Chapter 5.  Meeting the Media



Section 5.1.  How the browser works with images



Section 5.2.  How images work



Section 5.3.  <img>: it's not just relative links anymore



Section 5.4.  Always provide an alternative



Section 5.5.  Sizing up your images



Section 5.6.  there are no Dumb Questions



Section 5.7.  Creating the ultimate fan site: myPod



Section 5.8.  Check out myPod's "index.html" file



Section 5.9.  Whoa! The image is way too large



Section 5.10.  Resize the image to fit in the browser



Section 5.11.  Open the image



Section 5.12.  Resizing the image



Section 5.13.  Resizing the image, continued...



Section 5.14.  You've resized now save



Section 5.15.  Save the image



Section 5.16.  Fixing up the myPod HTML



Section 5.17.  And now for the test drive...



Section 5.18.  More photos for myPod



Section 5.19.  Taking myPod for another test drive



Section 5.20.  Reworking the site to use thumbnails



Section 5.21.  Create the thumbnails



Section 5.22.  Rework the HTML to use the thumbnails



Section 5.23.  Take myPod for another test drive



Section 5.24.  Turning the thumbnails into links



Section 5.25.  Create individual pages for the photos



Section 5.26.  So, how do I make links out of images?



Section 5.27.  Add the image links to "index.html"



Section 5.28.  Open the myPod logo



Section 5.29.  What format should we use?



Section 5.30.  To be transparent, or not to be transparent? That is the question...



Section 5.31.  Save the transparent GIF



Section 5.32.  Wait, what is the color of the Web page background?



Section 5.33.  Set the matte color



Section 5.34.  Set the matte color, continued



Section 5.35.  Check out the logo with a matte



Section 5.36.  Save the logo



Section 5.37.  Add the logo to the myPod Web page



Section 5.38.  And now for the final test drive



Section 5.39.  HTMLcross


  Chapter 6.  Serious HTML



Section 6.1.  A Brief History of HTML



Section 6.2.  We can't have your pages putting the browser into Quirks Mode!



Section 6.3.  Adding the document type definition



Section 6.4.  The DOCTYPE test drive



Section 6.5.  Meet the W3C validator



Section 6.6.  Validating the Head First Lounge



Section 6.7.  Houston, we have a problem...



Section 6.8.  Fixing that error



Section 6.9.  We're not there yet...



Section 6.10.  Adding a <meta > tag to specify the content type



Section 6.11.  Making the validator (and more than a few browsers) happy with a <meta> content tag...



Section 6.12.  Third time's the charm?



Section 6.13.  Changing the DOCTYPE to strict



Section 6.14.  Do we have validation ?



Section 6.15.  Fixing the nesting problem



Section 6.16.  One more chance to be strict...



Section 6.17.  Strict HTML 4.01, grab the handbook



Section 6.18.  HTMLcross



Section 6.19.  Solution


  Chapter 7.  Putting an 'X' into HTML



Section 7.1.  What is XML ?



Section 7.2.  What does this have to do with HTML?



Section 7.3.  So why would you want to use XHTML?



Section 7.4.  You're much closer to using XHTML than you might think



Section 7.5.  Going from strict HTML to XHTML 1.0 in three steps



Section 7.6.  there are no Dumb Questions



Section 7.7.  Validation: it's not just for HTML



Section 7.8.  Congratulations, you've just written your first XHTML!



Section 7.9.  Fireside Chats



Section 7.10.  HTML or XHTML? The choice is yours...



Section 7.11.  Micro XHTMLcross



Section 7.12.  Micro XHTMLcross Solution


  Chapter 8.  Adding a Little Style



Section 8.1.  You're not in Kansas anymore



Section 8.2.  Overheard on Webville's "Trading Spaces"



Section 8.3.  Using CSS with XHTML



Section 8.4.  Getting CSS into your XHTML



Section 8.5.  Adding style to the lounge



Section 8.6.  Cruising with style: the test drive



Section 8.7.  Style the heading



Section 8.8.  Let's put a line under the welcome message too



Section 8.9.  We have the technology: specifying a second rule , just for the <h1>



Section 8.10.  So, how do selections really work?



Section 8.11.  Seeing selectors visually



Section 8.12.  Getting the Lounge style into the elixirs and directions pages



Section 8.13.  Creating the "lounge.css" file



Section 8.14.  Linking from "lounge.html" to the external style



Section 8.15.  Linking from "elixir.html" and "directions.html" to the external style sheet



Section 8.16.  Test driving the entire lounge...



Section 8.17.  It's time to talk about your inheritance ...



Section 8.18.  What if we move the font up the family tree?



Section 8.19.  Test drive your new CSS



Section 8.20.  Overriding inheritance



Section 8.21.  Test drive



Section 8.22.  Adding a class to "elixir.html"



Section 8.23.  Creating a selector for the class



Section 8.24.  A greentea test drive



Section 8.25.  Taking classes further...



Section 8.26.  The world's smallest & fastest guide to how styles are applied



Section 8.27.  Who gets the inheritance?



Section 8.28.  Making sure the Lounge CSS validates


  Chapter 9.  Expanding your Vocabulary



Section 9.1.  Text and fonts from 30,000 feet



Section 9.2.  What is a font family anyway?



Section 9.3.  Specifying font families using CSS



Section 9.4.  How font-family specifications work



Section 9.5.  Dusting off Tony's Journal



Section 9.6.  Getting Tony a new font-family



Section 9.7.  Test driving Tony's new fonts



Section 9.8.  there are no Dumb Questions



Section 9.9.  How do I deal with everyone having different fonts?



Section 9.10.  Adjusting font sizes



Section 9.11.  So, how should I specify my font sizes?



Section 9.12.  Let's make these changes to the font sizes in Tony's Web page



Section 9.13.  Test driving the font sizes



Section 9.14.  there are no Dumb Questions



Section 9.15.  Changing a font's weight



Section 9.16.  Sharpen your pencil



Section 9.17.  Test drive the normal weight headings



Section 9.18.  Adding style to your fonts



Section 9.19.  Styling Tony's quotes with a little italic



Section 9.20.  How do Web colors work?



Section 9.21.  How do I specify Web colors? Let me count the ways...



Section 9.22.  The two minute guide to hex codes



Section 9.23.  How to find Web colors



Section 9.24.  Using an online color chart



Section 9.25.  there are no Dumb Questions



Section 9.26.  Back to Tony's page... We're going to make the headings orange, and add an underline too



Section 9.27.  Test drive Tony's orange headings



Section 9.28.  Everything you ever wanted to know about text-decorations in less than one page



Section 9.29.  there are no Dumb Questions



Section 9.30.  Removing the underline...



Section 9.31.  XHTMLcross



Section 9.32.  Markup Magnets Solutions


  Chapter 10.  Getting Intimate with Elements



Section 10.1.  Getting Intimate with Elements



Section 10.2.  The lounge gets an upgrade



Section 10.3.  The new and improved, ultra-stylish lounge



Section 10.4.  Setting up the new lounge



Section 10.5.  Starting with a few simple upgrades



Section 10.6.  A very quick test drive



Section 10.7.  One more adjustment



Section 10.8.  Checking out the new line height



Section 10.9.  Getting ready for some major renovations



Section 10.10.  A closer look at the box model



Section 10.11.  What you can do to boxes



Section 10.12.  Meanwhile back at the lounge...



Section 10.13.  Creating the guarantee style



Section 10.14.  A test drive of the paragraph border



Section 10.15.  Padding, border, and margins for the guarantee



Section 10.16.  Adding some padding



Section 10.17.  A test drive with some padding



Section 10.18.  Now let's add some margin



Section 10.19.  A test drive with the margin



Section 10.20.  Adding a background image



Section 10.21.  Test driving the background image



Section 10.22.  Fixing the background image



Section 10.23.  Another test drive of the background image



Section 10.24.  How do you add padding only on the left?



Section 10.25.  Are we there yet?



Section 10.26.  How do you increase the margin just on the right?



Section 10.27.  A two-minute guide to borders



Section 10.28.  Border fit and finish



Section 10.29.  Congratulations!



Section 10.30.  The Class Exposed



Section 10.31.  The id attribute



Section 10.32.  But how do I use id in CSS?



Section 10.33.  Using an id in the lounge



Section 10.34.  Remixing style sheets



Section 10.35.  Using multiple style sheets



Section 10.36.  Style sheets-they're not just for desktop browsers anymore...



Section 10.37.  there are no Dumb Questions



Section 10.38.  XHTML cross



Section 10.39.  XHTML cross Solution


  Chapter 11.  Advanced Web Construction



Section 11.1.  A close look at the elixirs XHTML



Section 11.2.  Let's explore how we can divide a page into logical sections



Section 11.3.  There are no Dumb Questions



Section 11.4.  Meanwhile, back at the lounge...



Section 11.5.  Taking the <div> for a test drive



Section 11.6.  Adding a border



Section 11.7.  An over-the-border test drive



Section 11.8.  Adding some real style to the elixirs section



Section 11.9.  The game plan



Section 11.10.  Working on the elixir width



Section 11.11.  Test driving the width



Section 11.12.  There are no Dumb Questions



Section 11.13.  Adding the basic styles to the elixirs



Section 11.14.  Test driving the new styles



Section 11.15.  We're almost there...



Section 11.16.  What are we trying to do?



Section 11.17.  What we need is a way to select descendants



Section 11.18.  There are no Dumb Questions



Section 11.19.  Changing the color of the elixir headings



Section 11.20.  A quick test drive...



Section 11.21.  Fixing the line height



Section 11.22.  Look what you've accomplished...



Section 11.23.  It's time to take a little shortcut



Section 11.24.  But there's more...



Section 11.25.  And even more shorthands



Section 11.26.  there are no Dumb Questions



Section 11.27.  Adding <span>s in three easy steps



Section 11.28.  Steps one and two: adding the <span>s



Section 11.29.  Step three: styling the <span>s



Section 11.30.  Test driving the spans



Section 11.31.  there are no Dumb Questions



Section 11.32.  The <a> element and its multiple personalities



Section 11.33.  How can you style elements based on their state?



Section 11.34.  there are no Dumb Questions



Section 11.35.  Putting those pseudo-classes to work



Section 11.36.  Test drive the links



Section 11.37.  Isn't it about time we talk about the "cascade "?



Section 11.38.  The cascade



Section 11.39.  Welcome to the "What's my specificity game"



Section 11.40.  there are no Dumb Questions



Section 11.41.  Putting it all together



Section 11.42.  there are no Dumb Questions


  Chapter 12.  Arranging Elements



Section 12.1.  Did you do the Super Brain Power?



Section 12.2.  Use the flow , Luke



Section 12.3.  BE the Browser



Section 12.4.  What about inline elements ?



Section 12.5.  How it all works together



Section 12.6.  One more thing you should know about flow and boxes



Section 12.7.  How to float an element



Section 12.8.  Behind the scenes at the lounge



Section 12.9.  The new Starbuzz



Section 12.10.  A look at the markup



Section 12.11.  And a look at the style



Section 12.12.  Let's take Starbuzz to the next level



Section 12.13.  Move the sidebar just below the header



Section 12.14.  Set the width of the sidebar and float it



Section 12.15.  Test driving Starbuzz



Section 12.16.  Fixing the two-column problem



Section 12.17.  Setting the margin on the main section



Section 12.18.  Test drive



Section 12.19.  Uh oh, we have another problem



Section 12.20.  Back to clearing up the overlap problem



Section 12.21.  Test drive



Section 12.22.  Righty tighty, lefty loosey



Section 12.23.  A quick test drive



Section 12.24.  Liquid and Frozen Designs



Section 12.25.  A frozen test drive



Section 12.26.  What's the state between liquid and frozen? Jello , of course!



Section 12.27.  Test driving with a tank of jello



Section 12.28.  How absolute positioning works



Section 12.29.  What the CSS does



Section 12.30.  Another example of absolute positioning



Section 12.31.  Using absolute positioning



Section 12.32.  Changing the Starbuzz CSS



Section 12.33.  Now we just need to rework the main <div>



Section 12.34.  Time for the absolute test drive



Section 12.35.  What can we do? Or, can't you just tell me how to do a two-column layout that doesn't break?



Section 12.36.  One tradeoff you can make to fix the footer



Section 12.37.  Positioning the award



Section 12.38.  A small glitch



Section 12.39.  Fireside Chats



Section 12.40.  One more thing you should know about absolute positioning



Section 12.41.  How does fixed positioning work?



Section 12.42.  Putting the coupon on the page



Section 12.43.  Putting the coupon on the page



Section 12.44.  Using a negative left propert y value



Section 12.45.  A rather positive, negative test drive



Section 12.46.  Getting relative



Section 12.47.  The test drive



Section 12.48.  To three-columns and beyond...



Section 12.49.  XHTMLcross


  Chapter 13.  Getting Tabular



Section 13.1.  How do you make tables with XHTML?



Section 13.2.  How to create a table using XHTML



Section 13.3.  What the browser creates



Section 13.4.  Tables dissected



Section 13.5.  there are no Dumb Questions



Section 13.6.  BE the Browser



Section 13.7.  Adding a caption and a summary



Section 13.8.  Test drive... and start thinking about style



Section 13.9.  Before we start styling, let's get the table into Tony's page



Section 13.10.  Now let's style the table



Section 13.11.  Taking the styled tables for a test drive



Section 13.12.  there are no Dumb Questions



Section 13.13.  Getting those borders to collaspe



Section 13.14.  How about some color?



Section 13.15.  How about some color in the table rows?



Section 13.16.  Did we mention that Tony made an interesting discovery in Truth or Consequences, New Mexico?



Section 13.17.  Another look at Tony's table



Section 13.18.  How to tell cells to span more than one row



Section 13.19.  The new and improved table



Section 13.20.  there are no Dumb Questions



Section 13.21.  Trouble in paradise?



Section 13.22.  Test driving the nested table



Section 13.23.  Overriding the CSS for the nested table headings



Section 13.24.  there are no Dumb Questions



Section 13.25.  Giving Tony's site the final polish



Section 13.26.  Giving the list some style



Section 13.27.  What if you want a custom marker ?



Section 13.28.  And, the final test drive...



Section 13.29.  there are no Dumb Questions



Section 13.30.  XHTMLcross



Section 13.31.  Exercise Solutions



Section 13.32.  BE the Browser


  Chapter 14.  Getting Interactive



Section 14.1.  How forms work



Section 14.2.  How forms work in the browser



Section 14.3.  What you write in XHTML



Section 14.4.  What the browser creates



Section 14.5.  How the form element works



Section 14.6.  What can go in a form?



Section 14.7.  What can go in a form? (Part II)



Section 14.8.  Markup Magnets



Section 14.9.  Getting ready to build the Bean Machine form



Section 14.10.  Figuring out what goes in the form element



Section 14.11.  Adding the form element



Section 14.12.  How form element names work



Section 14.13.  there are no Dumb Questions



Section 14.14.  Back to getting those <input> elements into your XHTML



Section 14.15.  A form-al test drive



Section 14.16.  Adding some more input elements to your form



Section 14.17.  Adding the <select > element



Section 14.18.  Test driving the <select> element



Section 14.19.  Punching the radio buttons



Section 14.20.  Completing the form



Section 14.21.  Adding the checkboxes and text area



Section 14.22.  The final test drive



Section 14.23.  Watching GET in action



Section 14.24.  There are no dumb questions



Section 14.25.  To Table or Not to Table? That's the question...



Section 14.26.  Getting the form elements into a table: Ready Bake XHTML



Section 14.27.  Test driving a very tabular form



Section 14.28.  Styling the form and the table with CSS: Ready Bake CSS



Section 14.29.  The final test drive



Section 14.30.  What more could possibly go into a form?



Section 14.31.  Markup Magnets Solution



Section 14.32.  Sharpen your pencil: GET or POST



Section 14.33.  Congratulations!


  Appendix A.  The Top Ten Topics (we didn't cover)



Section A.1.  #1 More Selectors



Section A.2.  #2 Frames



Section A.3.  #3 Multimedia & Flash



Section A.4.  #4 Tools for Creating Web Pages



Section A.5.  #5 Client-side Scripting



Section A.6.  #6 Ser ver-side Scripting



Section A.7.  #7 Tuning for Search Engines



Section A.8.  #8 More about St yle Sheets for Printing



Section A.9.  #9 Pages for Mobile Devices



Section A.10.  #10 Blogs


Index


Previous Page

Next Page




Previous Page

Next Page



Head First HTML with CSS and XHTML


by Elisabeth Freeman and Eric Freeman


Copyright © 2006 O'Reilly Media, Inc. All rights reserved.


Printed in the United States of America.


Published by O'Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.


O'Reilly Media books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (safari.oreilly.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com.



Associate Publisher:


Mike Hendrickson


Series Creators:


Kathy Sierra, Bert Bates


Series Advisors:


Elisabeth Freeman, Eric Freeman


Editor:


Brett McLaughlin


Cover Designers:


Ellie Volckhausen, Karen Montgomery


HTML Wranglers:


Elisabeth Freeman, Eric Freeman


Structure:


Elisabeth Freeman


Style:


Eric Freeman


Page Viewer:


Oliver




Printing History:


November 2005: First Edition.



Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly Media, Inc. The Head First series designations, Head First HTML with CSS and XHTML, and related trade dress are trademarks of O'Reilly Media, Inc.


Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O'Reilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps.


While every precaution has been taken in the preparation of this book, the publisher and the authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.


In other words, if you use anything in Head First HTML with CSS & XHTML to, say, run a nuclear power plant, you're on your own. We do, however, encourage you to visit the Head First Lounge.


No elements or properties were harmed in the making of this book.


Thanks to Clemens Orth for the use of his photo, "applestore.jpg", which appears in Chapter 5.



[C]


Previous Page

Next Page




Next Page



Dedication


To the W3C, for saving us from the browser wars and for their brilliance in separating structure (HTML) from presentation (CSS)...


Browser wars? You'll find out in Chapter 6.


And for making HTML, CSS, and XHTML complex enough that people need a book to learn it.


Previous Page

Next Page




Previous Page

Next Page



Praise for Head First HTML with CSS & XHTML


"Head First HTML with CSS & XHTML is a thoroughly modern introduction to forward-looking practices in Web page markup and presentation. It correctly anticipates readers' puzzlements and handles them just in time. The highly graphic and incremental approach precisely mimics the best way to learn this stuff: make a small change and see it in the browser to understand what each new item means."


Danny Goodman


"Eric and Elisabeth Freeman clearly know their stuff. As the Internet becomes more complex, inspired construction of web pages becomes increasingly critical. Elegant design is at the core of every chapter here, each concept conveyed with equal doses of pragmatism and wit."


Ken Goldstein, Executive Vice President & Managing Director, Disney Online


"The Web would be a much better place if every HTML author started off by reading this book."


L. David Baron, Technical Lead, Layout & CSS, Mozilla Corporation http://dbaron.org/


"I've been writing HTML and CSS for ten years now, and what used to be a long trial and error learning process has now been reduced neatly into an engaging paperback. HTML used to be something you could just hack away at until things looked okay on screen, but with the advent of web standards and the movement towards accessibility, sloppy coding practice is not acceptable anymore... from a business standpoint or a social responsibility standpoint. Head First HTML with CSS & XHTML teaches you how to do things right from the beginning without making the whole process seem overwhelming. HTML, when properly explained, is no more complicated than plain English, and the Freemans do an excellent job of keeping every concept at eye-level."


Mike Davidson, President & CEO, Newsvine, Inc.


"The information covered in this book is the same material the pros know, but taught in an educational and humorous manner that doesn't ever make you think the material is impossible to learn or you are out of your element."


Christopher Schmitt, Author of The CSS Cookbook and Professional CSS, schmitt@christopher.org


Oh, great. You made an XHTML book simple enough a CEO can understand it. What will you do next? Accounting simple enough my developer can understand it? Next thing you know we'll be collaborating as a team or something.


Janice Fraser, CEO, Adaptive Path


More Praise for Head First HTML with CSS & XHTML


"I *heart* Head First HTML with CSS & XHTML it teaches you everything you need to learn in a 'fun coated' format!"


Sally Applin, UI Designer and Fine Artist, http://sally.com.


"This book has humor, and charm, but most importantly, it has heart. I know that sounds ridiculous to say about a technical book, but I really sense that at its core, this book (or at least its authors) really care that the reader learn the material. This comes across in the style, the language, and the techniques. Learning real understanding and comprehension on the part of the reader is clearly top most in the minds of the Freemans. And thank you, thank you, thank you, for the book's strong, and sensible advocacy of standards compliance. It's great to see an entry level book, that I think will be widely read and studied, campaign so eloquently and persuasively on behalf of the value of standards compliance in web page code. I even found in here a few great arguments I had not thought of ones I can remember and use when I am asked as I still am 'what's the deal with compliance and why should we care?' I'll have more ammo now! I also liked that the book sprinkles in some basics about the mechanics of actually getting a web page live FTP, web server basics, file structures, etc."


Robert Neer, Director of Product Development, Movies.com


"Freeman's Head First HTML with CSS & XHTML is a most entertaining book for learning how to build a great web page. It not only covers everything you need to know about HTML, CSS, and XHTML, it also excels in explaining everything in layman's terms with a lot of great examples. I found the book truly enjoyable to read, and I learned something new!"


Newton Lee, Editor-in-Chief, ACM Computers in Entertainment http://www.acmcie.org


"My wife stole the book. She's never done any web design, so she needed a book like Head First HTML with CSS & XHTML to take her from beginning to end. She now has a list of web sites she wants to build for our son's class, our family, ... If I'm lucky, I'll get the book back when she's done."


David Kaminsky, Master Inventor, IBM


"Beware. If you're someone who reads at night before falling asleep, you'll have to restrict Head First HTML with CSS & XHTML to daytime reading. This book wakes up your brain."


Pauline McNamara, Center for New Technologies and Education, Fribourg University, Switzerland


Previous Praise for books by the authors


From the awesome Head First Java folks, this book uses every conceivable trick to help you understand and remember. Not just loads of pictures: pictures of humans, which tend to interest other humans. Surprises everywhere. Stories, because humans love narrative. (Stories about things like pizza and chocolate. Need we say more?) Plus, it's darned funny.


Bill Camarda, READ ONLY


"This book's admirable clarity, humor and substantial doses of clever make it the sort of book that helps even non-programmers think well about problem-solving."


Cory Doctorow, co-editor of Boing Boing and author of "Down and Out in the Magic Kingdom" and "Someone Comes to Town, Someone Leaves Town"


"I feel like a thousand pounds of books have just been lifted off of my head."


Ward Cunningham, inventor of the Wiki and founder of the Hillside Group


"This book is close to perfect, because of the way it combines expertise and readability. It speaks with authority and it reads beautifully. It's one of the very few software books I've ever read that strikes me as indispensable. (I'd put maybe 10 books in this category, at the outside.)"


David Gelernter, Professor of Computer Science, Yale University and author of "Mirror Worlds" and "Machine Beauty"


"A Nose Dive into the realm of patterns, a land where complex things become simple, but where simple things can also become complex. I can think of no better tour guides than the Freemans."


Miko Matsumura, Industry Analyst, The Middleware Company Former Chief Java Evangelist, Sun Microsystems


"I laughed, I cried, it moved me."


Daniel Steinberg, Editor-in-Chief, java.net


"Just the right tone for the geeked-out, casual-cool guru coder in all of us. The right reference for practical development strategiesgets my brain going without having to slog through a bunch of tired, stale professor-speak."


Travis Kalanick, Founder of Scour and Red Swoosh Member of the MIT TR100


"I literally love this book. In fact, I kissed this book in front of my wife."


Satish Kumar


Previous Page

Next Page




Previous Page

Next Page



Authors of Head First HTML with CSS & XHTML


Elisabeth Freeman


Elisabeth is an author and software developer. She's been involved with the Internet since the early days, having co-founded The Ada Project (TAP), an award winning web site for women in computing now adopted by the ACM. More recently Elisabeth led research and development efforts in digital media at the Walt Disney Company where she co-invented Motion, a content system that delivers terabytes of video every day to Disney, ESPN, and Movies.com users.


Elisabeth is a computer scientist at heart and holds graduate degrees in Computer Science from Yale University and Indiana University. She's worked in a variety of areas including visual languages, RSS syndication, and Internet systems. She's also been an active advocate for women in computing, developing programs that encourage woman to enter the field.


These days you'll find her sipping some Java or Cocoa on her Mac, although she dreams of a day when the whole world is using Scheme.


Elisabeth has loved hiking and the outdoors since her days growing up in Scotland. When she's outdoors her camera is never far away. She's also an avid cyclist, vegetarian, and animal lover.


You can send her email at beth@oreilly.com


Eric freeman


Eric is a computer scientist with a passion for media and software architectures. He just wrapped up four years at a dream job directing Internet broadband and wireless efforts at Disney and is now back to writing, creating cool software, and hacking Java and Macs.


Eric spent a lot of the '90s working on alternatives to the desktop metaphor with David Gelernter (and they're both still asking the question "why do I have to give a file a name?"). Based on this work, Eric landed a Ph.D. at Yale University in '97. He also co-founded Mirror Worlds Technologies (now acquired) to create a commercial version of his thesis work, Lifestreams.


In a previous life, Eric built software for networks and supercomputers. You might know him from such books as JavaSpaces Principles Patterns and Practice. Eric has fond memories of implementing tuple-space systems on Thinking Machine CM-5s and creating some of the first Internet information systems for NASA in the late 80s.


Eric is currently living on Bainbridge Island. When he's not writing text or code you'll find him spending more time tweaking than watching his home theater and trying to restoring a circa 1980s Dragon's Lair video game. He also wouldn't mind moonlighting as an electronica DJ.


Write to him at eric@oreilly.com or visit his blog at http://www.ericfreeman.com


Previous Page

Next Page




Previous Page

Next Page



Intro


I can't believe they put that in an HTML book!


In this section, we answer the burning question: "So, why DID they put that in an HTML book?"


Who is this book for?


If you can answer "yes" to all of these:


  1. Do you have access to a computer with a Web browser and a text editor?


  1. Do you want to learn, understand, and remember how to create Web pages using the best techniques and the most recent standards?


  1. Do you prefer stimulating dinner party conversation to dry, dull, academic lectures?


If you have access to any computer manufactured in the last decade, the answer is yes.


this book is for you.


Who should probably back away from this book?


If you can answer "yes" to any one of these:


  1. Are you completely new to computers?


  1. (You don't need to be advanced, but you should understand folders and files, simple text editing applications, and how to use a Web browser.)


  1. Are you a kick-butt Web developer looking for a reference book?


  1. Are you afraid to try something different? Would you rather have a root canal than mix stripes with plaid? Do you believe that a technical book can't be serious if HTML tags are anthropomorphized?


this book is not for you.


[Note from marketing: this book is for anyone with a credit card.]


We know what you're thinking.


"How can this be a serious book?"


"What's with all the graphics?"


"Can I actually learn it this way?"


And we know what your brain is thinking.


Your brain craves novelty. It's always searching, scanning, waiting for something unusual. It was built that way, and it helps you stay alive.


Your brain thinks THIS is important.


Today, you're less likely to be a tiger snack. But your brain's still looking. You just never know.


So what does your brain do with all the routine, ordinary, normal things you encounter? Everything it can to stop them from interfering with the brain's real jobrecording things that matter. It doesn't bother saving the boring things; they never make it past the "this is obviously not important" filter.


How does your brain know what's important? Suppose you're out for a day hike and a tiger jumps in front of you, what happens inside your head and body?


Neurons fire. Emotions crank up. Chemicals surge.


And that's how your brain knows...


This must be important! Don't forget it!


Great. Only 637 more dull, dry, boring pages.


Your brain thinks THIS isn't worth saving.


But imagine you're at home, or in a library. It's a safe, warm, tigerfree zone. You're studying. Getting ready for an exam. Or trying to learn some tough technical topic your boss thinks will take a week, ten days at the most.


Just one problem. Your brain's trying to do you a big favor. It's trying to make sure that this obviously non-important content doesn't clutter up scarce resources. Resources that are better spent storing the really big things. Like tigers. Like the danger of fire. Like how you should never again snowboard in shorts.


And there's no simple way to tell your brain, "Hey brain, thank you very much, but no matter how dull this book is, and how little I'm registering on the emotional Richter scale right now, I really do want you to keep this stuff around."



We think of a "Head First" reader as a learner.


So what does it take to learn something? First, you have to get it, then make sure you don't forget it. It's not about pushing facts into your head. Based on the latest research in cognitive science, neurobiology, and educational psychology, learning takes a lot more than text on a page. We know what turns your brain on.


Some of the Head First learning principles :


Make it visual. Images are far more memorable than words alone, and make learning much more effective (up to 89% improvement in recall and transfer studies). It also makes things more understandable.


Put the words within or near the graphics they relate to, rather than on the bottom or on another page, and learners will be up to twice as likely to solve problems related to the content.


Browsers make requests for HTML pages or other resources, like images.

Web Server "Found it, here ya go"



Use a conversational and personalized style. In recent studies, students performed up to 40% better on post-learning tests if the content spoke directly to the reader, using a first-person, conversational style rather than taking a formal tone. Tell stories instead of lecturing. Use casual language. Don't take yourself too seriously. Which would you pay more attention to: a stimulating dinner party companion, or a lecture?


It really sucks to forget your <body> element.


Get the learner to think more deeply. In other words, unless you actively flex your neuron s, nothing much happens in your head. A reader has to be motivated, engaged, curious, and inspired to solve problems, draw conclusions, and generate new knowledge. And for that, you need challenges, exercises, and thought-provoking questions, and activities that involve both sides of the brain, and multiple senses.


The head element is where you put things about your page.


Does it make sense to create a bathtub class for my style, or just to style the whole bathroom?


Getand keepthe reader's attention. We' ve all had the "I really want to learn this but I can't stay awake past page one" experience. Your brain pays attention to things that are out of the ordinary, interesting, strange, eye-catching, unexpected. Learning a new, tough, technical topic doesn't have to be boring. Your brai n will learn much more quickly if it's not.


Touch their emotions. We now know that your ability to remember something is largely dependent on its emotional content. You remember what you care about. You remember when you feel something. No, we're not talking heart-wrenching stories about a boy and his dog. We're talking emotions like surprise, curiosity, fun, "what the...?", and the feeling of "I Rule!" that comes when you solve a puzzle, learn something everybody else thinks is hard, or realize you know something that "I'm more technical than thou" Bob from engineering doesn't.



Metacognition: thinking about thinking


If you really want to learn, and you want to learn more quickly and more deeply, pay attention to how you pay attention. Think about how you think. Learn how you learn.


I wonder how I can trick my brain into remembering this stuff...


Most of us did not take courses on metacognition or learning theory when we were growing up. We were expected to learn, but rarely taught how to learn.


But we assume that if you're holding this book, you really want to learn how to create Web pages. And you probably don't want to spend a lot of time. And you want to remember what you read, and be able to apply it. And for that, you've got to understand it. To get the most from this book, or any book or learning experience, take responsibility for your brain. Your brain on this content.


The trick is to get your brain to see the new material you're learning as Really Important. Crucial to your well-being. As important as a tiger. Otherwise, you're in for a constant battle, with your brain doing its best to keep the new content from sticking.


So how DO you get your brain to think HTML & CSS are as important as a tiger?


There's the slow, tedious way, or the faster, more effective way. The slow way is about sheer repetition. You obviously know that you are able to learn and remember even the dullest of topics, if you keep pounding on the same thing. With enough repetition, your brain says, "This doesn't feel important to him, but he keeps looking at the same thing over and over and over, so I suppose it must be."


The faster way is to do anything that increases brain activity, especially different types of brain activity. The things on the previous page are a big part of the solution, and they're all things that have been proven to help your brain work in your favor. For example, studies show that putting words within the pictures they describe (as opposed to somewhere else in the page, like a caption or in the body text) causes your brain to try to makes sense of how the words and picture relate, and this causes more neurons to fire. More neurons firing = more chances for your brain to get that this is something worth paying attention to, and possibly recording.


A conversational style helps because people tend to pay more attention when they perceive that they're in a conversation, since they're expected to follow along and hold up their end. The amazing thing is, your brain doesn't necessarily care that the "conversation" is between you and a book! On the other hand, if the writing style is formal and dry, your brain perceives it the same way you experience being lectured to while sitting in a roomful of passive attendees. No need to stay awake.


But pictures and conversational style are just the beginning.


Here's what WE did:


We used pictures, because your brain is tuned for visuals, not text. As far as your brain's concerned, a picture really is worth 1024 words. And when text and pictures work together, we embedded the text in the pictures because your brain works more effectively when the text is within the thing the text refers to, as opposed to in a caption or buried in the text somewhere.


                html


                body



h1       p        p       h2      p


        img       a       em      a



We used redundancy, saying the same thing in different ways and with different media types, and multiple senses, to increase the chance that the content gets coded into more than one area of your brain.


We used concepts and pictures in unexpected ways because your brain is tuned for novelty, and we used pictures and ideas with at least some emotional content, because your brain is tuned to pay attention to the biochemistry of emotions. That which causes you to feel something is more likely to be remembered, even if that feeling is nothing more than a little humor, surprise, or interest.


Be the Browser


We used a personalized, conversational style, because your brain is tuned to pay more attention when it believes you're in a conversation than if it thinks you're passively listening to a presentation. Your brain does this even when you're reading.


We included more than 100 activities, because your brain is tuned to learn and remember more when you do things than when you read about things. And we made the exercises challenging-yet-do-able, because that's what most people prefer.


We used multiple learning styles, because you might prefer step-by-step procedures, while someone else wants to understand the big picture first, while someone else just wants to see a code example. But regardless of your own learning preference, everyone benefits from seeing the same content represented in multiple ways.


BULLET POINTS


We include content for both sides of your brain, because the more of your brain you engage, the more likely you are to learn and remember, and the longer you can stay focused. Since working one side of the brain often means giving the other side a chance to rest, you can be more productive at learning for a longer period of time.


Puzzles


And we included stories and exercises that present more than one point of view, because your brain is tuned to learn more deeply when it's forced to make evaluations and judgements.


We included challenges, with exercises, and by asking questions that don't always have a straight answer, because your brain is tuned to learn and remember when it has to work at something. Think about it-you can't get your body in shape just by watching people at the gym. But we did our best to make sure that when you're working hard, it's on the right things. That you're not spending one extra dendrite processing a hard-to-understand example, or parsing difficult, jargon-laden, or overly terse text.


We used people. In stories, examples, pictures, etc., because, well, because you're a person. And your brain pays more attention to people than it does to things.


We used an 80/20 approach. We assume that if you're going to be a kick-butt Web developer, this won't be your only book. So we don't talk about everything. Just the stuff you'll actually need.


Here's what YOU can do to bend your brain into submission


So, we did our part. The rest is up to you. These tips are a starting point; listen to your brain and figure out what works for you and what doesn't. Try new things.


cut this out and stick it on your refrigerator.


  1. Slow down. The more you understand, the less you have to memorize.


  1. Don't just read. Stop and think. When the book asks you a question, don't just skip to the answer. Imagine that someone really is asking the question. The more deeply you force your brain to think, the better chance you have of learning and remembering.


  1. Do the exercises. Write your own notes.


  1. We put them in, but if we did them for you, that would be like having someone else do your workouts for you. And don't just look at the exercises. Use a pencil. There's plenty of evidence that physical activity while learning can increase the learning.


  1. Read the "There are No Dumb Questions"


  1. That means all of them. They're not optional sidebarsthey're part of the core content! Don't skip them.


  1. Make this the last thing you read before bed. Or at least the last challenging thing.


  1. Part of the learning (especially the transfer to long-term memory) happens after you put the book down. Your brain needs time on its own, to do more processing. If you put in something new during that processing-time, some of what you just learned will be lost.


  1. Drink water. Lots of it.


  1. Your brain works best in a nice bath of fluid. Dehydration (which can happen before you ever feel thirsty) decreases cognitive function.


  1. Talk about it. Out loud.


  1. Speaking activates a different part of the brain. If you're trying to understand something, or increase your chance of remembering it later, say it out loud. Better still, try to explain it out loud to someone else. You'll learn more quickly, and you might uncover ideas you hadn't known were there when you were reading about it.


  1. Listen to your brain.


  1. Pay attention to whether your brain is getting overloaded. If you find yourself starting to skim the surface or forget what you just read, it's time for a break. Once you go past a certain point, you won't learn faster by trying to shove more in, and you might even hurt the process.


  1. Feel something!


  1. Your brain needs to know that this matters. Get involved with the stories. Make up your own captions for the photos. Groaning over a bad joke is still better than feeling nothing at all.


  1. Create something!


  1. Apply this to something new you're designing, or rework an older project. Just do something to get some experience beyond the exercises and activities in this book. All you need is a pencil and a problem to solve... a problem that might benefit from using HTML and CSS.


Read Me


This is a learning experience, not a reference book. We deliberately stripped out everything that might get in the way of learning whatever it is we're working on at that point in the book. And the first time through, you need to begin at the beginning, because the book makes assumptions about what you've already seen and learned.


We begin by teaching basic HTML, then standards-based HTML 4.01, and then on to XHTML.


To write standards-based HTML or XHTML, there are a lot of technical details you need to understand that aren't helpful when you're trying to learn the basics of HTML. Our approach is to have you learn the basic concepts of HTML first (without worrying about these details), and then, when you have a solid understanding of HTML, teach you to write standards compliant HTML and XHTML. This has the added benefit that the technical details are more meaningful after you've already learned the basics.


It's also important that you be writing complaint HTML or XHTML when you start using CSS, so, we make a point of getting you to standards-based HTML and XHTML before you begin any serious work with CSS.


We don't cover every single HTML element or attribute or CSS property ever created.


There are a lot of HTML elements, a lot of attributes, and a lot of CSS properties. Sure, they're all interesting, but our goal was to write a book that weighs less than the person reading it, so we don't cover them all here. Our focus is on the core HTML elements and CSS properties that matter to you, the beginner, and making sure that you really, truly, deeply understand how and when to use them. In any case, once you're done with Head First HTML & CSS, you'll be able to pick up any reference book and get up to speed quickly on all the elements and properties we left out.


This book advocates a clean separation between the structure of your pages and the presentation of your pages.


Today, serious Web pages use HTML and XHTML to structure their content, and CSS for style and presentation. 1990s-era pages often used a different model, one where HTML was used for both structure and style. This book teaches you to use HTML for structure and CSS for style; we see no reason to teach you out-dated bad habits.


We encourage you to use more than one browser with this book.


While we teach you to write HTML, CSS, and XHTML that is based on standards, you'll still (and probably always) encounter minor differences in the way Web browsers display pages. So, we encourage you to pick at least two up-to-date browsers and test your pages using them. This will give you experience in seeing the differences among browsers and in creating pages that work well in a variety of browsers.


We often use tag names for element names.


Rather than saying "the a element", or "the 'a' element", we use a tag name, like "the <a> element". While this may not be technically correct (because <a> is an opening tag, not a full blown element), it does make the text more readable, and we always follow the name with the word "element" to avoid confusion.


The activities are NOT optional.


The exercises and activities are not add-ons; they're part of the core content of the book. Some of them are to help with memory, some are for understanding, and some will help you apply what you've learned. Don't skip the exercises. The crossword puzzles are the only things you don't have to do, but they're good for giving your brain a chance to think about the words in a different context.


The redundancy is intentional and important.


One distinct difference in a Head First book is that we want you to really get it. And we want you to finish the book remembering what you've learned. Most reference books don't have retention and recall as a goal, but this book is about learning, so you'll see some of the same concepts come up more than once.


The examples are as lean as possible.


Our readers tell us that it's frustrating to wade through 200 lines of an example looking for the two lines they need to understand. Most examples in this book are shown within the smallest possible context, so that the part you're trying to learn is clear and simple. Don't expect all of the examples to be robust, or even completethey are written specifically for learning, and aren't always fully-functional.


We've placed all the example files on the Web so you can download them. You'll find them at http://www.headfirstlabs.com/books/hfhtml/


The 'Brain Power' exercises don't have answers.


For some of them, there is no right answer, and for others, part of the learning experience of the Brain Power activities is for you to decide if and when your answers are right. In some of the Brain Power exercises you will find hints to point you in the right direction.


Tech Reviewers


Lousie Barr


Joe Konior


Valentin Crettaz


Corey McGlone


Barney Marispini


Pauline McNamara


Pauline gets the "kick ass reviewer" award.


Eiffel Tower


Fearless leader of the Extreme Review Team.


Johannes de Jong


Marcus Green


Ike Van Atta


David O'Meara


Our reviewers:


We're extremely grateful for our technical review team. Johannes de Jong organized and led the whole effort, acted as "series dad," and made it all work smoothly. Pauline McNamara, "co-manager" of the effort, held things together and was the first to point out when our examples were a little more "baby boomer" than hip. The whole team proved how much we needed their technical expertise and attention to detail. Valentin Crettaz, Barney Marispini, Marcus Green, Ike Van Atta, David O'Meara, Joe Konior, and Corey McGlone left no stone unturned in their review and the book is a much better book for it. You guys rock! And further thanks to Corey and Pauline for never letting us slide on our often too formal (or we should just say it, incorrect) punctuation. A shout out to JavaRanch as well for hosting the whole thing.


A big thanks to Louise Barr, our token Web designer, who kept us honest on our designs and on our use of XHTML & CSS (although you'll have to blame us for the actual designs).


Acknowledgments[*]


[*] The large number of acknowledgments is because we're testing the theory that everyone mentioned in a book acknowledgment will buy at least one copy, probably more, what with relatives and everything. If you'd like to be in the acknowledgment of our next book, and you have a large family, write to us.


Even more technical review:


We're also extremely grateful to our esteemed technical reviewer David Powers. We have a real love/hate relationship with David because he made us work so hard, but the result was oh so worth it. The truth be told, based on David's comments, we made significant changes to this book and it is technically twice the book it was before. Thank you, David.


Esteemed Reviewer, David Powers


Don't let the sweater fool you, this guy is hard core (technically of course).


At O'Reilly:


Our biggest thanks to our editor, Brett McLaughlin, who cleared the path for this book, removed every obstacle to its completion, and sacrificed family time to get it done. Brett also did hard editing time on this book (not an easy task for a Head First title). Thanks Brett, this book wouldn't have happened without you.


Brett McLaughlin


Our sincerest thanks to the whole O'Reilly team: Greg Corrin, Glenn Bisignani, Tony Artuso, and Kyle Hart all led the way on marketing and we appreciate their out-of-the-box approach. Thanks to Ellie Volkhausen for her inspired cover design that continues to serve us well, and to Karen Montgomery for stepping in and bringing life to this book's cover. Thank you, as always, to Colleen Gorman for her hardcore copyedit (and for keeping it all fun). And, we couldn't have pulled off a color book like this without Sue Willing and Claire Cloutier.


No Head First acknowledgment would be complete without thanking Mike Loukides for shaping the Head First concept into a series, and to Tim O'Reilly for always being there and his continued support. Finally, thanks to Mike Hendrickson for bringing us into the Head First family and having the faith to let us run with it.


Kathy Sierra and Bert Bates:


Last, and anything but least, to Kathy Sierra and Bert Bates, our partners in crime and the BRAINS who created the series. Thanks guys for trusting us even more with your baby. We hope once again we've done it justice. The three-day jam session was the highlight of writing the book, we hope to repeat it soon. Oh, and next time around can you give LTJ a call and tell him he's just going to have to make a trip back to Seattle?


Bert Bates


Kathy Sierra


Hard at work researching Head First Parelli.


Kara


Previous Page

Next Page




Previous Page

Next Page



Chapter 1. The Language of the Web


Not so fast... to get to know me you've got to speak the universal language. You know, HTML and CSS.


The only thing that is standing between you and getting yourself on the Web is learning to speak the lingo: HyperText Markup Language, or HTML for short. So, get ready for some language lessons. After this chapter, not only are you going to understand some basic elements of HTML, but you'll also be able to speak HTML with a little style. Heck, by the end of this book you'll be talking HTML like you grew up in Webville.


Previous Page

Next Page




Previous Page

Next Page



1.1. The Web killed the radio star


Want to get an idea out there? Sell something? Just need a creative outlet? Turn to the Web we don't need to tell you it has become the universal form of communication. Even better, it's a form of communication YOU can participate in.


But, if you really want to use the Web effectively, you've got to know a few things about HTML, not to mention how the Web works. Let's take a look from 30,000 feet:


The Internet


To make Web pages, you create files written in the HyperText Markup

Language (HTML for short) and place them on a Web server (we'll talk about how to get your

files on a server later in the book).

Web Server

Once you've

put your files on a Web server, any browser can retrieve your Web pages over the Internet.

The HTML in your Web page

tells the browser everything it needs to know to display your

page. And, if you've done your job well, your pages will even display well on PDAs and

mobile devices, and work with speech browsers and screen magnifiers for the visually impaired.

And there are a lot of PCs and devices connected to the Internet all running Web browsers.

More importantly, there are friends, family, fans, and potential customers using those

PCs!



Previous Page

Next Page




Previous Page

Next Page



1.2. What does the Web server do?


Web servers have a full time job on the Internet, tirelessly waiting for requests from Web browsers. What kinds of requests? Requests for Web pages, images, sounds, or maybe even a movie. When a server gets a request for any of these resources, the server finds the resource, and then sends it back to the browser.


Web ServerThe server's just a computer connected

to the Internet waiting for requests from browsers.

Each server stores HTML files, pictures, sounds and other file types.

"I

need the HTML file 'lounge.html'"Browsers make

requests for HTML pages or other resources, like images.

"Found it, here ya go"...and

if the server can locate the resource, it sends it to the browser.



Previous Page

Next Page




Previous Page

Next Page



1.3. What does the Web browser do?


You already know how a browser works: you're surfing around the Web and you click on a link to visit a page. That click causes your browser to request an HTML page from a Web server , retrieve it, and display the page in your browser window.


Web ServerThe server "serves up" Web

pages and sends them to the browser.

The browser retrieves the page...

...and the browser displays the HTML page.



But, how does the browser know how to display a page? That's where HTML comes in. HTML tells the browser all about the content and structure of the page. Let's see how that works...


Previous Page

Next Page




Previous Page

Next Page



1.4. What you write (the HTML)...


So, you know HTML is the key to getting a browser to display your pages, but, what exactly does HTML look like? And, what does it do?


Let's have a look at a little HTML... imagine you're going to create a Web page to advertise the Head First Lounge , a local hangout with some good tunes, refreshing elixirs, and wireless access. Here's what you'd write in HTML:


<html>


  <head>


    <title>Head First Lounge</title> A

  </head>

  <body>

    <h1>Welcome to the Head First Lounge</h1> B

    <img src="drinks.gif"> C

    <p>

  D Join us any evening for refreshing elixirs,

    conversation and maybe a game or

    two of <em>Dance Dance Revolution</em>. E

    Wireless access is always provided;

    BYOWS (Bring your own web server).

  </p>

  <h2>Directions</h2> F

  <p>

  G You'll find us right in the center of

    downtown Webville. Come join us!

  </p>

  </body>

  </html>




We don't expect you to know HTML, yet.


At this point you should just be getting a feel for what HTML looks like; we're going to cover everything in detail in a bit. For now, study the HTML and see how it gets represented in the browser on the next page. Be sure to pay careful attention to each letter annotation and how and where it is displayed in the browser.



Previous Page

Next Page




Previous Page

Next Page



1.5. What the browser creates...


When the browser reads your HTML, it interprets all the tags that surround your text. Tags are just words or characters in angle brackets, like <head>, <p>, <h1>, and so on. The tags tell the browser about the structure and meaning of your text. So rather than just giving the browser a bunch of text, with HTML you can use tags to tell the browser what text is in a heading, what text is a paragraph, what text needs to be emphasized, or even where images need to be placed.


Let's check out how the browser interprets the tags in the Head First Lounge:


A

Notice how each tag in the HTML maps to what the browser displays.

B

C

D

E

F

G



Previous Page

Next Page




Previous Page

Next Page



1.6. there are no Dumb Questions


Q:


So HTML is just a bunch of tags that I put around my text?

A:


For starters. Remember that HTML stands for HyperText Markup Language, so HTML gives you a way to "mark up" your text with tags that tell the browser how your text is structured. But there is also the HyperText aspect of HTML, which we'll talk about a little later in the book.

Q:


How does the browser decide how to display the HTML?

A:


HTML tells your browser about the structure of your document: where the headings are, where the paragraphs are, what text needs emphasis, and so on. Given this information, browsers have builtin default rules for how to display each of these elements.


But, you don't have to settle for the default settings. You can add your own style and formatting rules with CSS that determine font, colors, size, and a lot of other characteristics of your page. We'll get back to CSS later in the chapter.

Q:


The HTML for the Head First Lounge has all kinds of indentation and spacing, and yet I don't see that when it is displayed in the browser. How come?

A:


Correct, and good catch. Browsers ignore tabs, returns, and most spaces in HTML documents. Instead, they rely on your markup to determine where line and paragraph breaks occur.


So why did we insert our own formatting if the browser is just going to ignore it? To help us more easily read the document when we're editing the HTML. As your HTML documents become more complicated, you'll find a few spaces, returns, and tabs here and there really help to improve the readability of the HTML.

Q:


So there are two levels of headings, <h1> and a subheading <h2>?

A:


Actually there are six, <h1> through <h6>, which the browser typically displays in successively smaller font sizes. Unless you are creating a complex and large document, you typically won't use headings beyond <h3>.

Q:


Why do I need the <html> tag? Isn't it obvious this is a HTML document?

A:


The <html> tag tells the browser your document is actually HTML. While some browsers will forgive you if you omit it, some won't, and as we move toward "industrial strength HTML" later in the book, you'll see it is quite important to include this tag.

Q:


What makes a file an HTML file?

A:


Basically an HTML file is a simple text file. Unlike a word processing file, there is no special formatting embedded in it. By convention we add a ".html" or ".htm" (on systems that only support three letter file extensions) to the end of the file name to give the operating system a better idea of what the file is. But, as you've seen, what really matters is what we put inside the file.

Q:


Markup seems silly. What-yousee-is-what-you-get applications have been around since, what, the '70s? Why isn't the Web based on a format like Microsoft Word or a similar application?

A:


The Web is created out of text files without any special formatting characters. This enables any browser in any part of the world to retrieve a Web page and understand its contents. You'll see that on the Web, in many ways HTML is more powerful than using a proprietary document format.

Q:


Is there any way to put comments to myself in HTML?

A:


Yes, if you place your comments in between <!-- and --> the browser will totally ignore them. Say you wanted to write a comment "Here's the beginning of the lounge content". You'd do that like this:


<!-- Here's the beginning of

the lounge content -->



Notice that you can put comments on multiple lines. Keep in mind anything you put between the "<!--" and the "-->", even HTML, will be ignored by the browser.



Sharpen your pencil


You're closer to learning HTML than you think...


Here's the HTML for the Head First Lounge again. Take a look at the tags and see if you can guess what they tell the browser about the content. Write your answers in the space on the right; we've already done the first couple for you..


Tells the browser this is the start of HTML.. Starts the page "head" (more about this later).



<html>

  <head>

    <title>Head First Lounge</title>

  </head>

  <body>

    <h1>Welcome to the Head First Lounge</h1>

    <img src="drinks.gif">

    <p>

      Join us any evening for refreshing elixirs,

      conversation and maybe a game or

      two of <em>Dance Dance Revolution</em>.

      Wireless access is always provided;

      BYOWS (Bring your own web server).

    </p>

    <h2>Directions</h2>

    <p>

      You'll find us right in the center of

      downtown Webville. Come join us!

    </p>

  </body>

</html>




Sharpen your pencil: answers


<html>

  <head>

    <title>Head First Lounge</title>

  </head>

  <body>

    <h1>Welcome to the Head First Lounge</h1>

    <img src="drinks.gif">

    <p>

      Join us any evening for refreshing elixirs,

      conversation and maybe a game or

      two of <em>Dance Dance Revolution</em>.

      Wireless access is always provided;

      BYOWS (Bring your own web server).

    </p>

    <h2>Directions</h2>

    <p>

      You'll find us right in the center of

      downtown Webville. Come join us!

    </p>

  </body>

</html>



Tells the browser this is the start of HTML..


Starts the page "head"


Gives the page a title.


Start of the body of page.


Tells browser that "Welcome to..." is a heading.


Places the image "drinks.gif" here.


Start of a paragraph.


Puts emphasis on dance dance revolution.


End of paragraph.


Tells the browser that "Directions" is a subheading.


Start of another paragraph.


End of paragraph.


End of the body.


Tells the browser this is the end of the HTML.



Previous Page

Next Page




Previous Page

Next Page



1.7. Your big break at Starbuzz Coffee


Starbuzz Coffee has made a name for itself as the fastest growing coffee shop around. If you've seen one on your local corner, look across the street you'll see another one.


In fact, they've grown so quickly, they haven't even managed to put up a web page, yet... and therein lies your big break: By chance, while buying your Starbuzz Chai Tea, you run into the Starbuzz CEO...


Word has it you know a little about HTML. We really need a Web page that features the Starbuzz offerings. Can you help?


The Starbuzz CEO



BRAIN POWER


Decisions, decisions. Check your first priority below (choose only one):


  • A. Give dog a bath.


  • B. Finally get my checking account balanced.


  • C. Take the Starbuzz gig and launch BIG-TIME Web career.


  • D. Schedule dentist appointment.



Wonderful! We're so glad you'll be helping us.[*] Here's what we need on our first page...


[*] If by chance you chose options A, B, or D on the previous page, we recommend you donate this book to a good library, use it as kindling this winter, or what the hell, go ahead and sell it on Amazon and make some cash.



Sharpen your pencil


Take a look at the napkin. Can you determine the structure of it? In other words, are there obvious headings? Paragraphs? Is it missing anything like a title?


Go ahead and mark up the napkin (using your pencil) with any structure you see, and add anything that is missing.


You'll find our answers at the end of Chapter 1.




Starbuzz Coffee Starbuzz Coffee


Thanks for giving us a hand! On the Web page we just need something simple (see below) that includes the beverage names, prices, and descriptions.


House Blend, $1.49 A smooth, mild blend of coffees from Mexico, Bolivia and Guatemala.


The CEO scribbles something on a napkin and hands it to you...


Mocha Cafe Latte, $2.35 Espresso, steamed milk and chocolate syrup.


Cappuccino, $1.89 A mixture of espresso, steamed milk and foam.


Chai Tea, $1.85 A spicy drink made with black tea, spices, milk and honey.



Previous Page

Next Page




Previous Page

Next Page



1.8. Creating the Starbuzz Web page


Of course, the only problem with all this is that you haven't actually created any Web pages, yet. But, that's why you decided to dive head first into HTML, right?


No worries, here's what you're going to do on the next few pages:


  1. Create an HTML file using your favorite text editor.


  1. Type in the menu the Starbuzz CEO wrote on the napkin.


  1. Save the file as "index.html".


  1. Open the file "index.html" in your favorite browser, step back, and watch the magic happen.


No pressure, but thousands of people are going to visit this Web page when you're finished. It not only needs to be correct, it's gotta look great, too!


Previous Page

Next Page




Previous Page

Next Page



1.9. Creating an HTML file (Mac)


All HTML files are text files. To create a text file you need an application that allows you to create plain text without throwing in a lot of fancy formatting and special characters. You just need plain, pure text.


We'll use TextEdit on the Mac in this book; however, if you prefer another text editor, that should work fine as well. And, if you're running Windows, you'll want to skip ahead a couple of pages to the Windows instructions.



Step one:


Navigate to your Applications


folder The TextEdit application is in the Applications folder. The easiest way to get there is to choose "New Finder Window" from the Finder's File menu and then look for the Application directly in your shortcuts. When you've found it, click on Applications.



step two:


Locate and run TextEdit


You'll probably have lots of applications listed in your applications folder, so scroll down until you see TextEdit. To run the application, double click on the TextEdit icon.


Your Finder shortcuts.



step three (optional):


Keep TextEdit in your Dock If you want to make your life easier, click and hold on the TextEdit icon in the Dock (this icon appears once the application is running). When it displays a popup menu, choose "Keep in Dock." That way, the TextEdit icon will always appear in your Dock and you won't have to hunt it down in the Applications folder every time you need to use it.



Step four:


Change your TextEdit Preferences


By default, TextEdit is in "rich text" mode, which means it will add its own formatting and special characters to your file when you save it not what you want. So, you'll need to change your TextEdit Preferences so that TextEdit saves your work as a pure text file. To do this, first choose the "Preferences" menu item from the TextEdit menu.


This text formatting menu means you're in "rich text" mode. If you see these, you need to change your preferences.



Step five


Set Preferences for Plain text


Once you see the Preferences dialog box, there are three things you need to do.


First, choose "Plain text" as the default editor mode in the New Document tab.


Second, in the "Open and Save" tab, make sure that the "Add .txt extension to plain text files" is unchecked.


Last, make sure "Ignore rich text commands in HTML files" is checked.


That's it; to close the dialog box click on the red button in the top left corner.



Step six:


Quit and restart Now quit out of TextEdit by choosing Quit from the TextEdit menu, and then restart the application. This time, you'll see a window with no fancy text formatting menus at the top of the window. You're now ready to create some HTML.


See, the formatting menu is gone: that means we're in text mode.


Previous Page

Next Page




Previous Page

Next Page



1.10. Creating an HTML file (Windows)


Or another version of Windows.


If you're reading this page you must be a Windows XP user. If not, you might want to skip a couple of pages ahead. Or, if you just want to sit in the back and not ask questions, we're okay with that too.


To create HTML files in XP we're going to use Notepad it ships with every copy of Windows, the price is right, and it's easy to use. If you've got your own favorite editor that runs on XP, that's fine too; just make sure you can create a plain text file with an ".html" extension.


Assuming you're using Notepad, here's how you're going to create your first HTML file.


If you're using another version of Windows you'll find Notepad there as well.



step one:


Open the Start menu and navigate to Notepad


You'll find the Notepad application in Accessories. The easiest way to get there is to click on the "Start" menu, then on "All Programs", then "Accessories". You'll see Notepad listed there.



Step two:


Open Notepad


Once you've located Notepad in the Accessories folder, go ahead and click on it. You'll see a blank window ready for you to start typing HTML.



Step three: Optional but recommended


Don't hide extensions of well known file types.


By default XP's File Explorer hides the file extensions of well known file types. For example, a file named, "Irule.html" will be shown in the Explorer as "Irule" without its ".html" extension.


It's much less confusing if XP shows you these extensions, so let's change your folder options so you can see the file extensions.


First, in any Explorer window select "Folder Options..." from the Tools menu.


Next, in the "View" tab, under "Advanced settings", scroll down until you see "Hide extensions for known file types" and uncheck this option.


That's it. Click on the OK button to save the preference and you'll now see the file extensions in the Explorer.


Previous Page

Next Page




Previous Page

Next Page



1.11. there are no Dumb Questions


Q:


Why am I using a simple text editor? Aren't there powerful tools like Dreamweaver , FrontPage and GoLive for creating Web pages?

A:


You're reading this book because you want to understand the true technologies used for Web pages, right? Now those are all great tools, but they do a lot of the work for you, and until you are a master of HTML and CSS you want to learn this stuff without a big tool getting in your way.


Once you're a master, however, these tools do provide some nice features like syntax checking and previews. At that point, when you view the "code" window, you'll understand everything in it, and you'll find that changes to the raw HTML and CSS are often a lot faster than going through a user interface. You'll also find that as standards change, these tools aren't always updated right away and may not support the most recent standards until their next release cycle. Since you'll know how to change the HTML and CSS without the tool, you'll be able to keep up with the latest and greatest all the time.

Q:


I get the editor, but what browser am I supposed to be using? There are so many Internet Explorer , Firefox , Opera , Safari what's the deal?

A:


The simple answer: use whatever browser you like. HTML and CSS are industry standards, which means that all browsers try to support HTML and CSS in the same way (just make sure you are using the newest version of the browser for the best support).


The complex answer: in reality there are slight differences in the way browsers handle your pages. If you've got users who will be accessing your pages in a variety of browsers, then always test your web page in several different browsers. Some pages will look exactly the same; some won't. The more advanced you become with HTML and CSS, the more these slight differences may matter to you, and we'll get into some of these subtleties throughout the book.


If you're looking for a good browser, give Mozilla's Firefox a try; it has very good HTML and CSS support.

Q:


I'm creating these files on my own computer how am I going to view these on the Web/Internet?

A:


That's one great thing about HTML: you can create files and test them on your own computer and then later publish them on the Web. Right now we're going to worry about how to create the files and what goes in them. We'll come back to getting them on the Web a bit later.


Previous Page

Next Page




Previous Page

Next Page



1.12. Meanwhile, back at Starbuzz Coffee...


Okay, now that you know the basics of creating a plain text file, you just need to get some content into your text editor, save it, and then load it into your browser.


Start by typing in the beverages straight from the CEO's napkin; these beverages are the content for your page. You'll be adding some HTML markup to give the content some structure in a bit, but for now, just get the basic content typed in. While you're at it, go ahead and add "Starbuzz Coffee Beverages" at the top of the file.


Type in the info from the napkin like this.


Mac


Windows


Previous Page

Next Page




Previous Page

Next Page



1.13. Saving your work...


Once you've typed in the beverages from the CEO's napkin, you're going to save your work in a file called "index.html". Before you do that, you'll want to create a folder named "starbuzz" to hold the site's files.


To get this all started, choose "Save" from the File menu and you'll see a "Save As" dialog box. Then, here's what you need to do:


  1. First, create a "starbuzz" folder for all your Starbuzz related files. You can do this with the New Folder button.


  1. Create a new folder here.


  1. Windows


  1. Next, click on the newly created "starbuzz" folder and then enter "index.html" as the file name and click on the Save button.


  1. Using Windows you need to also choose "All Files" as your type, otherwise Notepad will add a ".txt" to your filename.


  1. Create a new folder here.


  1. Mac


Previous Page

Next Page




Previous Page

Next Page



1.14. Opening your Web page in a browser


Are you ready to open your first Web page? Using your favorite browser, choose "Open File..." (or "Open..." using Windows XP and Internet Explorer) from the File menu and navigate to your "index.html" file. Select it and click "Open".


Mac


On the Mac, navigate to your file, and select it by clicking on the file icon and then on the Open button.


Windows


In Windows Internet Explorer it's a two step process. First you'll get the open dialog box.


Then click "Browse" to get a browse dialog and navigate to where you saved your file.


Previous Page

Next Page




Previous Page

Next Page



1.15. Taking your page for a test drive...


Success! You've got the page loaded in the browser, although the results are a little... uh... unsatisfying. But that's just because all you've done so far is go through the mechanics of creating a page and viewing it in the browser. And, so far, you've only typed in the content of the Web page. That's where HTML comes in. HTML gives you a way to tell the browser about the structure of your page. What's structure? As you've already seen, it is a way of marking up your text so that the browser knows what's a heading, what text is in a paragraph, what text is a subheading, and so on. Once the browser knows a little about the structure, it can display your page in a more meaningful and readable manner.


Depending on your operating system and browser, often you can just double-click the HTML file or drag it on top of the browser icon to open it. Much simpler.


Windows


Mac


Previous Page

Next Page




Previous Page

Next Page



1.16. Markup Magnets


So, let's add that structure...


Your job is to add structure to the text from the Starbuzz napkin. Use the fridge magnets at the bottom of the page to mark up the text so that you've indicated which parts are headings, subheadings and paragraph text. We've already done a few to get you started. You won't need all the magnets below to complete the job; some will be left over.


<h1>Starbuzz Coffee Beverages</h1>


    House Blend, $1.49

    A smooth, mild blend of coffees from Mexico, Bolivia

    and Guatemala.


<h2>Mocha Cafe Latte, $2.35</h2>

<p>Espresso, steamed milk and chocolate syrup.</p>


    Cappuccino, $1.89

    A mixture of espresso, steamed milk and foam.


    Chai Tea, $1.85

    A spicy drink made with black tea, spices, milk and honey.



<h1>Use this magnet to start a heading.

</h1>Use this magnet to end a heading.

<h2>

<h2>Use this magnet to start a subheading.

</h2>Use this magnet to end a subheading.

<p>

<p>

<p>Use this magnet to start a paragraph.

</p>Use this magnet to end a paragraph.



Previous Page

Next Page




Previous Page

Next Page



1.17. 1st Congratulations, you've just written your first HTML!


They might have looked like fridge magnets, but you were really marking up your text with HTML. Only, as you know, we usually refer to the magnets as tags.


Check out the markup below and compare it to your magnets on the previous page.


Use the <h1>

and </h1> tags to mark headings. All the text in between is

the actual content of the heading.<h1>Starbuzz Coffee Beverages</h1>

<h2>

House Blend, $1.49</h2>The <h2>

and </h2> tags go around a subheading. Think of an <h2> heading as a

subheading of an <h1> heading.

<p>

A smooth, mild blend of coffees from Mexico, Bolivia

and Guatemala.</p>

<h2>Mocha Cafe Latte, $2.35</h2>

<p>Espresso, steamed milk and chocolate syrup.</p>The <p>

and </p> tags go around a block of text that is a paragraph. That can be one or

many sentences.

<h2>Cappuccino, $1.89</h2>

<p>A mixture of espresso, steamed milk and foam.</p>

<h2>Chai Tea, $1.85</h2>

<p>A spicy drink made with black tea, spices, milk and honey.</p>Notice that

you don't have to put matching tags on the same line. You can put as much content as you

like between them.



Previous Page

Next Page




Previous Page

Next Page



1.18. Are we there yet?


You have an HTML file with markup does that make a Web page? Almost.


You've already seen the <html > , <head > , <title> , and <body > tags, and we just need to add those to make this a first class HTML page...


First, surround your HTML with <html> & </html> tags. This tells the

browser the content of the file is HTML.<html>

        Next add <head> and </head> tags. The head contains

information about your Web page, like its title. For now, think about it this way: the

head allows you to tell the browser things about

the Web page.<head>

The head consists of the <head> & </head> tags and

everything in between.

                <title>Starbuzz Coffee</title>Go ahead and put a

title inside the head. The title usually appears at the top of the browser window.

        </head>


        <body>The body consists of the <body> & </body> tags and

everything in between.


                <h1

>Starbuzz Coffee Beverages</h1>

                <h2

>House Blend, $1.49</h2>

                <p

>A smooth, mild blend of coffees from Mexico,

                         Bolivia and Guatemala.</p>


                <h2>Mocha Cafe Latte, $2.35</h2>

                <p>Espresso, steamed milk and chocolate syrup.</p>


                <h2>Cappuccino, $1.89</h2>

                <p>A mixture of espresso, steamed milk and foam.</p>


                <h2>Chai Tea, $1.85</h2>

                <p>A spicy drink made with black tea, spices, milk and honey.</p>

        </body>The body contains all the content and structure of your Web page  the parts

of the Web page that you see in your browser.

</html>



Keep your head and body separate when writing HTML.


Previous Page

Next Page




Previous Page

Next Page



1.19. Another test drive...


Go ahead and change your "index.html" file by adding in the <head>, </head>, <title>, </title>, <body> and </body> tags. Once you've done that, save your changes and reload the file into your browser.


You can reload the index.html file by selecting the "Open File" menu item again, or by using your browser's reload button.


Notice that the title, which you specified in the <head> element, shows up here.


Now things look a bit better. The browser has interpreted your tags and created a display for the page that is not only more structured but also more readable.


Sweet!


Previous Page

Next Page




Previous Page

Next Page



1.20. Tags dissected...


Okay, you've seen a bit of markup, so let's zoom in and take a look at how tags really work...


Here's the opening tag


that begins the

heading.<h1>


Tags consist of the tag name surrounded by angle brackets; that is, the

< and > characters.You usually put tags around

some piece of content. Here we're using tags to tell the browser that our content,

"Starbuzz Coffee Beverages", is a top level heading (that is, heading level one).

Starbuzz Coffee Beverages The whole shebang is called an element.

In this case we can call it the <h1> element. An element consists of the enclosing

tags and the content in between. This is the

closing tag


that ends the heading; in this case the </h1> tag is ending an

<h1> heading. You know it's a closing tag because it comes after the content, and

it's got a "/" before the "h1". All closing tags have a "/" in them.</h1>We call

an opening tag and its closing tag matching tags


.



To tell the browser about the structure of your page, use pairs of tags around your content.


Remember,


Element = Opening Tag + Content + Closing Tag




Previous Page

Next Page




Previous Page

Next Page



1.21. there are no Dumb Questions


Q:


So matching tags don't have to be on the same line?

A:


No; remember the browser doesn't really care about tabs, returns, and most spaces. So, your tags can start and end anywhere on the same line or they can start and end on different lines. Just make sure you start with an opening tag, like <h2>, and end with a closing tag, like </h2>.

Q:


Why do the closing tags have that extra "/"?

A:


That "/" in the closing tag is to help both you and the browser know where a particular piece of structured content ends. Otherwise, the closing tags would look just like the opening tags, right?

Q:


I've noticed the HTML in some pages doesn't always match opening tags with closing tags.

A:


Well, the tags are supposed to match. In general, browsers do a pretty good job of figuring out what you mean if you write incorrect HTML. But, as you're going to see, these days there are big benefits to writing totally correct HTML. If you're worried you'll never be able to write perfect HTML, don't be; there are plenty of tools to verify your code before you put it on a Web server so the whole world can see it. For now, just get in the habit of always matching your opening tags with closing tags.

Q:


Well, what about that <img src="drinks.gif"> tag in the lounge example? Did you forget the closing tag?

A:


Wow, sharp eye. There are some elements that use a shorthand notation with only one tag. Keep that in the back of your mind for now and we'll come back to it in a later chapter.

Q:


An element is an opening tag + content + closing tag, but can't you have tags inside other tags? Like the head and body are inside an <html> tag?

A:


Yes, HTML tags are often "nested" like that. If you think about it, it's natural for an HTML page to have a body, which contains a paragraph, and so on. So many HTML elements have other HTML elements between their tags. We'll take a good look at this kind of thing in later chapters, but for now just get your mind noticing how the elements relate to each other in a page.



BRAIN POWER


Tags can be a little more interesting than what you've seen so far. Here's the paragraph tag with a little extra added to it. What do you think this does?



    <p id="houseblend">A smooth, mild

    blend of coffees from Mexico, Bolivia

    and Guatemala.</p>





Exercise


Oh, I forgot to mention, we need our company mission on a page, too. Grab the mission statement off one of our coffee cups and create another page for it...


Starbuzz Coffee's Mission


To provide all the caffeine that you need to power your life.


Just drink it.


  1. Write the HTML for the new "mission.html" page here.


  1. Type in your HTML using a text editor, and save it as "mission.html" in the same folder as your "index.html" file.


  1. Once you've done that, open "mission.html" in your browser.


  1. Check your work at the end of the chapter before moving on...



Okay, it looks like you're getting somewhere. You've got the main page and the mission page all set. But, don't forget the CEO said the site needs to look great too. Don't you think it needs a little style?


Right. We have the structure down, so now we're going to concentrate on its presentation.


You already know that HTML gives you a way to describe the structure of the content in your files. When the browser displays your HTML, it uses its own built-in default style to present this structure. But, relying on the browser for style obviously isn't going to win you any "designer of the month" awards.


That's where CSS comes in. CSS gives you a way to describe how your content should be presented. Let's get our feet wet by creating some CSS that makes the Starbuzz page look a little more presentable (and launch your Web career in the process).


CSS is an abbreviation for Cascading Style Sheets. We'll get into what that all means later, but for now just know that CSS gives you a way to tell the browser how elements in your page should look.


Previous Page

Next Page




Previous Page

Next Page



1.22. Meet the style element


To add style, you add a new (say it with us) E-L-E-M-E-N-T to your page the <style> element. Let's go back to the main Starbuzz page and add some style. Check it out...



<html>

        <head>

                The <style> element is placed inside the head of your HTML.

<title>Starbuzz Coffee</title>

               <style type="text/css">Just like other elements, the <style>

element has an opening tag, <style>, and a closing tag, </style>...

...but, the <style> tag also requires an attribute, called type, which tells the

browser the kind of style you're using. Because you're going to use CSS, you need to

specify the "text/css" type.

And, here's where you're going to define the styles for the page.




               </style>

        </head>


        <body>

                <h1>Starbuzz Coffee Beverages</h1>


                <h2>House Blend, $1.49</h2>

                <p>A smooth, mild blend of coffees from Mexico, Bolivia and

                                      Guatemala.</p>


                <h2>Mocha Caffe Latte, $2.35</h2>

                <p>Espresso, steamed milk and chocolate syrup.</p>


                <h2>Cappuccino, $1.89</h2>

                <p>A mixture of espresso, steamed milk and milk foam.</p>


                <h2>Chai Tea, $1.85</h2>

                <p>A spicy drink made with black tea, spices, milk and honey.</p>

        </body>

</html>




there are no Dumb Questions


Q:


An element can have an "attribute?" What does that mean?

A:


Attributes give you a way to provide additional information about an element. Like, if you have a style element, the attribute allows you to say exactly what kind of style you're talking about. You'll be seeing a lot more attributes for various elements; just remember they give you some extra info about the element.

Q:


Why do I have to specify the type of the style, "text/css", as an attribute of the style? Are there other kinds of style?

A:


There aren't currently any other styles that work with today's browsers, but those designers of HTML are always planning ahead and anticipate that there may be other types of style in the future. Personally, we're holding our breath for the <style type="50sKitsch"> style.



Previous Page

Next Page




Previous Page

Next Page



1.23. Giving Starbuzz some style...


Now that you've got a <style> element in the HTML head, all you need to do is supply some CSS to give the page a little pizazz. Below you'll find some CSS already "baked" for you. Whenever you see the logo, you're seeing HTML and CSS that you should type in as-is. Trust us. You'll learn how the markup works later, after you've seen what it can do.


So, take a look at the CSS and then add it to your "index.html" file. Once you've got it typed in, save your file.


1.23.1. Ready Bake CSS



<html>

        <head>

                <title>Starbuzz Coffee</title>

                <style type="text/css">

                      body {

                            background-color: #d2b48c;

                            margin-left: 20%;

                            margin-right: 20%;

                            border: 1px dotted gray;

                            padding: 10px 10px 10px 10px;

                            font-family: sans-serif;

                      }

                </style>

        </head>


       <body>

               <h1>Starbuzz Coffee Beverages</h1>


               <h2>House Blend, $1.49</h2>

               <p>A smooth, mild blend of coffees from Mexico, Bolivia and

           Guatemala.</p>


              <h2>Mocha Caffe Latte, $2.35</h2>

              <p>Espresso, steamed milk and chocolate syrup.</p>


              <h2>Cappuccino, $1.89</h2>

              <p>A mixture of espresso, steamed milk and milk foam.</p>


              <h2>Chai Tea, $1.85</h2>

              <p>A spicy drink made with black tea, spices, milk and honey.</p>

       </body>

</html>



CSS uses a syntax that is totally different from HTML.


Previous Page

Next Page




Previous Page

Next Page



1.24. Cruisin' with style...


It's time for another test drive, so reload your "index.html" file again. This time you'll see the Starbuzz Web page has a whole new look.


Background color is now tan.


Now we have margins around the content.


We've got a gray border around the content as well...


There's now some padding between the content and the border (on all sides).


We're using a different font for a cleaner look.


Whoa! Very nice. We're in business now!



WHO DOES WHAT?


Even though you've just glanced at CSS, you've already begun to see what it can do. Match each line in the style definition to what it does.



background-color: #d2b48c;



Defines the font to use for text.


margin-left: 20%;

margin-right: 20%;



Defines a border around the body that is dotted and the color gray.


border: 1px dotted grey;



Sets the left and right margins to take up 20% of the page each.


padding: 10px 10px 10px 10px;



Sets the background color to a tan color.


font-family: sans-serif;



Creates some padding around the body of the page.




1.24.1. there are no Dumb Questions


Q:


CSS looks like a totally different language than HTML. Why have two languages? That's just more for me to learn, right?

A:


You are quite right that HTML and CSS are completely different languages, but that is because they have very different jobs. Just like you wouldn't use English to balance your checkbook, or Math to write a poem, you don't use CSS to create structure or HTML to create style because that's not what they were designed for. While it does mean you need to learn two languages, you'll discover that because each language is good at what it does, this is actually easier than if you had to use one language to do both jobs.

Q:


#d2b48c doesn't look like a color. How is #d2b48c the color "tan"?

A:


There are a few different ways to specify colors with CSS. The most popular is called a "hex code", which is what #d2b48c is. This really is a tan color. For now, just go with it, and we'll be showing you exactly how #d2b48c is a color a little later.

Q:


Why is there a "body" in front of the CSS rules? What does that mean?

A:


The "body" in the CSS means that all the CSS between the "{" and "}" applies to content within the HTML <body> element. So when you set the font to sans-serif, you're saying that the default font within the body of your page should be sans-serif.


We'll go into a lot more detail about how CSS works shortly, so keep reading. Soon, you'll see that you can be a lot more specific about how you apply these rules, and by doing so you can create some pretty cool designs.


Previous Page

Next Page




Previous Page

Next Page



1.25. Exercise


Now that you've put a little style in the Starbuzz "index.html" page, go ahead and update your "mission.html" page to have the same style.


  1. Write the HTML for the "mission.html" page below, and then add the new CSS.


  1. Update your "mission.html" file to include the new CSS.


  1. Once you've done that, reload "mission.html" in your browser.


  1. Make sure your mission page looks like ours, at the end of the chapter.


Previous Page

Next Page




Previous Page

Next Page



1.26. Firside Chats


Tonight's talk: HTML and CSS on content anad style.



HTML


CSS


Greetings CSS; I'm glad you're here because I've been wanting to clear up some confusion about us.




Really? What kind of confusion?


Lots of people think that my tags tell the browsers how to display the content. It's just not true! I'm all about structure, not presentation.




Heck yeah I don't want people giving you credit for my work!


Well, you can see how some people might get confused; after all, it's possible to use HTML without CSS and still get a decent-looking page.




"Decent" might be overstating it a bit, don't you think? I mean, the way most browsers display straight HTML looks kinda crappy. People need to learn how powerful CSS is and how easily I can give their web pages great style.


Hey, I'm pretty powerful too. Having your content structured is much more important than having it look good. Style is so superficial; it's the structure of the content that matters.




Get real! Without me web pages would be pretty damn boring. Not only that, take away the ability to style pages and no one is going to take your pages seriously. Everything is going to look clumsy and unprofessional.


Whoa, what an ego! Well I guess I shouldn't expect anything else from you you're just trying to make a fashion statement with all that style you keep talking about.




Fashion statement? Good design and layout can have a huge effect on how readable and usable pages are. And you should be happy that my flexible style rules allow designers to do all kinds of interesting things with your elements without messing up your structure.


Right. In fact we're totally different languages, which is good because I wouldn't want any of your style designers messing with my structure elements.




Don't worry, we're living in separate universes.


Yea, that is obvious to me any time I look at CSS talk about an alien language.




Yeah, like HTML can be called a language? Who has ever seen such a clunky thing with all those tags?


Millions of web writers would disagree with you. I've got a nice clean syntax that fits right in with the content.




Just take a look at CSS; it's so elegant and simple, no goofy angle brackets <around> <everything>. <See> <I> <can><talk> <just><like><Mr.><HTML><,><look><at> <me><!>


Hey stupid, ever heard of closing tags?



Just notice that no matter where you go, I've got you surrounded by <style> tags. Good luck escaping!




Ha! I'll show you… because, guess what? I can escape…



Not only is this one fine cup of House Blend, but now we've got a web page to tell all our customers about our coffees. Excellent work.


I've got some bigger ideas for the future; in the meantime, can you start thinking about how we are going to get these pages on the Internet so other people can see them?



BULLET POINT


  • HTML and CSS are the languages we use to create web pages.


  • Web servers store and serve Web pages, which are created from HTML and CSS. Browsers retrieve pages and render their content based on the HTML and CSS.


  • HTML is an abbreviation for HyperText Markup Language and is used to structure your web page.


  • CSS is an abbreviation for Cascading Style Sheets, and is used to control the presentation of your HTML.


  • Using HTML we mark up content with tags to provide structure. We call matching tags, and their enclosed content, elements.


  • An element is composed of three parts: an opening tag, content and a closing tag. There are a few elements, like <img>, that are an exception to this rule.


  • Opening tags can have attributes. We've seen a couple: type and align.


  • Closing tags have a "/" after the left angle bracket, in front of the tag name to distinguish them as closing tags.


  • Your pages should always have an <html> element along with a <head> element and a <body> element.


  • Information about the Web page goes into the <head> element.


  • What you put into the <body> element is what you see in the browser.


  • Most whitespace (tabs, returns, spaces) are ignored by the browser, but you can use these to make your HTML more readable (to you).


  • CSS can be added to an HTML Web page by putting the CSS rules inside the <style> element. The <style> element should always be inside the <head> element.


  • You specify the style characteristics of the elements in your HTML using CSS.



Previous Page

Next Page




Previous Page

Next Page



1.27. HTML cross


It's time to sit back and give your left brain something to do. It's your standard crossword; all of the solution words are from this chapter.



Across


Down


4. We emphasized this.


1. What you see in your page.


5. Always separate these in HTML.


2. The "M" in HTML.


7. CSS is used when you need to control this.


3. Browsers ignore this.


11. You markup content to provide this.


6. Style we're all waiting on.


14. Only style available.


8. Tags can have these to provide additional information.


15. About your web page.


9. Purpose of <p> element.


16. Two tags and content.


10. Appears at the top of the browser for each page.


17. You define presentation through this tag.


12. Opening and closing.


18. Company that launched your web career.


13. There are six of these.




Sharpen your pencil: Solution


Go ahead and mark up the napkin (using your pencil) with any structure you see, and add anything that is missing.


Not going to be part of the web page


Thanks for giving us a hand! On the Web page we just need something simple (see below) that includes the beverage names, prices and descriptions.


Starbuzz Coffee Beverages


Add a page heading.


House Blend, $1.49


A sub-heading…


Paragraphs.


A smooth, mild blend of coffees from Mexico, Bolivia and Guatemala.


Mocha Cafe Latte, $2.35


Another sub-heading.


Espresso, steamed milk and chocolate syrup.


More sub-headings.


Cappuccino, $1.89


A mixture of espresso, steamed milk and foam.


More sub-headings.


Chai Tea, $1.85


A spicy drink made with black tea, spices, milk and honey.



Previous Page

Next Page




Previous Page

Next Page



1.28. Markup Magnets Solution


Your job is to add some structure to the text from the Starbuzz napkin. Use the fridge magnets at the bottom of the page to mark up the text so that you've indicated which parts are headings, subheadings and paragraph text. We've already done a few to get you started. You won't need all the magnets below to complete the job; some will be left over.



<h1>Starbuzz Coffee Beverages</h1>


<h2>House Blend, $1.49</h2>


<p>A smooth, mild blend of coffees from Mexico, Bolivia and Guatemala.</p>


<h2>Mocha Cafe Latte, $2.35</h2>


<p>Espresso, steamed milk and chocolate syrup.</p>


<h2>Cappuccino, $1.89</h2>


<p>A mixture of espresso, steamed milk and foam.</p>


<h2>Chai Tea, $1.85</h2>


<p>A spicy drink made with black tea, spices, milk and honey.</p>


<h1></h1>



Previous Page

Next Page




Previous Page

Next Page



1.29. Exercise Solutions


Starbuzz Coffee's Mission To provide all the caffeine that you need to power your life. Just drink it.


  <html>

    <head>

      <title>Starbuzz Coffee's Mission</title>

    </head>

    <body>

      <h1>Starbuzz Coffee's Mission</h1>

      <p>To provide all the caffeine that you need to

  power your life.</p>

      <p>Just drink it.</p>

    </body>

  </html>

Here's the HTML.



Here's the HTML displayed in a browser.



Exercise Solutions


    <html>

      <head>

        <title>Starbuzz Coffee's Mission</title>

        <style type="text/css">

          body {

               background-color: #d2b48c;

               margin-left: 20%;

               margin-right: 20%;

               border: 1px dotted gray;

               padding: 10px 10px 10px 10px;

               font-family: sans-serif;

         }

      </style>

      </head>

      <body>

        <h1>Starbuzz Coffee's Mission</h1>

        <p>To provide all the caffeine that you need to power your life.</p>

        <p>Just drink it.</p>

        </body>

        </html>





Exercise Solutions: WHO DOES WHAT


Even though you've just glanced at CSS, you've already seen the beginnings of what it can do. Match each line in the style definition to what it does.



background-color: #d2b48c;


Defines the font to use for text.


margin-left: 20%;


margin-right: 20%;


Defines a border around the body that is dotted and the color gray.


border: 1px dotted grey;


Sets the left and right margins to take up 20% of the page each.


padding: 10px 10px 10px 10px;


Sets the background color to a tan color.


font-family: sans-serif;


Creates some padding around the bodyof the page.




  1. BODY


  1. MARKUP


  1. WHITESPACE


  1. DDR


  1. HEADANDBODY


  1. 50SKITCH


  1. PRESENTATION


  1. ATTRIBUTES


  1. PARAGRAPH


  1. TITLE


  1. STRUCTURE


  1. TAGS


  1. HEADINGS


  1. TEXT/CSS


  1. HEAD


  1. ELEMENT


  1. STYLE


  1. STARBUZZ


Previous Page

Next Page




Previous Page

Next Page



Chapter 2. Meeting the 'HT' in HTML


Right, that's me, they call me Hyper Ted.


You're not listening. I came here to meet HyperTEXT!


Did someone say "hypertext?" What's that? Oh, only the entire basis of the Web. In Chapter 1 we kicked the tires of HTML and found it to be a nice markup language (the 'ML' in HTML) for describing the structure of Web pages. Now we're going to check out the 'HT' in HTML, hypertext, which will let us break free of a single page and link to other pages. Along the way we're going to meet a powerful new element, the <a> element, and learn how being "relative" is a groovy thing. So, fasten your seat belts-you're about to learn some hypertext.


Previous Page

Next Page




Previous Page

Next Page



2.1. Head First Lounge , New and Improved


Remember the Head First Lounge? Great site, but wouldn't it be nice if customers could view a list of the refreshing elixirs? Even better, we should give customers some real driving directions so they can find the place.


Welcome to the New and Improved Head First Lounge


Here's the new and improved page.


The "elixirs" link points to a page with a full list of elixir selections.


Join us any evening for refreshing elixirs, conversation and maybe a game or two of Dance Dance Revolution. Wireless access is always provided; BYOWS (Bring your own web server).


We've added links to two new pages, one for elixirs and one for driving directions.


Directions


You'll find us right in the center of downtown Webville. If you need help finding us, check out our detailed directions. Come join us!


The "detailed directions" link leads to an HTML page with driving directions.


Directions


directions.html


Our Elixirs


Green Tea Cooler


Chock full of vitamins and minerals, this elixir combines the healthful benefits of green tea with a twist of chamomile blossoms and ginger root.


Raspberry Ice Concentration


Combining raspberry juice with lemon grass, citrus peel and rosehips, this icy drink will make your mind feel clear and crisp.


Blueberry Bliss Elixir


Blueberries and cherry essence mixed into a base of elderflower herb tea will put you in a relaxed state of bliss in no time.


Cranberry Antioxidant Blast


Wake up to the flavors of cranberry and hibiscus in this vitamin C rich elixir.


A page listing some refreshing and healthy drinks. Feel free to grab one before going on.


elixir.html


2.1.1. Creating the new and improved lounge in three steps...


Let's rework the original Head First Lounge page so it links to the two new pages.


  1. The first step is easy because we've already created the "directions.html" and "elixir.html" files for you. You'll find them in the source files for the book, which are available at http://www.headfirstlabs.com.


  1. Ready Bake


  1. Next you're going to edit the "lounge.html" file and add in the HTML needed to link to "directions.html" and "elixir.html".


  1. Last, you'll give the pages a test drive and try out your new links. When you get back we'll sit down and look at how it all works.


  1. Flip the page and let's get started...


Previous Page

Next Page




Previous Page

Next Page



2.2. Creating the new lounge


  1. Grab the source files


  1. Go ahead and grab the source files from http://www.headfirstlabs.com. Once you've downloaded them, look under the folder "chapter2/lounge" and you'll find "lounge.html", "elixir.html", and "directions.html" (and a bunch of image files).


  1. Chapter 2You'll find the lounge directory here in your source

files.

lounge

All the lounge files are in this folder.

lounge.html

Here's the

current lounge file, without links.

elixir.html

Two new files, already written for you. Go ahead and take a peek-you

already know everything you need to understand them.

directions.html

blue.jpg

drinks.gif

red.jpg

green.jpg

lightblue.jpgAnd here's all the images needed for our new and

improved lounge.




BRAIN POWER


The Head First Lounge is already growing; do you think that keeping all the site's files in a single directory is a good way to organize the site? What would you do differently?



  1. Edit lounge.html


  1. Open "lounge.html" in your editor. Add the new text and HTML that is highlighted below. Go ahead and type this in; we'll come back and see how it all works on the next page.


  1. <html>

  <head>

    <title>Head First Lounge</title>

  </head>

  <body>

    <h1>Welcome to the New and ImprovedLet's add "New and Improved" to the heading. Head First Lounge</h1>

    <img src="drinks.gif">

    <p>

       Join us any evening for

       refreshing <a

href="elixir.html"Here's where

we add the HTML for the link to the elixirs.>elixirs</a>,To

create links we use the <a> element; we'll take a look at how this element works

in just a sec...

       conversation and maybe a game or two of

       <em>Dance Dance Revolution</em>.

       Wireless access is always provided;

       BYOWS (Bring your own web server).

    </p>

    <h2>Directions</h2>

    <p>

      You'll find us right in the center of downtown Webville.

      If you need help finding us, check out

      our <a href="directions.And here's

where we add the link to the directions, again using an <a> element.html">detailed

directions</a>.We need to add

some text here to point customers to the new directions.

    </p>

  </body>

</html>



  1. Save lounge. html and give it a test drive.


  1. When you're finished with the changes, save the file "lounge.html" and open it in your browser. Here are a few things to try...


    1. Click on the elixir link and the new elixir page will display.


    1. Click on the browser's back button and "lounge.html" should be displayed again.


    1. Click on the directions link and the new directions page will display.


2.2.1. Behind the Scenes


Okay, I've loaded the new lounge page, clicked the links, and everything worked. But, I want to make sure I understand how the HTML works.


Previous Page

Next Page




Previous Page

Next Page



2.3. What did we do?


  1. Let's step through creating the HTML links. First we need to put the text we want for the link in an <a> element, like this:


  1. <a>elixirs</a>The <a> element is used to create a link to another page.

<a>driving directions</a>

The content of

the <a> element acts as a label for the link. In the

browser the label appears with an underline to indicate you can click on it.




  1. Now that we have a label for each link, we need to add some HTML to tell the browser where the link points to:


  1. <a href

="elixir.html">elixirs

For this link, the browser will display an "elixirs" label that, when

clicked, will take the user to the "elixir.html" page.

</a>

<a href="directions.html"And for this link, the browser

will display a "driving directions" link that, when clicked, will take the user to the

"directions.html" page.>driving directions</a>



Previous Page

Next Page




Previous Page

Next Page



2.4. What does the browser do?


Behind the Scenes


  1. First, as the browser renders the page, if it encounters an <a> element, it takes the content of the element and displays it as a clickable link.


  1. <a href="elixir.html">elixirs</a>



  1. Both "elixirs" and "detailed directions" are between the opening and closing <a> tags, so they end up being clickable labels in the web page.


  1. <a href="directions.html">detailed directions</a>



  1. Use the <a> element to create a hypertext link to another web page. The content of the <a> element becomes clickable in the web page. The href attribute tells the browser the destination of the link.


  1. Next, when a user clicks on a link, the browser uses the "href" attribute to determine the page the link points to.


The user clicks on either the elixirs link or...


...on detailed directions.


When "detailed directions" is clicked, the browser grabs the value of the href attribute, in this case "directions.html"...


<a href="directions.html">detailed directions</a>



...and loads "directions.html".


If elixirs was clicked, the browser grabs the href value "elixir.html"...


<a href="elixir.html">elixirs</a>



...and displays the "elixir.html" page.


Previous Page

Next Page




Previous Page

Next Page



2.5. Understanding attributes


Attributes give you a way to specify additional information about an element. While we haven't looked at attributes in detail, you've already seen a few examples of them:


<style type="text/css">The type attribute

specifies which style language we're using, in this case CSS.

<a href="irule.html">The href

attribute tells us the destination of a hyperlink.

<img src="sweetphoto.gif">The src

attribute specifies the filename of the picture an img tag displays.



Let's cook up an example to give you an even better feel for how attributes work:


2.5.1. What if <car> was an element?


If <car> was an element, then you'd naturally want to write some markup like this:


<car>My Red Mini</car>With no attributes, all we can supply is a descriptive name for the car.



But this <car> element only gives a descriptive name for your car-it doesn't tell us the make, precise model, whether it is a convertible, or a zillion other details we might want to know. So, if <car> were really an element, we might use attributes like this:


<car make="BMW" model="Mini Cooper" convertibleBut

with attributes, we can customize the element with all kinds of information.="no">My Red Mini</car>



Better, right? Now this markup tells us a lot more information in an easy to write, convenient form.



SAFETY FIRST


Attributes are always written the same way: first comes the attribute name, followed by an equals sign, and then the attribute value surrounded in double quotes.


You may see some sloppy HTML on the Web that leaves off the double quotes, but don't get lazy yourself. Being sloppy can cause you a lot of problems down the road (as we'll see later in the book).


Do this (correct form)


<a hrefattribute name=equals sign"double quotetop10.htmlattribute value"double quote>Great Movies</a>



Not this (incorrect form)


<a href=top10.html>Great Movies</a>



WRONG-no double quotes around the attribute value.



The "href" attribute is pronounced "h-ref"...


...rhymes with "space chef".


2.5.2. there are no Dumb Questions


Q:


Can I just make up new attributes for an HTML element?

A:


No, because Web browsers only know about a predefined set of attributes for each element. If you just made up attributes, then Web browsers wouldn't know what to do with them, and as you'll see later in the book, doing this will very likely get you into trouble. When a browser recognizes an element or an attribute, we like to say that it "supports" that element or attribute. You should only use attributes that you know are supported.

Q:


Who decides what is "supported?"

A:


There are standards committees that worry about the elements and attributes of HTML. These committees are made up of people with nothing better to do who generously give their time and energy to make sure there's a common HTML roadmap that all companies can use to implement their browsers.

Q:


How do I know what attributes and elements are supported? Or, can all attributes be applied to any element?

A:


Only certain attributes can be used with a given element. Think about it this way: you wouldn't use an attribute "convertible" with the element <toaster>, would you? So, you only want to use attributes that make sense and are supported by the element.


We're going to be learning which attributes are supported by which elements as we make our way through the book. After you've finished the book there are lots of great references you can use to refresh your memory, such as HTML & XHTML: The Definitive Guide (O'Reilly).


2.5.3. Attributes Exposed


This week's interview: Confessions of the href attribute


HeadFirst: Welcome, href. It's certainly a pleasure to interview as big an attribute as you.


href: Thanks. It's good to be here and get away from all the linking; it can wear an attribute out. Every time someone clicks on a link, guess who gets to tell the browser where to go next? That would be me.


HeadFirst: We're glad you could work us into your busy schedule. Why don't you take us back to the beginning... What does it mean to be an attribute?


href: Sure. Well, attributes are used to customize an element. It's easy to wrap some <a> tags around a piece of content, like "Sign up now!"-we do it like this: <a>Sign up now!</a>-but without me, the href attribute, you have no way to tell the <a> element the destination of the link.


HeadFirst: Got it so far...


href: ...but with an attribute you can provide additional information about the element. In my case, that's where the link points to:


<a href="signup.html">Sign up now!</a>. This says that the <a> element, which is labeled "Sign up now!", links to the "signup.html" page. Now, there are lots of other attributes in the world, but I'm the one you use with the <a> element to tell it where it points to.


HeadFirst: Nice. Now, I have to ask, and I hope you aren't offended, but what is with the name? href ? What's with that?


href: It's an old Internet family name. It means "hypertext reference", but all my friends just call me "href " for short.


HeadFirst: Which is?


href: A hypertext reference is just another name for a resource that is on the Internet or your computer. Usually the resource is a Web page, but I can also point to audio, video... all kinds of things.


HeadFirst: Interesting. All our readers have seen so far are links to their own pages; how do we link to other pages and resources on the Web?


href: Hey, I gotta get back to work, the whole Web is getting gunked up without me. Besides, isn't it your job to teach them this stuff ?


HeadFirst: Okay okay, yes, we're getting to that in a bit... thanks for joining us, href.



Exercise


You've created links to go from "lounge.html" to "elixir.html" and "directions.html"; now we're going to go back the other way. Below you'll find the HTML for "elixir.html". Add a link with the label "Back to the Lounge" at the bottom of the elixir page that points back to "lounge.html".


<html>

  <head>

    <title>Head First Lounge Elixirs</title>

  </head>

  <body>

    <h1>Our Elixirs</h1>


    <h2>Green Tea Cooler<h2>

    <p>

                 <img src="green.jpg">

                 Chock full of vitamins and minerals, this elixir

                 combines the healthful benefits of green tea with

                 a twist of chamomile blossoms and ginger root.

    </p>

    <h2>Raspberry Ice Concentration</h2>

    <p>

                 <img src="lightblue.jpg">

                 Combining raspberry juice with lemon grass,

                 citrus peel and rosehips, this icy drink

                 will make your mind feel clear and crisp.

    </p>

    <h2>Blueberry Bliss Elixir</h2>

    <p>

                 <img src="blue.jpg">

                 Blueberries and cherry essence mixed into a base

                 of elderflower herb tea will put you in a relaxed

                 state of bliss in no time.

    </p>

    <h2>Cranberry Antioxidant Blast</h2>

    <p>

                 <img src="red.jpg">

                 Wake up to the flavors of cranberry and hibiscus

                 in this vitamin C rich elixir.

    </p>



Your new HTML goes here.


  </body>

</html>



When you are done, go ahead and do the same with "directions.html" as well.




CONSTRUCTION ZONE BEGINS


We need some help constructing and deconstructing <a> elements. Given your new knowledge of the <a> element, we're hoping you can help. In each row below you'll find some combination of the label, destination, and the complete <a> element. Fill in any information that is missing. The first row is done for you.



Label


Destination


What you write in HTML


Hot or Not?


hot.html


<a href="hot.html">Hot or Not?</a>


Resume


cv.html




candy.html


<a href=".............">Eye Candy</a>


See my mini


mini-cooper.html



let's play



<a href="millionaire.html">............ </a>




2.5.4. there are no Dumb Questions


Q:


I've seen many pages where I can click on an image rather than text. Can I use the <a> element for that?

A:


Yes, if you put an <img> element between the <a> tags then your image will be clickable just like text. We're not going to talk about images in depth for a few chapters, but they work just fine as links.

Q:


So I can put anything between the <a> tags and it will be clickable? Like, say, a paragraph?

A:


Whoa now. Not so fast. Not every element can be placed inside an <a> element. In general you'll just be using text and images (or both) within the <a> element. What tags will go inside other tags is a whole other topic, but don't worry; we'll get there soon enough.


Your work on the Head First Lounge has really paid off. With those enticing elixirs and directions, lots of people are frequenting the place and visiting the Web site. Now we've got plans for expanding the lounge's online content in all sorts of directions.


Previous Page

Next Page




Previous Page

Next Page



2.6. Getting organized


Before you start creating more HTML pages, it's time to get things organized. So far, we've been putting all our files and images in one folder. You'll find that even for modestly-sized Web sites, things are much more manageable if you organize your Web pages, graphics, and other resources into a set of folders. Here's what we've got now:


We've got a top-level folder called "lounge" that holds all our files in

the site.loungeThis is

often referred to as the "root" folder of the site, which means it is the top-level

folder that contains the entire site.

lounge.htmlHere are the three HTML

files: for the lounge, the elixirs page, and the directions.

elixir.html

directions.html

blue.jpg

drinks.gif

red.jpg

green.jpg

lightblue.jpgAnd here are all the images. See, this is getting

sorta cluttered already, and we only have three pages and a few graphics. Let's do

something about it....



Previous Page

Next Page




Previous Page

Next Page



2.7. Organizing the lounge...


Let's give the lounge site some meaningful organization now. Keep in mind there are lots of ways to organize any site; we're going to start simple and create a couple of folders for pages. We'll also group all those images into one place.


loungeOur root folder is still the "lounge" folder.

lounge.htmlWe're going to leave the

main "lounge.html" page in the "lounge" folder.

aboutLet's create a folder to hold

pages about the lounge, like the directions. We could also add new pages here about the

management, events, and so on.

directions.html

beveragesWe'll also create a folder to hold pages about the

lounge's beverages. Right now that's just the elixirs, but we'll be adding more soon.

elixir.html

imagesAnd, let's group all images into one folder.

drinks.gif

green.jpg

blue.jpg

red.jpg

lightblue.jpg




there are no Dumb Questions


Q:


Since you have a folder for images, why not have another one called "html" and put all the HTML in that folder?

A:


You could. There aren't any "correct" ways to organize your files; rather, you want to organize them in a way that works best for you and your users. As with most design decisions, you want to choose an organization scheme that is flexible enough to grow, while keeping things as simple as you can.

Q:


Or, why not put an images folder in each other folder, like "about" and "beverages."

A:


Again, we could have. We expect that some of the images will be reused among several pages, so we put images in a folder at the root (the top level) to keep them all together. If you have a site that needs lots of images in different parts of the site, you might want each branch to have its own image folder.

Q:


"Each branch"?

A:


You can understand the way folders are described by looking at them as upside down trees. At the top is the root and each path down to a file or folder is a branch.




Exercise


Now you need to create the file and folder structure shown on the previous page. Here's exactly what you need to do:


  1. Locate your "lounge" folder and create three new subfolders named "about", "beverages", and "images".


  1. Move the file "directions.html" into the "about" folder.


  1. Move the file "elixir.html" into the "beverages" folder.


  1. Move all the images into the "images" folder.


  1. Finally, load your "lounge.html" file and try out the links.


  1. Compare with how ours worked below.



Previous Page

Next Page




Previous Page

Next Page



2.8. Technical difficulties


It looks like we've got a few problems with the lounge page after moving things around.


We've got an image that isn't displaying. We usually call this a "broken image".


And, when you click on elixirs (or detailed directions) things get much worse: we get an error saying the page can't be found.


Some browsers display this error as a web page rather than a dialog box.


I think the problem is that the browser thinks the files are still in the same folder as "lounge.html". We need to change the links so they point to the files in their new folders.


Right. We need to tell the browser the new location of the pages.


So far you've used href values that point to pages in the same folder. Sites are usually a little more complicated, though, and you need to be able to point to pages that are in other folders.


To do that, you trace the path from your page to the destination file. That might mean going down a folder or two, or up a folder or two, but either way we end up with a relative path that we can put in the href.


Previous Page

Next Page




Previous Page

Next Page



2.9. Planning your paths...


What do you do when you're planning that vacation in the family truckster? You get out a map and start at your current location, and then trace a path to the destination. The directions themselves are relative to your location-if you were in another city, they'd be different directions, right?


Okay, you'd really go to Google maps, but work with us here!


To figure out a relative path for your links, it's the same deal: you start from the page which has the link, and then you trace a path through your folders until you find the file you need to point to.


There are other kinds of paths too. We'll get to those in later chapters.


Let's work through a couple of relative paths (and fix the lounge at the same time):


2.9.1. Linking down into a subfolder


  1. Linking from "lounge.html" to "elixir.html".


  1. We need to fix the elixirs link in the "lounge.html" page. Here's what the <a> element looks like now:


  1. <a href="elixir.html">elixirs</a>Right

now we're just using the filename "elixir.html", which tells the browser to look in the

same folder as "lounge.html".



  1. Identify the source and the destination.


  1. When we re-organized the lounge, we left "lounge.html" in the "lounge" folder, and we put "elixir.html" in the "beverages" folder, which is a subfolder of "lounge".


  1. lounge

lounge.htmlStart here...

about

directions.html

beverages

elixirs.html...and find a path to here.

images

drinks.gif

green.jpg

blue.jpg

red.jpg

lightblue.jpg



  1. Trace a path from the source to the destination.


  1. Let's trace the path. To get from the "lounge.html" file to "elixir.html", we need to go into the "beverages" folder first, and then we'll find "elixir.html" in that folder.


  1. lounge

lounge.htmlFirst we need to go down into the "beverages" folder.

about

directions.html

beveragesAnd "elixir.html" is directly in that folder.

elixir.html

images

drinks.gif

green.jpg

red.jpg

blue.jpg

lightblue.jpg



  1. Create an href to represent the path we traced.


  1. Now that we know the path, we need to get it into a format the browser understands. Here's how you write the path:


  1. beveragesFirst we go into the beverages

folder.

/

Separate all parts

of the path with a "/".

beverages / elixir.html

Finally we have the file name.



  1. Putting it all together...


  1. <a href="beverages/elixir.html">elixirs</a>



  1. We put the relative path into the href value. Now when the link is clicked on, the browser will look for the "elixir.html" file in the "beverages" folder.



Sharpen your pencil


Your turn: trace the relative path from "lounge.html" to "directions.html". When you've discovered it, complete the <a> element below. Check your answer in the back of the chapter, and then go ahead and change both <a> elements in "lounge.html."


lounge

lounge.html

about

directions.html

beverages

elixir.html

images

drinks.gif

green.jpg

blue.jpg

red.jpg

lightblue.jpg



<a href="..........YOUR ANSWER HERE">detailed directions</a>




2.9.2. Going the other way; linking up into a "parent " folder


  1. Linking from "directions.html" to "lounge.html".


  1. Now we need to fix those "Back to the Lounge" links. Here's what the <a> element looks like in the "directions.html" file:


  1. <a href="lounge.html">Back to the LoungeRight

now we're just using the filename "lounge.html", which tells the browser to look in the

same folder as "directions.html". That's not going to work.</a>



  1. Identify the source and the destination.


  1. Let's take a look at the source and destination. The source is now the "directions.html" file, which is down in the "about" folder. The destination is the "lounge.html" file that sits above the "about" folder, where "directions.html" is located.


  1. lounge

lounge.html...and find a path to here.

about

directions.htmlStart here...

beverages

elixir.html

images

drinks.gif

green.jpg

blue.jpg

red.jpg

lightblue.jpg



  1. Trace a path from the source to the destination.


  1. Let's trace the path. To get from the "directions.html" file to "lounge.html", we need to go up one folder into the "lounge" folder, and then we'll find "lounge.html" in that folder.


  1. lounge

lounge.html

about

directions.html

beverages

elixir.html

images

drinks.gif

green.jpg

blue.jpg

red.jpg

lightblue.jpg



  1. First we need to go UP into the "lounge" folder...


  1. ...and "lounge.html" is directly in that folder.


  1. Create an href to represent the path we traced.


  1. We're almost there. Now that you know the path, you need to get it into a format the browser understands. Let's work through this:


  1. First you need to go up one folder. How do you do that? With a "..

".

That's right, two periods. Go with it, we'll explain in a sec...Pronounce

".." as "dot dot". /Separate

all parts of the path with a "/".

../ loungeFinally you have the file name..html



  1. Putting it all together...


  1. <a href="../lounge.html"Now when you

click on the link, the browser will look for the "lounge.html" file in the folder

above.>Back to the Lounge</a>



Dot dot Up, down, housewares, lingerie?


2.9.3. there are no Dumb Questions


Q:


What's a parent folder? If I have a folder "apples" inside a folder "fruit", is "fruit" the parent of "apples"?

A:


Exactly. Folders (you might have heard these called directories) are often described in terms of family relationships. For instance, using your example, "fruit" is the parent of "apples", and "apples" is the child of "fruit". If you had another folder "pears" that was a child of "fruit", it would be a sibling of "apples." Just think of a family tree.

Q:


Okay, parent makes sense, but what is ".. "?

A:


When you need to tell the browser that the file you're linking to is in the parent folder, you use ".." to mean "move UP to the parent folder." In other words, it's browser-speak for parent.


In our example, we wanted to link from "directions.html", which is in the "about" folder, to "lounge.html", which is in the "lounge" folder, the parent of "about". So we had to tell the browser to look UP one folder. ".." is the way we tell the browser to go UP.

Q:


What do you do if you need to go up two folders instead of just one?

A:


You can use ".." for each parent folder you want to go up. Each time you use ".." you're going up by one parent folder. So, if you want to go up two folders, you'd type "../..". You still have to separate each part with the "/", so don't forget to do that (the browser won't know what "...." means!).

Q:


Once I'm up two folders, how do I tell the browser where to find the file?

A:


You combine the "../.." with the filename. So, if you're linking to a file called "fruit.html" in a folder that's two folders up, you'd write "../../fruit.html". You might expect that we'd call "../.." the "grandparent" folder, but we don't usually talk about them that way, and instead say, "the parent of the parent folder," or "../.." for short.

Q:


Is there a limit to how far up I can go?

A:


You can go up until you're at the root of your Web site. In our example, the root was the "lounge" folder. So, you could only go up as far as "lounge".

Q:


What about in the other direction-is there a limit to how many folders I can go down?

A:


Well, you can only go down as many folders as you have created. If you create folders that are 10 deep, then you can write a path that takes you down 10 folders. But we don't recommend that-when you have that many folder levels, it probably means your website organization is too complicated!


In addition, there is a limit to the number of characters you can have in a path: 255 characters. That's a lot of characters, so it's unlikely you'll ever need that many, but if you have a large site, it's something to be aware of.

Q:


My operating system uses "\" as a separator; shouldn't I be using that instead of "/"?

A:


No; in Web pages you always use "/". Don't use "\". Various operating systems use different file separators (for instance, Windows uses "\" instead of "/") but when it comes to the Web, we pick a common separator and all stick to it. So, whether you're using Mac, Windows, Linux, or something else, always use "/" in the paths in your HTML.



BRAIN POWER


Your turn: trace the relative path from "elixir.html" to "lounge.html" from the "Back to the Lounge" link. How does it differ from the same link in the "directions.html" file?


Answer: It doesn't, it is exactly the same.



Previous Page

Next Page




Previous Page

Next Page



2.10. Fixing those broken images...


You've almost got the lounge back in working order; all you need to do now is fix those images that aren't displaying.


We haven't looked at the <img> element in detail yet (we will in a couple of chapters), but all you need to know for now is that the <img> element's src attribute takes a relative path, just like the href attribute.


Here's the image element from the "lounge.html" file:


<img src="drinks.gif"Here's the

relative path, which tells the browser where the image is located. We specify this just

like we do with the href attribute in the <a> element.>



Hey, it's nice you fixed all those links, but didn't you forget something? All our images are broken! Don't leave us hanging, we've got a business to run.


2.10.1. Finding the path from "lounge.html" to "drinks.gif"


To find the path, we need to go from the "lounge.html" file to where the images are located, in the "images" folder.


GOAL: we're in the lounge folder and we need to get down into the images folder.


lounge

lounge.htmlStart here...

about

directions.html

beverages

elixir.html

images

drinks.gif...and find a path to here.

green.jpg

blue.jpg

red.jpg

lightblue.jpg



  1. Go down into the images folder.


  1. There's our file, "drinks.gif".


So putting (1) and (2) together our path looks like "images/drinks.gif ", or:


<img src="images/drinks.gif">



2.10.2. Finding the path from "elixir.html" to "red.jpg"


The elixirs page contains images of several drinks: "red.jpg", "green.jpg", "blue.jpg", and so on. Let's figure out the path to "red.jpg" and then the rest will have a similar path because they are all in the same folder:


GOAL: we're in the beverages folder and we need to get over to the images folder.


lounge

lounge.html

about

directions.html

beverages

elixir.html Start here...

images

drinks.gif

blue.jpg

green.jpg

red.jpg

lightblue.jpg...and find a path to here.



  1. So we go up to the parent folder, "lounge". Remember this will be written as ".." in the path.


  1. And then down into the "images" folder.


  1. Finally, we find "red.jpg".


So putting (1), (2), and (3) together we get:


..Up to the parent folder.

/

"/" in between.    imagesDown into

the "images" folder.    /"/" in between.    red.jpgAnd the file name itself.



<img src="../images/red.jpg">




Exercise


That covers all the links we broke when we reorganized the lounge, although you still need to fix the images in your "lounge.html" and "elixir.html" files. Here's exactly what you need to do:


  1. In "lounge.html", update the image src attribute to have the value "images/drinks.gif".


  1. In "elixir.html", update the image src attribute so that "../images/" comes before each image name.


  1. Save both files and load "lounge.html" in your browser. You'll now be able to navigate between all the pages and view the images.


P.S. If you're having any trouble, the folder "chapter2/completelounge" contains a working version of the lounge. Double-check your work against it.



You did it! Now we've got organization and all our links are working. Time to celebrate. Join us and have a green tea cooler.


And then we can take the site to the next level!



BULLET POINTS


  • When you want to link from one page to another, use the <a> element.


  • The href attribute of the <a> element specifies the destination of the link.


  • The content of the <a> element is the label for the link. The label is what you see on the Web page. By default, it's underlined to indicate you can click on it.


  • You can use words or an image as the label for a link.


  • When you click on a link, the browser loads the Web page that's specified in the href attribute.


  • You can link to files in the same folder, or files in other folders.


  • A relative path is a link that points to other files on your Web site relative to the Web page you're linking from. Just like on a map, the destination is relative to the starting point.


  • Use ".." to link to a file that's one folder above the file you're linking from.


  • ".." means "parent folder."


  • Remember to separate the parts of your path with the "/" character.


  • When your path to an image is incorrect, you'll see a broken image on your Web page.


  • Don't use spaces in names when you're choosing names for files and folders for your Web site.


  • It's a good idea to organize your Web site files early on in the process of building your site, so you don't have to change a bunch of paths later when the Web site grows.


  • There are many ways to organize a Web site; how you do it is up to you.




The Relativity Grand Challenge


Here's your chance to put your relativity skills to the test. We've got a Web site for the top 100 albums in a folder named "music". In this folder you'll find HTML files, other folders and images. Your challenge is to find the relative paths we need so we can link from our Web pages to other Web pages and files.


On this page, you'll see the Web site structure; on the next page you'll find the tasks to test your skills. For each source file and destination file, it's your job to make the correct relative path. If you succeed, you will truly be champion of relative paths.


Good luck!


music

top100.htmlFeel free to draw right on this Web site picture to

figure out the paths.

genres

genres.html

rock

pinkfloyd.html

coldplay.html

images

logo.gif

cdcovers

darkside.gif

xandy.gif

artists

floyd.gif

chris.gif



It's time for the competition to begin. Ready... set... write!


EXAMPLE

top100.html

genres/genres.html

"top100.html" is in the "music" folder, so to get to "genres.html", we

had to go down into the "genres" folder.

genres.html

ROUND ONE

<html>

...<html>

logo.gif

<html>

...<html>

logo.gif Bonus Round

<html>

...<html>

coldplay.html chris.gif

top100.html

logo.gif

ROUND TWO

genres.html

logo.gif

ROUND THREE

top100.html

pinkfloyd.html

BONUS ROUND

coldplay.html

chris.gif




Previous Page

Next Page




Previous Page

Next Page



2.11. HTMLcross


How does a crossword help you learn HTML? Well, all the words are HTML-related and from this chapter. In addition, the clues provide the mental twist and turns that will help you burn alternative routes to HTML right into your brain!


Across


1. ../myfiles/index.html is this kind of link.


3. Another name for a folder.


6. Flavor of blue drink.


9. what href stands for.


13. Everything between the <a> and </a> is this.


16. Can go in an <a> element, just like text.


17. Pronounced "..".


Down


2. href and src are two of these.


4. Hardest working attribute on the web.


5. Rhymes with href.


7. Top folder of your site.


8. The "H" in HTML.


10. Healthy drink.


11. A folder at the same level.


12. Use .. to reach this kind of directory.


14. Text between the <a> tags acts as a ______.


15. A subfolder is also called this.



Exercise Solutions


<html>

  <head>

    <title>Head First Lounge Elixirs</title>

  </head>

  <body>

    <h1>Our Elixirs</h1>


    <h2>Green Tea Cooler</h2>

    <p>

                 <img src="green.jpg">

                 Chock full of vitamins anda minerals, this elixir

                 combines the healthful benefits of green tea with

                 a twist of chamomile blossoms and ginger

    </p>

    <h2>Raspberry Ice Concentration</h2>

    <p>

                 <img src="lightblue.jpg">

                 Combining raspberry juice with lemon grass,

                 citrus peel and rosehips, this icy drink

                 will make your mind feel clear and crisp.

    </p>

    <h2>Blueberry Bliss Elixir</h2>

    <p>

                 <img src="blue.jpg">

                 Blueberries and cherry essence mixed into a base

                 of elderflower herb tea will put you in a relaxed

                 state of bliss in no time.

    </p>

    <h2>Cranberry Antioxidant Blast</h2>

    <p>

                 <img src="red.jpg">

                 Wake up to the flavors of cranberry and hibiscus

                 in this vitamin C rich elixir.

    </p>

    <p>

         <a href="lounge.html">Back to the Lounge </a>

Here's the new element pointing back to the lounge.

    </a>

    </p>

We put the link inside its own paragraph to keep things tidy. We'll talk

more about this in the next chapter.

   </body>

</html>




2.11.1. Exercise Solutions



Label


Destination


Element


Hot or Not?


hot.html


<a href="hot.html">Hot or Not?</a>


Resume


cv.html


<a href="cv.html">Resume</a>


Eye Candy


candy.html


<a href="candy.html">Eye Candy</a>


See my mini


mini-cooper.html


<a href="mini-cooper.html">See my mini</a>


let's play


millionaire.html


<a href="millionaire.html">let's play</a>



1.RELATIVE


3.DIRECTORY


6.RASPBERRY


9.HYPERTEXTREFERENCE


13.CLICKABLE


16.IMAGE


17.DOTDOT


2.ATTRIBUTES


4.HREF


5.SPACECHEF


7.ROOT


8.HYPERTEXT


10.ELIXIR


11.SIBLING


12.PARENT


14.LABEL


15.CHILD



Sharpen your pencil : Solution


Trace the relative path from "lounge.html" to "directions.html". When you've discovered it, complete the <a> element below.


Here's the solution. Did you change both <a> elements in "lounge.html"?


lounge

lounge.html

about"about"

directions.html"directions.html"

beverages

elixir.html

images

drinks.gif

green.jpg

blue.jpg

red.jpg

light blue.jpg

<a href="about/directions.htmlYOUR ANSWER HERE">detailed directions</a>




Previous Page

Next Page




Previous Page

Next Page



2.12. The Relativity Grand Challenge Solution


ROUND ONE

top100.html

images/logo.giftop100.html is in the music folder, so to get to logo.gif, we had to go down into the images folder.

logo.gif

ROUND TWO

genres.html

../images/logo.gif

genres.html is down in the genres directory, so to get to logo.gif, we

first had to go up to music, and then down into the images folder.

logo.gif

ROUND THREE

top100.html

genres/rock/pinkfloyd.html

From top100.html, we go down into genres, then down into rock, and find

pinkfloyd.html.

pinkfloyd.html

BONUS ROUND

coldplay.html

../../images/artists/chris.gif

This was a tricky one. From coldplay.html, which is down in the rock

folder, we had to go up TWO folders to get to music, and then go down into images, and

finally artists to find the image chris.gif. Whew!

chris.gif



Previous Page

Next Page




Previous Page

Next Page



Chapter 3. Web Page Construction


We better find some hard hats, Betty. It's a real construction zone around here, and these Web pages are going up fast!


I was told I'd actually be creating Web pages in this book? You've certainly learned a lot already: tags, elements, links, paths... but it's all for nothing if you don't create some killer Web pages with that knowledge. In this chapter we're going to ramp up construction: you're going to take a Web page from conception to blueprint, pour the foundation, build it, and even put on some finishing touches. All you need is your hard hat and your tool belt, as we'll be adding some new tools and giving you some insider knowledge that would make Tim "The Toolman" Taylor proud.


What better way to enjoy my new Segway than to hit the open road? I'm riding it across the entire USA and I've been documenting my travels in my journal. What I really need to do is get this in a Web page so my friends and family can see it.


Tony

Tony's Segway



Segway'n USA


Documenting my trip around the US on my

very own Segway!



June 2, 2005

My first day of the trip! I can't believe I

finally got everything packed and ready to go.

Because I'm on a Segway, I wasn't able to bring

a whole lot with me: cell phone, iPod, digital

camera, and a protein bar. Just the essentials.

As Lao Tzu would have said, "A journey of a

thousand miles begins with one step Segway."



July 14, 2005

Tony's journal


I saw some Burma Shave style signs on the side of

the road today: "Passing cars, When you can't see,

May get you, A glimpse, Of eternity." I definitely

won't be passing any cars!


August 20 2005


Well I made it 1200 miles already, and I passed

through some interesting places on the way:

Walla Walla, WA, Magic City, ID, Bountiful,

UT, Last Chance, CO, Why, AZ and Truth or

Consequences, NM. Make sure you read through Tony's adventures  they'll come in handy throughout the chapter.



Previous Page

Next Page




Previous Page

Next Page



3.1. From Journal to Web site, at 12mph


The Segway's recommended top speed.


Tony's got his hands full driving across the United States on his Segway.


Why don't you give him a hand and create a Web page for him.


Here's what you're going to do:


  1. First, you're going to create a rough sketch of the journal that is the basis for your page design.


  1. Next, you'll use the basic building blocks of HTML (<h1>, <h2>, <h3>, <p>, and so on) to translate your sketch into an outline (or blueprint) for the HTML page.


  1. Once you have the outline, then you're going to translate it into real HTML.


  1. Finally, with the basic page done, you'll add some enhancements and meet some new HTML elements along the way.


STOP! Do this exercise before turning the page.



Sharpen Your Pencil


Your sketch goes here.


Take a close look at Tony's journal and think about how you'd present the same information in a Web page.


Draw a picture of that page on the right. No need to get too fancy, you're just creating a rough sketch. Assume all his journal entries will be on one page.


Things to think about:


  • Think of the page in terms of large structural elements: headings, paragraphs, images, and so on.


  • Are there ways his journal might be changed to be more appropriate for the Web?



Previous Page

Next Page




Previous Page

Next Page



3.2. The rough design sketch


Tony's journal looks a lot like a Web page; all we need to do to create the design sketch is to get all his entries on one page and map out the general organization. It looks like, for each day that Tony creates an entry, he has a date heading, an optional picture, and a description of what happened that day. Let's look at the sketch...


Segway'n USA Tony gave his journal a title, "Segway'n USA", so let's get

that right at the top as a heading.

Documenting my trip around the US on my very own Segway! He also gave his

journal a description. We'll capture that here as a small paragraph at the top.

August 20, 2005 Each day, Tony creates an entry that includes the date,

usually a picture, and a description of the day's adventures. So, that's a heading, an

image, and another paragraph of text.

Well I made it 1200 miles already, and I passed

through some interesting places on the way: Walla Walla,

WA, Magic City, ID, Bountiful, UT, Last Chance, CO,

Why, AZ and Truth or Consequences, NM.

July 14, 2005

I saw some Burma Shave style signs on the side of

the road today: "Passing cars, When you can't see,

May get you, A glimpse, Of eternity." I definitely

won't be passing any cars.Sometimes he doesn't include a picture. In this

entry he just has a heading (the date) and a description of the day's events.

June 2, 2005

The third entry should look just like the first one: a heading, an image, and

a paragraph.

My first day of the trip! I can't believe I finally

got everything packed and ready to go. Because

I'm on a Segway, I wasn't able to bring a whole

lot with me: cellphone, iPod, digital camera, and

a protein bar. Just the essentials. As Lao Tzu

would hav