Bulletproof Web Design
Total Page:16
File Type:pdf, Size:1020Kb
Bulletproof Web Design Web Bulletproof Bulletproof Improving flexibility and protecting against Web worst-case scenarios with HTML5 and CSS3 Design THIRD EDITION No matter how visually appealing or content packed a web site may be, Dan Cederholm is if it doesn’t reach the widest possible audience, it isn’t truly successful. a designer, author, speaker, husband, Bulletproof In Bulletproof Web Design, Third Edition, bestselling author and web and father living designer Dan Cederholm outlines standards-based strategies for building in Massachusetts. designs that can accommodate the myriad ways users choose to view He’s the Founder and Principal of SimpleBits LLC, a the content. Each chapter starts out with an example of an unbulletproof tiny design studio. A recognized worst-case scenarios with HTML5 and CSS3 with HTML5 scenarios worst-case against and protecting flexibility Improving approach—one that employs traditional HTML-based techniques—which expert in the field of standards- Dan deconstructs, pointing out its limitations. He then gives the example based web design, Dan has worked Web with YouTube, Microsoft, Google, a makeover using HTML and CSS, so you can learn to replace bloated code MTV, ESPN, Electronic Arts, Blogger, with lean markup and CSS for fast-loading sites that are accessible to all Fast Company, Inc. Magazine, and users. Finally, he assembles all of the page components discussed in prior others. Dan is co-founder and designer of Dribbble, a vibrant chapters into a single-page template. This fully revised and updated third community for sharing screenshots of your work. His other bestselling Design edition introduces CSS3 and HTML5 methods and features redesigned case studies including new responsive design examples. books include CSS3 For Web Designers and Handcrafted CSS: Size text using keywords, percentages, and ems to allow more user control. More Bulletproof Web Design. He’s currently an aspiring clawhammer Improving flexibility and protecting Plan for vertical expansion of horizontal page components. banjoist and occasionally wears a baseball cap. Use floats to achieve grid-like results. against worst-case scenarios E THIR D Ensure that content is still readable in the absence of images or CSS. I T ION D Strip the presentation from data tables, and rebuild with CSS. with HTML5 and CSS3 Progressively enhance your designs using HTML5 and CSS3. Cederholm THIRD EDITION Visit the companion website at simplebits.com/bulletproof to download finished files, additional resources, and book updates. Dan Cederholm US $44.99 CAN $46.99 ISBN-13: 978-0-321-80835-6 ISBN-10: 0-321-80835-5 www.newriders.com 54499 Book Level: Intermediate / Advanced Computer Book Shelf Category: Web Design / Web Development / Scripting 9 780321 808356 Covers: CSS and HTML scripting on Windows, Mac OS, and Unix and Dan Cederholm Design: Mimi Heft Cover Bulletproof Web Design Improving flexibility and protecting against worst-case scenarios with HTML5 and CSS3 Third Edition Dan Cederholm Bulletproof Web Design: Improving flexibility and protecting against worst-case scenarios with HTML5 and CSS3, Third Edition Dan Cederholm New Riders 1249 Eighth Street Berkeley, CA 94710 510/524-2178 510/524-2221 (fax) Find us on the web at: www.newriders.com To report errors, please send a note to: [email protected] New Riders is an imprint of Peachpit, a division of Pearson Education. Copyright © 2012 by Daniel Cederholm Editor: Rebecca Gulick Copy Editor: Liz Merfeld Technical Reviewer: Patrick H. Lauke Proofreader: Patricia Pane Production Coordinator and Compositor: Danielle Foster Indexer: Valerie Haynes Perry Cover Designers: Mimi Heft and Dan Cederholm Interior Designers: Charlene Will and Maureen Forys Notice of Rights All rights reserved. No part of this book may be reproduced or transmitted in any form by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. For information on getting permission for reprints and excerpts, contact [email protected]. Notice of Liability The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of the book, neither the author nor Peachpit shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the instructions contained in this book or by the computer software and hardware products described in it. Trademarks 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 Peachpit was aware of a trademark claim, the designations appear as requested by the owner of the trademark. All other product names and services identified throughout this book are used in editorial fashion only and for the benefit of such companies with no intention of infringement of the trademark. No such use, or the use of any trade name, is intended to convey endorsement or other affiliation with this book. ISBN-13: 978-0-321-80835-6 ISBN-10: 0-321-80835-5 9 8 7 6 5 4 3 2 1 Printed and bound in the United States of America For Jack & Tenley. Acknowledgments To Michael Nolan for connecting me with New Riders as well as helping me solidify the concept of the book early on. Similarly, big thanks also go to the late, great Marjorie Baer for her guidance at the beginning of the project. To Dave Roberts for stealing second. To everyone at Peachpit who was involved in this book in some way, but especially Rebecca Gulick for steering the entire project, making the entire process as smooth as possible. To Ethan Marcotte for being an excellent technical editor on the first edition. It was great to work with Ethan on this, and his comments and insight were invaluable. Thanks also to Virginia DeBolt for tech-editing the second edition and Patrick H. Lauke for tech-editing the third edition. To my colleagues who continue to provide inspiration, sharing their tech- niques and knowledge, on and off line. This book wouldn’t have been written if it weren’t for the previous work of the following (as well as many more who I’m forgetting to mention here): John Allsopp, Dan Benjamin, Holly Bergevin, Douglas Bowman, Andy Budd, Tantek Çelik, Joe Clark, Andy Clarke, Mike Davidson, Todd Dominey, Jason Fried, John Gallant, Patrick Griffiths, Jon Hicks, Molly Holzschlag, Shaun Inman, Ryan Irelan, Richard Ishida, Roger Johansson, Jeremy Keith, Ian Lloyd, Drew McLellan, Eric Meyer, Cameron Moll, Matt Mullenweg, Mark Newhouse, Dunstan Orchard, Veerle Pieters, D. Keith Robinson, Richard Rutter, Jason Santa Maria, Christopher Schmitt, Dave Shea, Ryan Sims, Greg Storey, Jeffrey Veen, Josh Williams, and Jeffrey Zeldman. Special thanks to Jon Hicks for creating the original 3D CSS Box Model Illustration (www.hicksdesign.co.uk/3dboxmodel/), which inspired those found in the book. To the readers and clients of SimpleBits, you’ve made it possible for me to work on things I love. To the Greater Beverly Adult Dodgeball league, for providing a necessary escape every Tuesday evening at 7:30. To my always amazingly supportive parents, my brother Matt and his family, and the rest of my extended family and friends. And as always, to my partner in crime, Kerry, for being the rock star wife that she is. Lastly, thank you for reading. Contents Introduction. xiii CHAPTERONE Flexible Text. .1 Size text using keywords and percentages or ems to allow user control and maximum flexibility.. 2 A Common Approach . 3 Why it’s not bulletproof. 4 Weighing Our Options . 6 Length units . 6 Relative-size keywords . 6 Percentages. 7 Absolute-size keywords . 7 A Bulletproof Approach. 8 Keywords explained. 8 Letting go of “pixel precision” . 9 Why It’s Bulletproof . 10 A Flexible Base. Now What? . 10 Set it and forget it . 10 Use percentages to stray from the base. .11 Working with Keywords and Percentages . 15 Setting an in-between keyword base. 15 Be careful when nesting percentages . 17 Experiment with percentage values for consistency. 18 Flexible Text Using Ems . 20 The rem unit . 22 Summary . 23 vi Contents CHAPTERTWO Scalable Navigation. 25 Provide site navigation that scales to any text size or content amount. 26 A Common Approach . 27 Strong tabs. 27 Common rollovers . 28 Why It’s Not Bulletproof . 29 Mountains of code. 29 Inaccessibility issues . 29 Scalability issues . 30 Lack of flexibility . 30 A Bulletproof Approach. 30 Sans style . 31 Two tiny images . 31 Applying style. 32 Float to fix. 33 Making the tabs take shape . 34 Aligning the background images . 35 Adding the bottom border . 37 Hovering swap . 38 Selected state. 38 Why It’s Bulletproof . 39 An Imageless Variation Using CSS3 Gradients . 40 A Variation Using Ems . 44 Additional Examples . 46 Mozilla.org . 46 Slants . 46 ESPN.com Search. 47 Summary . 49 Contents vii CHAPTERTHREE Expandable Rows. .51 Resist specifying height and plan for vertical expansion of horizontal page components. 52 A Common Approach . 53 Why It’s Not Bulletproof . 54 Nonessential graphics. 54 Thinking in fixed height. 55 Code bloat . 55 A Bulletproof Approach. 56 The markup structure . 56 Identifying the pieces . 57 Sans style . 57 Adding background. 58 Positioning the content. 59 Missing background . 60 Adding the details . 62 Four rounded corners . 64 Text and link details. 65 The final step . 67 A fix for IE7 . 69 Why It’s Bulletproof . 70 Separation of structure and design . 70 No more fixed heights . 71 A variation using border-radius . 72 Another Example of Expanding. 74 The markup . 75 Creating the two images . 76 Applying the CSS . 77 Expand-o-matic . 79 Summary . 79 viii Contents CHAPTERFOUR Creative Floating. 81 Use floats to achieve grid-like results.. 82 A Common Approach . 83 Why It’s Not Bulletproof .