The HTML5 Developer's Collection
Total Page:16
File Type:pdf, Size:1020Kb
The HTML5 Developer’s Collection Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Cape Town • Sydney • Tokyo • Singapore • Mexico City Note from the Publisher The HTML5 Developer’s Collection includes two recently published HTML5 application development eBooks: • Sams Teach Yourself HTML5 Mobile Application Development in 24 Hours • HTML5 Developer’s Cookbook Sams Teach Yourself HTML5 Mobile Application Development in 24 Hours is an excellent way to get up-to-speed quickly on the ins and outs of HTML5 mobile app development. HTML5 Developer’s Cookbook contains many invaluable “recipes” that working developers will want to use in their production-level code. To simplify access, we’ve appended “A” to pages of Sams Teach Yourself HTML5 Mobile Application Development in 24 Hours and “B” to pages of HTML5 Developer’s Cookbook. This enabled us to produce a single, comprehensive table of contents and dedicated indexes so that you can easily link to the topics you want.We hope you find this collec- tion useful! —The editorial and production teams at Sams Publishing and Addison-Wesley Professional 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 the pub- lisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact: U.S. Corporate and Government Sales (800) 382-3419 [email protected] For sales outside the United States, please contact: International Sales [email protected] Visit us on the Web: informit.com/aw Copyright © 2012 Pearson Education, Inc. All rights reserved. Printed in the United States of America.This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibit- ed reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise.To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax your request to (201) 236-3290. ISBN-13: 978-0-13-292860-1 ISBN-10: 0-13-292860-4 Table of Contents SAMS TEACH YOURSELF HTML5 MOBILE APPLICATION DEVELOPMENT IN 24 HOURS Part I Building Web Pages and Applications with the Open Web Standard 1 Improving Mobile Web Application Development with HTML5 . .1A Understanding How We Got to HTML5 . .1A Learning What’s Different with HTML5 . .3A Defining Web Applications . .4A Using the Open Web Standard . .4A Using HTML5 with iOS and Android Devices . .6A Writing Mobile Websites . .7A Summary . .11A Q&A . .12A Workshop . .13A 2 New HTML5 Tags and Attributes with Mobile Development . .15A The New HTML5 Tags . .15A The New HTML5 Attributes . .24A Changes to HTML 4 Tags and Attributes . .25A Changes to HTML Syntax in HTML5 . .27A Mobile Support of HTML5 Tags and Attributes . .28A Benefits of HTML5 for Mobile Web Development . .29A Summary . .30A Q&A . .30A Workshop . .31A 3 Styling Mobile Pages with CSS3 . .33A Quick Introduction to CSS . .33A What CSS3 Adds to the Party . .42A Using CSS3 on Mobile Devices . .46A Summary . .46A Q&A . .46A Workshop . .47A 4 Detecting Mobile Devices and HTML5 Support .49A Choosing What HTML5 Elements to Use . .50A Android and iOS Support for HTML5 . .50A Detecting HTML5 Functions . .52A Degrading Gracefully . .58A Using CSS3 Media Queries to Detect Mobile Browsers . .60A Testing Your Applications . .63A Summary . .64A Q&A . .64A Workshop . .65A 5 JavaScript and HTML5 Web Applications . .67A What is JavaScript? . .67A What is jQuery? . .72A Using jQuery Mobile . .79A Summary . .82A Q&A . .82A Workshop . .83A 6 Building a Mobile Web Application . .85A Building a Site that Works on All Devices . .85A Deciding on What Type of Application You Want . 86A Building the Application in HTML . .89A Using CSS to Make the HTML Look Good . .91A Adding Mobile Meta Tags for More Effective HTML5 Pages . .96A Optimizing Your Site for Mobile . .99A Summary . .102A Q&A . .102A Workshop . .103A vi Contents 7 Upgrading a Site to HTML5 . .105A Deciding When and How to Upgrade from HTML 4 . .105A HTML5 Features that Work Right Now . .111A The State of HTML5 Browser Support . 112A Adding HTML5 Features as Extras on Your Site . .113A HTML5 Features that Turn Your Site into a Killer Mobile Application . .115A Summary . .116A Q&A . .116A Workshop . .118A 8 Converting Web Apps to Mobile . .119A Choosing a Web Editor . .120A Testing Your Application . .121A Evaluating Your Content . .123A Changing the Visual Design for Mobile . .124A Checking for HTML5 and CSS3 . .130A Supporting Multiple Devices . .132A Evaluating Finished Apps on Other Devices . .133A Getting an Application to Work on Older Browsers . .134A Summary . .138A Q&A . .139A Workshop . .139A Part II Learning the HTML5 Essentials 9 Adding Meaning with HTML5 Sectioning and Semantic Elements . .141A What Are Sectioning Elements? . 141A Using the New Sectioning Elements . .142A Marking Up HTML Semantically . .154A Summary . .159A Q&A . .159A Workshop . .160A Contents vii 10 Drawing with the HTML5 Canvas Element . .163A Using the Canvas Element . .163A Drawing Shapes on the <Canvas> Element . .165A Writing Fonts and Text on the Canvas . .177A Displaying Images . .179A How Is Canvas Different from SVG or Flash . .182A Summary . .183A Q&A . .184A Workshop . .185A 11 Fonts and Typography in HTML5 . .187A Defining the Elements of Typography . .187A Using Proper Typographical Entities . .196A Understanding Web Open Font Format (WOFF) . .198A Summary . .202A Q&A . .202A Workshop . .203A 12 Audio and Video in HTML5 . .205A Why Use HTML5 for Audio and Video vs. Flash . .205A Choosing Video Formats for the Best Compatibility . .207A Choosing Audio Codecs for the Widest Support . .208A The New HTML5 Media Elements . .210A Useful Attributes to Extend Your Media . .212A Creating Fallback Options for Internet Explorer . .216A Creating Custom Controls with API Methods . .217A Summary . .219A Q&A . .220A Workshop . .220A 13 HTML5 Forms . .223A New Usability Features in HTML5 Forms . .223A HTML5 Input Types . .228A Other New Form Elements . .235A Form Validation . .237A Summary . .241A viii Contents Q&A . .242A Workshop . .242A 14 Editing Content and User Interaction with HTML5 . .245A The New contenteditable Attribute . .245A The execCommand Method . .247A Adding Spellcheck to Web Pages . .251A Hiding Elements . .252A Additional UI Components of HTML5 . .253A Browser Support of UI and Editing Features . .255A Summary . .257A Q&A . .258A Workshop . .258A 15 Microformats and Microdata . .261A Using Microformats . ..