<<

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance to access them.

www.it-.info

Beginning HTML5 and CSS3

Richard Clark, Oli Studholme, Christopher Murphy and Divya Manian

www.it-ebooks.info Beginning HTML5 and CSS 3 Copyright © 2012 by Richard Clark, Oli Studholme, Christopher Murphy and Divya Manian This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher's location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law. ISBN-13 (pbk): 978-1-4302-2874-5 ISBN-13 (electronic): 978-1-4302-2875-2 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logos, or image we use the names, logos, or images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. For information on translations, please e-mail [email protected] or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales– eBook Licensing at www.apress.com/bulk-sales. Any source code or other supplementary materials referenced by the author in this text is available to readers at www.apress.com. For detailed information about how to locate your book’s source code, go to www.apress.com/source-code/. Credits President and Publisher: Copy Editor: Paul Manning Mary Behr Lead Editor: Compositor: Ben Renow-Clarke Bytheway Publishing Services Technical Reviewers: Indexer: Andrew Zack and Chris Mills SPi Global Editorial Board: Artist: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary SPi Global Cornell, Morgan Ertel, Jonathan Gennick, Jonathan Hassell, Robert Hutchinson, Michelle Lowman, James Cover Designer: Markham, Matthew Moodie, Jeff Olson, Jeffrey Pepper, Anna Ishchenko Douglas Pundick, Ben Renow-Clarke, Dominic Coordinating Editor: Shakeshaft, Gwenan Spearing, Matt Wade, Tom Welsh Christine Ricketts and Jennifer Blackwell

www.it-ebooks.info

For K & J.

—Richard

For C, R & C

—C

www.it-ebooks.info Contents at a Glance

Contents ...... v

Forewords ...... xv

About the Authors ...... xvi

About the Technical Reviewers ...... xvii

Acknowledgments ...... xviii

Introduction ...... xix

Chapter 1: HTML5: Now, Not 2022 ...... 1

Chapter 2: Your First Plunge into HTML5 ...... 19

Chapter 3: New Structural Elements ...... 43

Chapter 4: A Richer Approach to Marking Up Content ...... 89

Chapter 5: Rich Media ...... 141

Chapter 6: Paving the Way for Web Applications ...... 189

Chapter 7: CSS3, Here and Now ...... 231

Chapter 8: Keeping Your Markup Slim Using CSS Selectors ...... 275

Chapter 9: A Layout for Every Occasion ...... 311

Chapter 10: Improving Web ...... 397

Chapter 11: Putting CSS3 Properties to Work ...... 435

Chapter 12: Transforms, Transitions, and ...... 499

Chapter 13: The Future of CSS or, Awesome Stuff That’s Coming ...... 581

Index ...... 591

iv www.it-ebooks.info Contents

Contents at a Glance ...... iv

Forewords ...... xv

About the Authors ...... xvi

About the Technical Reviewers ...... xvii

Acknowledgments ...... xviii

Introduction ...... xix Who is this book for? ...... xix How is this book structured? ...... xix Conventions used in this book ...... xix

Chapter 1: HTML5: Now, Not 2022 ...... 1 Basic tenets ...... 1 A approach ...... 2 The Dao of : embracing uncertainty ...... 4 ...... 6 Crafting your markup ...... 7 How was HTML5 created? ...... 8 Beyond HTML 4… ...... 8 XHTML 1.0 ...... 8 XHTML 2.0 and the backlash ...... 9 HTML5 moving forward! ...... 10 HTML5 design principles ...... 11 Supporting existing content ...... 12 Degrading gracefully ...... 12 Don’t reinvent the wheel ...... 13 Paving the cowpaths ...... 13 Evolution, not revolution ...... 13 A dozen myths about HTML5 ...... 14 1. Browsers don’t support HTML5...... 14 2. OK, most browsers support HTML5, but IE surely doesn’t...... 14 3. HTML5 won’t be finished until 2022...... 14 4. Now I have to relearn everything! ...... 15 5. HTML5 uses presentational elements...... 15 6. HTML5 is a return to ...... 15 7. HTML5 kills accessibility kittens...... 15

v www.it-ebooks.info 8. Flash is dead...... 15 9. HTML5 will break the Web! ...... 15 10. HTML5’s development is controlled by browser vendors...... 15 11. HTML5 includes CSS3, Geolocation, SVG, and every other modern technology under the sun...... 16 12. So when can I start using HTML5? ...... 16 Summary ...... 16 Homework ...... 17 Chapter 1 homework ...... 17 Directed reading ...... 17

Chapter 2: Your First Plunge into HTML5 ...... 19 Homework review ...... 19 Our page ...... 20 84.8% of your markup remains ...... 21 It’s all in the head ...... 22 A more perfect DOCTYPE ...... 23 Declaring languages in HTML5 ...... 23 Character encoding ...... 25 Mr. Memory ...... 25 A “Hello World!” journey ...... 26 “Hello World!” in XHTML1.0 style ...... 26 “Hello World!” in HTML4 style ...... 27 “Hello World!” in HTML5 “loose” style ...... 27 “Hello World!” in HTML5 “strict” style ...... 28 Supporting HTML5 cross-browser ...... 29 How do browsers deal with unknown elements? ...... 29 Meet the shiv ...... 31 IE print protector ...... 32 Declaring block-level elements ...... 32 An HTML5 boilerplate page ...... 33 No more type attribute ...... 33 Polyfills and alternatives ...... 34 Validation ...... 35 HTML5 ...... 35 HTML Lint ...... 37 Revisiting Miss Baker ...... 38 Summary ...... 40 Homework ...... 41

Chapter 3: New Structural Elements ...... 43 Workflow practices, evolving? ...... 44 A new semantic dawn ...... 45 vi www.it-ebooks.info Structural building blocks:

,
, and
...... 49 The difference between
,
, and
...... 49 Which one to choose? ...... 50 Basic structures using these elements ...... 51 Headings:
,
, and

, plus