SlideShare a Scribd company logo
Visit https://ebookultra.com to download the full version and
explore more ebooks
Beginning CSS Cascading Style Sheets for Web
Design Wrox Beginning Guides 2nd Edition Richard
York
_____ Click the link below to download _____
https://ebookultra.com/download/beginning-css-
cascading-style-sheets-for-web-design-wrox-beginning-
guides-2nd-edition-richard-york/
Explore and download more ebooks at ebookultra.com
Here are some suggested products you might be interested in.
Click the link to download
Beginning JavaScript und CSS development with jQuery 1. ed
Edition Richard York
https://ebookultra.com/download/beginning-javascript-und-css-
development-with-jquery-1-ed-edition-richard-york/
Beginning Visual C 2005 Wrox Beginning Guides 2nd Edition
Karli Watson Christian Nagel Jacob Hammer Pedersen Jon
D. Reid Morgan Skinner Eric White
https://ebookultra.com/download/beginning-visual-c-2005-wrox-
beginning-guides-2nd-edition-karli-watson-christian-nagel-jacob-
hammer-pedersen-jon-d-reid-morgan-skinner-eric-white/
Beginning Joomla Web Site Development Wrox Programmer to
Programmer 1st Edition Cory Webb
https://ebookultra.com/download/beginning-joomla-web-site-development-
wrox-programmer-to-programmer-1st-edition-cory-webb/
Beginning JSP JSF and Tomcat 2nd Edition Java Web
Development Giulio Zambon
https://ebookultra.com/download/beginning-jsp-jsf-and-tomcat-2nd-
edition-java-web-development-giulio-zambon/
Beginning Android Web Apps Development 1st ed. Edition Jon
Westfall
https://ebookultra.com/download/beginning-android-web-apps-
development-1st-ed-edition-jon-westfall/
Beginning ASP NET Web Pages with WebMatrix 1st Edition
Mike Brind
https://ebookultra.com/download/beginning-asp-net-web-pages-with-
webmatrix-1st-edition-mike-brind/
Beginning JSP Jsf and Tomcat Web Development 1st Edition
Giulio Zambon
https://ebookultra.com/download/beginning-jsp-jsf-and-tomcat-web-
development-1st-edition-giulio-zambon/
BEGINNING LUCIFERIAN MAGICK 2nd Edition Michael W. Ford
https://ebookultra.com/download/beginning-luciferian-magick-2nd-
edition-michael-w-ford/
Beginning Bridge Alan Hiron
https://ebookultra.com/download/beginning-bridge-alan-hiron/
Beginning CSS Cascading Style Sheets for Web Design Wrox Beginning Guides 2nd Edition Richard York
Beginning CSS Cascading Style Sheets for Web Design
Wrox Beginning Guides 2nd Edition Richard York
Digital Instant Download
Author(s): Richard York
ISBN(s): 0470096977
Edition: 2
File Details: PDF, 33.97 MB
Year: 2007
Language: english
Beginning CSS Cascading Style Sheets for Web Design Wrox Beginning Guides 2nd Edition Richard York
Beginning
CSS
Cascading Style Sheets for Web Design
Second Edition
Richard York
Beginning CSS Cascading Style Sheets for Web Design Wrox Beginning Guides 2nd Edition Richard York
Beginning
CSS
Second Edition
Beginning CSS Cascading Style Sheets for Web Design Wrox Beginning Guides 2nd Edition Richard York
Beginning
CSS
Cascading Style Sheets for Web Design
Second Edition
Richard York
Beginning CSS: Cascading Style Sheets
for Web Design, Second Edition
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-09697-0
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any
means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections
107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or
authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood
Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be
addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317)
572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REP-
RESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CON-
TENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT
LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CRE-
ATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CON-
TAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE
UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR
OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A
COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE
AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION
OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FUR-
THER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFOR-
MATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE.
FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE
CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.
For general information on our other products and services or to obtain technical support, please contact our Cus-
tomer Care Department within the U.S. at (800) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002.
Library of Congress Cataloging-in-Publication Data
York, Richard, 1978–
Beginning CSS : cascading style sheets for Web design / Richard York. — 2nd ed.
p. cm.
Includes index.
ISBN 978-0-470-09697-0 (paper/website)
1. Web sites—Design. 2. Cascading style sheets. I. Title.
TK5105.888.Y67 2007
006.7—dc22
2007008853
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are
trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other
countries, and may not be used without written permission. All other trademarks are the property of their respec-
tive owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be
available in electronic books.
To my own cousin Ryan Wood
In the words of Ryan’s favorite comedian, Dave Chappelle,
“I’m rich, bitch!”
Rest in peace, brother. We love you and we miss you.
Beginning CSS Cascading Style Sheets for Web Design Wrox Beginning Guides 2nd Edition Richard York
About the Author
Richard York is a web application developer for Trilithic, Inc., a company specializing in test equipment
for the telecommunications industry. He wrote his first book, Beginning CSS: Cascading Style Sheets for
Web Design (Wrox Press), in 2004.
Richard began his web development career taking courses at Indiana University–Purdue University
Indianapolis. Since college, he has continued a self-imposed curriculum, mastering various technologies
used in web development including HTML/XHTML, CSS, JavaScript, PHP, and MySQL. An avid sup-
porter of open source software, he has written an open source webmail application for PHP PEAR and is
currently working on an open source PHP library and framework called Hierophant, which he hopes to
release in 2007.
Richard maintains a personal website at http://www.richard-york.com where you can learn more
about his professional and personal interests.
Credits
Senior Acquisitions Editor
Jim Minatel
Development Editor
Brian MacDonald
Technical Editor
Alexei Gorkov
Technical Reviewers
Robert Searing
Marybeth Fullmer
Copy Editor
Mildred Sanchez
Editorial Manager
Mary Beth Wakefield
Production Manager
Tim Tate
Vice President and Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher
Joseph B. Wikert
Project Coordinator
Heather Kolter
Graphics and Production Specialists
Carrie A. Foster
Denny Hager
Joyce Haughey
Alicia B. South
Ronald Terry
Quality Control Technician
John Greenough
Proofreader
Sossity R. Smith
Indexer
Aptara
Anniversary Logo Design
Richard Pacifico
Contents
Acknowledgments xv
Introduction xvii
Part I: The Basics
Chapter 1: Introducing Cascading Style Sheets 3
Who Creates and Maintains CSS? 4
How the Internet Works 5
How CSS Came to Be 6
Browsers 8
Internet Explorer 8
The Gecko Browsers: Mozilla Firefox, Netscape, Camino 12
Safari 13
Opera 13
Writing CSS 14
Your First CSS-Enabled Document 15
Advantages of Using CSS 21
Summary 22
Chapter 2: The Essentials 25
CSS Rules 25
Selectors 26
Declarations 27
Grouping Selectors 28
CSS Comments 29
Values 31
Keywords 31
Strings 34
Length and Measurement 36
Numbers 45
The URI 51
Including CSS in a Document 52
Including an Embedded Style Sheet 53
Linking to External Style Sheets 54
x
Contents
Importing Style Sheets 56
Inline Styles 56
Summary 57
Exercises 58
Chapter 3: Selectors 59
Class and ID Selectors 60
Class Selectors 60
ID Selectors 63
The Universal Selector 68
Descendant Selectors 71
Direct Child Selectors 75
Next Sibling Selector 79
Attribute Selectors 82
Selection Based on the Value of an Attribute 83
Attribute Substring Selectors 87
Pseudo-Elements :first-letter and :first-line 93
Pseudo-Classes 97
Dynamic Pseudo-Classes 97
The first-child Structural Pseudo-Class 102
Summary 106
Exercises 106
Chapter 4: The Cascade and Inheritance 109
The Cascade 109
Calculating the Specificity of a Selector 112
!important Rules 118
Inheritance 121
Summary 125
Exercises 126
Part II: Properties
Chapter 5: Text Manipulation 131
The letter-spacing Property 132
The word-spacing Property 137
Indenting Paragraph Text Using text-indent 141
Aligning Text with the text-align Property 147
The text-decoration Property 150
xi
Contents
The text-transform Property 155
The white-space Property 158
Summary 164
Exercises 164
Chapter 6: Fonts 167
Specifying Fonts with the font-family Property 167
Font Families 169
Generic Font Families 171
The font-style Property 175
The font-variant Property 181
The font-weight Property 183
The font-size Property 185
Absolute Font Sizes 185
Relative Font Sizes 187
Percentage Font Sizes 189
The font Shorthand Property 194
The font Properties 194
System Fonts 200
Summary 203
Exercises 203
Chapter 7: The Box Model 205
Overview 205
Margin 208
Margin Property with Four Values 209
Margin Property with Three Values 211
Margin Property with Two Values 213
Margin Property with One Value 214
Margin Collapsing 216
Horizontally Aligning Elements with the Margin Property 220
Borders 230
border-width 230
border-style 233
border-color 236
Border Shorthand Properties 236
Padding 242
Setting Dimensions 244
width 245
height 247
xii
Contents
Auto Values for width and height 249
Percentage Measurements 255
Quirks Mode width and height in Internet Explorer 256
Minimum and Maximum Dimensions 259
Overflowing Content 271
CSS 3 overflow-x and overflow-y 273
Summary 273
Exercises 274
Chapter 8: CSS Buoyancy: Floating and Vertical Alignment 277
The float Property 277
Floating Box Model 282
The clear Property 293
Float Bugs in IE 6 298
The Peek-A-Boo Bug 298
The Guillotine Bug 300
The Three-Pixel Jog 303
The Double-Margin Bug 305
The vertical-align Property 306
Subscript and Superscript Text 307
The top, middle, and bottom Keywords 308
The text-top and text-bottom Keywords 310
Percentage and Length Value 311
Vertically Aligning the Contents of Table Cells 312
Summary 318
Exercises 319
Chapter 9: List Properties 321
The list-style-type Property 321
Styling Unordered Lists 322
Styling Ordered Lists 324
The list-style-image Property 330
The list-style-position Property 331
The list-style shorthand Property 333
Summary 337
Exercises 337
Chapter 10: Backgrounds 339
The background-color Property 339
The background-image Property 343
xiii
Contents
The background-repeat Property 346
The background-position Property 350
Mixing Different Kinds of Position Values 352
Tiling and Position 354
The background-attachment Property 360
The background shorthand Property 365
Summary 369
Exercises 370
Chapter 11: Positioning 371
Introduction to Positioning 372
Absolute Positioning 372
Relative Positioning 381
Fixed Positioning 389
The z-axis and the z-index Property 428
The z-index Property with an Integer Value 430
Layering Nested Elements 433
The IE 6/IE 7 z-index Bug 434
Other Ways to Apply Positioning 441
Horizontally and Vertically Aligning Positioned Content 441
Multicolumn Layout 444
Summary 452
Exercises 452
Chapter 12: Tables 455
Optional Table Elements 455
Table Captions and the caption-side Property 457
Table Columns 459
Controlling Table Width with the table-layout Property 469
Removing Cell Spacing with the border-collapse Property 478
The border-spacing Property 479
Summary 484
Exercises 484
Part III: Advanced CSS and Alternative Media
Chapter 13: Styling for Print 487
Applying Styles Based on Media 487
The @media Rule 491
xiv
Contents
Controlling Page Breaks 497
Summary 500
Exercises 500
Chapter 14: XML 501
Crash Course in XML 502
Creating an XML Schema 505
The XML Declaration 510
The display Property 514
Styling Inline Elements with display: inline 515
Styling Block Elements with display: block 516
Styling List Items with display: list-item 517
Table Display Values 523
Other Display Values 534
Summary 535
Exercises 536
Chapter 15: The Cursor Property 537
Cursor Compatibility 538
Custom Cursors 540
Additional CSS Resources 542
Beginning CSS, Second Edition Online 542
Summary 542
Exercises 543
Appendix A: Answers to Exercises 545
Appendix B: CSS Reference 563
Appendix C: CSS Colors 593
Appendix D: Browser Rendering Modes 607
Index 611
Acknowledgments
As I wrote this book, so much has happened. Through the course of about 10 months, many people have
been instrumental in making this happen, either directly or indirectly. I owe my success to all of you.
I’d like to thank my boss at Trilithic, Karalee Slayton. I appreciate all the encouragement, understanding,
and help you’ve given me along the way. And I have just one more thing to say, shhhhhhhhht!
I’d like to thank Marybeth Fulmer, my colleague and friend. Thanks for always being willing to listen
and help.
I want to thank again, Jim Minatel from Wiley, for giving me the opportunity to write for Wrox again.
Thanks for listening to all my wild ideas, and for being willing to take the risks on all the new things
we’ve done with this book.
A great big thanks to Brian MacDonald, my development editor. I appreciate your patience and under-
standing, and you’ve been truly great to work with. This book owes much to your meticulous attention
to every detail.
I’d also like to thank my tech editor, Alexei Gorkov. Your incredible attention to detail has been a
tremendous asset on this project.
I want to thank my friends and family, who have been very supportive through some very difficult
times: my aunt, Brenda; my uncle, Johnny; my cousins, Amanda, Kimberly, and Amy. Be strong, but
don’t be afraid to talk about your son, your brother, and my cousin, Ryan. Let’s always keep in mind the
good times, and the good things that happened, and not dwell on the bad. We can’t change what hap-
pened, but we can keep his memory alive. Here’s to you. Here’s to me...
I want to thank Richelle Brown. You are a truly awesomely good friend. As we enter the year of our
Paul, 5AP, I’m very proud of all of your accomplishments as of late. Egg-cellent! Keep your nose up.
Let’s find another Paul McCartney show so we can reset the Paul clock.
Thanks to my parents, John and Tammy. Thanks for your help and support. I love you.
And finally, I want to thank my best friend, Lisa Ratliff. I’m very sorry that I haven’t been there for you.
I should have been. There are so many things that I should have said and done, but didn’t. I regret that
we grew apart. Thanks for listening and thanks for understanding. Despite our ups and downs, you
should know that I will always be here for you, and I will always love you. Snotface.
Beginning CSS Cascading Style Sheets for Web Design Wrox Beginning Guides 2nd Edition Richard York
Introduction
Cascading style sheets (CSS) are the modern standard for website presentation. When combined with a
structural markup language such as HTML, XHTML, or XML (though not limited to these), cascading
style sheets provide Internet browsers with the information that enables them to present all the visual
aspects of a web document. Cascading style sheets apply things such as borders, spacing between para-
graphs, headings or images, control of font faces or font colors, background colors and images, textual
effects such as underlined or strike-through text, layering, positioning, and a number of other presenta-
tional effects. CSS controls the presentational aspects of a web page’s design, whereas HTML, XHTML,
or XML controls the structure of a web page, which means little more than determining that certain text
is a heading, other text is a paragraph, still other text is a list of hyperlinks, and so on. CSS provides
enhanced and precise visual rendering; markup languages such as HTML provide meaning and structure.
Beginning CSS: Cascading Style Sheets for Web Design, Second Edition covers all the details required to com-
bine CSS with HTML, XHTML, or XML to create rich, aesthetically powerful designs. Throughout the
book, I focus on combining CSS with XHTML specifically because XHTML is the standard hailed by
Internet standards bodies as the successor to HTML and the present and future of website design. CSS
and XHTML allow a web document to be presented with less code, resulting in a significantly smaller
file size and greatly increased ease of maintenance. CSS also enables the presentation of a web document
to be centralized, which allows for the look and feel of an entire website to be written and centralized in
one or a few simple documents, which makes updating a website a breeze. With only a few simple edits
to a single document, the look and feel of an entire website can be completely changed.
By using modern standards like CSS and XHTML, you can drastically reduce the cost of building and
maintaining a website when compared to legacy HTML-only pages. You can also greatly reduce the
amount of physical bandwidth and hard disk space required, resulting in immediate long-term benefits
for any website.
In this book, I also discuss how to style XML documents with CSS — XML being a more advanced
markup language with multipurpose applications. XML will play an increasingly larger role in the pro-
duction of XHTML documents in the future.
What’s New in the Second Edition
This second edition of Beginning CSS features a near-complete overhaul of the content from the first edi-
tion. I listened to what my readers had to say about the first edition and took that feedback to create the
most comprehensive introduction on CSS available on the market. Throughout this book, you see CSS
broken down into simple examples that focus on a single concept at a time. This allows you to better
understand how and why something works, since you aren’t presented with a lot of irrelevant code, and
you can better see the bits and pieces that come together that make something work. While these exam-
ples may not be particularly pretty, they are extremely valuable learning tools that will help you master
cascading style sheets.
xviii
Introduction
To enhance the learning experience, I’ve presented most of the source code examples in syntax-colored
code, a special feature in this book. Syntax coloring is a feature that you commonly see in fancy develop-
ment software, such as Zend Studio (used to develop PHP), or Microsoft’s Visual Studio (used to
develop ASP, C#, and so on), and other software used by professional programmers every day. Syntax
coloring is used in these software suites to make programming easier and more intuitive, and I think
that it offers tremendous benefits in teaching as well. It allows you to see what the different bits and
pieces are in source code, since each of the different bits and pieces has a different coloring to identify
its purpose. It helps you to distinguish the building blocks of code more easily, and if you use similar
development software to write your CSS and HTML documents, you’ll also find that you make fewer
mistakes and typos, since syntax coloring also helps you to write code that is more bug free.
I’ve also added annotations to many of the source code examples to highlight important, not-to-be-
forgotten bits of information, and to visually point out concepts that are discussed in the surrounding text.
This edition also features every screenshot from a browser in color, a first for Wrox. Presenting the
browser screenshots in color makes it easier for you to compare your results with what you see in the
book.
This book also approaches CSS development from a browser-neutral point of view, and provides all the
information that you need to get a good healthy start on professional cross-browser, cross-platform web-
site design with IE 6, IE 7, Firefox 2, Opera 9, and Safari 2, which will allow you to reach over 99 percent
of the web browsing public.
You also see comprehensive coverage of bugs, and workarounds for the IE 6 and IE 7 web browsers.
Long a thorn in the side of CSS developers, making CSS work in IE 6 can be quite a chore without
detailed knowledge of its quirks and shortcomings. I have covered throughout this book many of the
hacks and nonstandard workarounds that you may need to develop compatible CSS content in IE 6. IE 7
features many great improvements to CSS support, and though they are much fewer than its predeces-
sor, you still need a few tricks to make your web page shine in Microsoft’s latest browser. I have covered
the workarounds that you’ll need to make your pages work just as well in IE 7 as they do in all the other
popular browsers. In addition, you’ll find the quick reference in Appendix B updated to reflect all of
IE 7’s new CSS support.
Along with better coverage of Internet Explorer, I’ve also greatly improved coverage of Mac OS X
browsers, Safari, Firefox, and Opera. You’ll see that Mac browsers are equally represented among their
Windows brethren.
I had so much new content that I’ve even written an additional chapter that will appear online, on the
Wrox website, which you’ll be able to download for free. In this chapter I discuss additional workarounds
for IE 6, and walk you through putting all of the knowledge that you’ve learned throughout the book
together in a real-life web page.
You can visit the book’s web page at:
http://www.wrox.com/go/beginning_css2e
The following sections tell you what Beginning CSS: Cascading Style Sheets for Web Design, Second Edition
covers, whom this book is intended for, how it is structured, what equipment you need to use it, where
you can go if you have a problem or question, and the conventions used in writing it.
xix
Introduction
Whom Is This Book For?
This book’s primary audience is anyone seeking to learn how to use cascading style sheets to present
web documents. Because cascading style sheets are used to control the presentational layout of a web
document, people from backgrounds in art, graphic design, or those who prepare print layouts for pub-
lishing will feel at home using CSS. Regardless of your background, CSS is a simple and powerful lan-
guage designed so that anyone can understand and use it.
To get the most out of this book, you need some experience with markup languages like HTML or
XHTML. If you are completely new to website design and development, I recommend you begin learn-
ing web programming with Jon Duckett’s Beginning Web Programming with HTML, XHTML, and CSS.
Jon Duckett’s book provides a complete overview of website development and design for the complete
beginner, whereas Beginning CSS: Cascading Style Sheets for Web Design, Second Edition focuses specifically
on the role of CSS in website design.
Throughout this book, I present all of the material you need to become comfortable with writing CSS
from scratch.
What Does This Book Cover?
This book covers portions of the CSS Level 1, 2, 2.1, and 3 specifications. These specifications are
created by an independent, not-for-profit Internet standards organization called the World Wide Web
Consortium (W3C) that plans and defines how Internet documents work. The majority of the book is
written using what is defined in the CSS Level 2.1 specification.
This book leads you through how to write CSS so that it is compatible with all of the most popular web
browsers. I have focused on all of the following popular browsers:
❑ Microsoft Internet Explorer 6 for Windows
❑ Windows Internet Explorer 7 for Windows XP Service Pack 2, Windows Server 2003, Windows
XP Professional 64 bit, and Windows Vista
❑ Safari 2 for Mac OS X 10.4 (Tiger)
❑ Mozilla Firefox 2 for Mac OS X, Windows, and Linux
❑ Opera 9 for Mac OS X, Windows, and Linux
The preceding browsers make up over 99 percent of the web browser market share at the time of this
writing. For your convenience, this book also includes an integrated CSS feature reference throughout
the book, as well as notes on browser compatibility. A CSS reference is also included in Appendix B.
How This Book Is Structured
This book is divided into three parts. The following explains each of these three parts in detail, and what
each chapter covers.
xx
Introduction
Part I: The Basics
Throughout Chapters 1 through 4 you learn the founding principles of CSS-based web design.
❑ Chapter 1, “Introducing Cascading Style Sheets”: In this first chapter, I talk about what CSS is,
why it exists, who created it, where it is maintained, and how it has evolved. I also discuss some
of the basic differences among the various CSS specifications—CSS Level 1, CSS Level 2, CSS
Level 2.1, and CSS Level 3—and how these specifications define what CSS is. You also learn
more about each of the most popular browsers in use today, how to obtain them, and write your
first CSS-enabled document. I also show you how to install Internet Explorer 6 and Internet
Explorer 7 side-by-side on the same computer for testing.
❑ Chapter 2, “The Essentials”: This chapter introduces the basics of CSS. Now that you have seen
an example CSS document, this chapter introduces CSS rules and how selectors and declarations
are combined to create rules. I demonstrate the various methods used to include CSS in a docu-
ment. I explain how keywords are used in CSS to create predefined behavior, and how strings
are used in CSS to refer to font names in a style sheet. I present the various units of measure-
ment that CSS supports. Finally, I talk about the different ways of specifying color.
❑ Chapter 3, “Selectors”: Chapter 2 introduced the concept of selectors. In Chapter 3 I talk about
complex selectors, and how you apply style to a portion of a document based on its context
within the document or user-initiated events.
❑ Chapter 4, “The Cascade and Inheritance”: In Chapter 4, you learn about how to override
styles, how precedence works in a style sheet, and how some styles can be considered more
important than others, concepts that come together to define the cascade in cascading style sheets.
You also learn how once you set some styles in a document, those styles can be inherited to
other parts of a document depending on the context in which they are applied.
Part II: Properties
Throughout Chapters 5 through 12, you learn about properties that are used to manipulate the presenta-
tion of a document.
❑ Chapter 5, “Text Manipulation”: In Chapter 5, I present the various properties that CSS pro-
vides for text manipulation. These properties provide effects such as controlling the amount of
space between the letters of words, controlling the amount of space between the words of a
paragraph, controlling text alignment, underlining, overlining, or strike-through text. I also
show how to control the case of text by making text all lowercase, uppercase, or capitalized.
❑ Chapter 6, “Fonts”: After you have seen the properties that CSS provides for text manipulation
in Chapter 5, Chapter 6 presents the CSS properties you can use to manipulate the presentation
of fonts. These effects include applying bold text, setting a font face, setting the font size, setting
an italic font, as well as learning to use a property that enables you to specify all CSS’s font
effects in one single property.
❑ Chapter 7, “The Box Model”: Chapter 7 elaborates on a design concept fundamental to CSS
design: The Box Model. You learn how the box model plays an important role in determining
layout dimensions. Using the margin, border, padding, width, and height properties, you can
control how much space elements within a document occupy, how much space separates them,
whether there are borders around them, whether scroll bars should be included. I also discuss a
xxi
Introduction
CSS phenomenon known as margin collapsing, which is what happens when top or bottom
margins come into direct contact with other top or bottom margins in a web document.
❑ Chapter 8, “CSS Buoyancy: Floating and Vertical Alignment”: In Chapter 8, I discuss float
and clear, two properties used to control the flow of layout in a web document and often used
to flow text beside images. I also discuss the vertical-align property, which is used to create
effects like subscript or superscript text, as well as to control vertical alignment in table cells.
❑ Chapter 9, “List Properties”: In this chapter, I look at the properties CSS provides to control pre-
sentation of ordered and unordered lists. This discussion includes the options CSS provides for
predefined list markers, custom list markers, and the position of list markers.
❑ Chapter 10, “Backgrounds”: In Chapter 10, I present the properties CSS provides to control
backgrounds in a web page. This includes properties that set a background color or background
image, as well as those that control the position of a background, the tiling of a background, and
whether a background remains fixed in place as a web page is scrolled or remains static. Finally,
the chapter shows you how to use a property that combines all these individual effects into a
single property.
❑ Chapter 11, “Positioning”: I discuss four different types of positioning: static, relative, absolute,
and fixed. You use positioning primarily to layer portions of a document. I also describe some of
the practical uses for positioning, such as creating a multicolumn layout.
❑ Chapter 12, “Tables”: In Chapter 12, I present the different properties that CSS provides for
styling (X)HTML tables. The properties presented in this chapter let you control the spacing
between the cells of a table, the placement of the table caption, and whether empty cells are ren-
dered. I also look in detail at the available tags and options that (X)HTML provides for structur-
ing tabular data.
Part III: Advanced CSS and Alternative Media
Throughout Chapters 13, 14, and 15 you learn about how to use CSS to make documents for printing,
and another kind of document altogether, XML.
❑ Chapter 13, “Styling for Print”: In this chapter, I discuss what steps to take to use CSS to pro-
vide alternative style sheets to create a printer-friendly version of a web document.
❑ Chapter 14, “XML”: In this chapter, I show how you can use CSS to style XML content. This
chapter focuses specifically on the CSS display property and how you use this property to
change the behavior of tags in an XML or HTML/XHTML document.
❑ Chapter 15, “The Cursor Property”: In this chapter, I show you how you can change the user’s
mouse cursor using CSS, how you can customize the mouse cursor, and what browsers support
which cursor features.
❑ Chapter 16, “Dean Edwards’s ‘IE7’”: In this chapter I talk about one alternative to many of the
hacks and workarounds that you need for IE6. I talk about how to install an HTTP server for your
website, and how to install and use Dean Edwards’s “IE7” JavaScript, which is a collection of IE6
hacks and workarounds designed to make “IE6” feature compatible with its successor. This chap-
ter is available online only, on the Wrox website at www.wrox.com/go/beginning_css2e.
❑ Appendixes: Appendix A contains the answers to chapter exercises. Appendix B, “CSS
Reference,” provides a place for you to look up CSS features and browser compatibility on
xxii
Introduction
the fly. Appendix C, “CSS Colors,” provides a reference of CSS named colors. Appendix D,
“Browser Rendering Modes,” provides a reference for the browser rendering modes invoked
by the presence or absence of a Document Type Declaration (discussed in Chapter 7).
What Do You Need to Use This Book?
To make use of the examples in this book, you need the following:
❑ Several Internet browsers to test your web pages
❑ Text-editing software
Designing content for websites requires being able to reach more than one type of audience. Some of
your audience may be using different operating systems or different browsers other than those you have
installed on your computer. This book focuses on the most popular browsers available at the time of this
writing.
I discuss how to obtain and install each of these browsers in greater detail in Chapter 1. The examples in
this book also require that web page source code be composed using text-editing software. Chapter 1
also discusses a few different options for the text-editing software available on Windows or Macintosh
operating systems.
Conventions
To help you get the most from the text and keep track of what’s happening, I’ve used a number of con-
ventions throughout the book:
Tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.
As for styles in the text:
❑ I highlight important words when I introduce them.
❑ I show keyboard strokes like this: Ctrl+A.
❑ I show URLs and code within the text in a special monofont typeface, like this: persistence
.properties.
❑ I present code in the following two ways:
In code examples, I highlight new and important code with a gray background.
The gray highlighting is not used for code that’s less important in the present
context, or has been shown before.
Boxes like this one hold important, not-to-be-forgotten information that is directly
relevant to the surrounding text.
xxiii
Introduction
Source Code
As you work through the examples in this book, you may choose either to type the code yourself or use
the source code files that accompany the book. All the source code used in this book is available for
download at www.wrox.com/go/beginning_css2e. When you arrive at the site, simply click the
Download Code link on the book’s detail page to obtain all the source code for the book.
Because many books have similar titles, you may find it easiest to search by ISBN; this book’s ISBN is
978-0-470-09697-0.
After you download the code, just decompress it with your favorite compression tool. Alternatively, you
can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to
see the code available for this book and all other Wrox books.
Errata
We make every effort to ensure that there are no errors in the text or in the code. However, no one is per-
fect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece
of code, we would be very grateful for your feedback. By sending in errata you may save another reader
hours of frustration; at the same time, you will be helping us provide even higher quality information.
To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one
of the title lists. Then, on the book details page, click the Book Errata link. On this page, you can view all
errata that has been submitted for this book and posted by Wrox editors. A complete book list including
links to each book’s errata is also available at www.wrox.com/misc-pages/booklist.shtml.
If you don’t spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport
.shtml and complete the form there to send us the error you have found. We’ll check the information
and, if appropriate, post a message to the book’s errata page and fix the problem in subsequent editions
of the book.
p2p.wrox.com
For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a web-based sys-
tem for you to post messages relating to Wrox books and related technologies and interact with other
readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of
your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts,
and your fellow readers are present on these forums.
At http://p2p.wrox.com you will find a number of different forums that will help you not only as
you read this book, but also as you develop your own applications. To join the forums, just follow these
steps:
1. Go to p2p.wrox.com and click the Register link.
2. Read the terms of use and click Agree.
xxiv
Introduction
3. Complete the required information to join as well as any optional information you wish to pro-
vide and click Submit.
4. You will receive an e-mail with information describing how to verify your account and com-
plete the joining process.
You can read messages in the forums without joining P2P; but, in order to post your own messages, you
must join.
After you join, you can post new messages and respond to messages other users post. You can read mes-
sages at any time on the Web. If you would like to have new messages from a particular forum e-mailed
to you, click the Subscribe to this Forum icon by the forum name in the forum listing.
For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to ques-
tions about how the forum software works, as well as answers to many common questions specific to
P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.
Part I
The Basics
Chapter 1: Introducing Cascading Style Sheets
Chapter 2: The Essentials
Chapter 3: Selectors
Chapter 4: The Cascade and Inheritance
Beginning CSS Cascading Style Sheets for Web Design Wrox Beginning Guides 2nd Edition Richard York
1
Introducing
Cascading Style Sheets
Cascading style sheets is a language intended to simplify website design and development. Put
simply, CSS handles the look and feel of a web page. With CSS, you can control the color of text, the
style of fonts, the spacing between paragraphs, how columns are sized and laid out, what back-
ground images or colors are used, as well as a variety of other visual effects.
CSS was created in language that is easy to learn and understand, but it provides powerful
control over the presentation of a document. Most commonly, CSS is combined with the markup
languages HTML or XHTML. These markup languages contain the actual text you see in a web
page — the hyperlinks, paragraphs, headings, lists, and tables — and are the glue of a web docu-
ment. They contain the web page’s data, as well as the CSS document that contains information
about what the web page should look like, and JavaScript, which is another language that pro-
vides dynamic and interactive functionality.
HTML and XHTML are very similar languages. In fact, for the majority of documents today, they
are pretty much identical, although XHTML has some strict requirements about the type of syntax
used. I discuss the differences between these two languages in detail in Chapter 2, and I also pro-
vide a few simple examples of what each language looks like and how CSS comes together with
the language to create a web page. In this chapter, however, I discuss the following:
❑ The W3C, an organization that plans and makes recommendations for how the web
should function and evolve
❑ How Internet documents work, where they come from, and how the browser displays
them
❑ An abridged history of the Internet
❑ Why CSS was a desperately needed solution
❑ The advantages of using CSS
The next section takes a look at the independent organization that makes recommendations about how
CSS, as well as a variety of other web-specific languages, should be used and implemented.
Who Creates and Maintains CSS?
Creating the underlying theory and planning how cascading style sheets should function and work in a
browser are tasks of an independent organization called the World Wide Web Consortium, or W3C. The
W3C is a group that makes recommendations about how the Internet works and how it should evolve. I
emphasize should, because the World Wide Web Consortium has no control over the implementation of
the standards that it defines. The W3C is comprised of member companies and organizations that come
together to create agreed-upon standards for how the web should function. Many prominent companies
and organizations are W3C members, including Microsoft, Adobe, The Mozilla Foundation, Apple,
Opera Software, and IBM. The W3C oversees the planning of several web languages including CSS,
HTML, XHTML, and XML, all of which are mentioned in this book.
CSS is maintained through a group of people within the W3C called the CSS Working Group. The CSS
Working Group creates documents called specifications. When a specification has been discussed and
officially ratified by W3C members, it becomes a recommendation. These ratified specifications are
called recommendations because the W3C has no control over the actual implementation of the language.
Independent companies and organizations create that software.
The specifications created by the W3C are not limited only to web browsers; in fact, the specifications
can be used in a variety of software, including word processor and spreadsheet applications, as well as
by different types of hardware devices, such as PDAs and cell phones. For that reason, the software
implementing a specification is referred to by the W3C as the user agent, which is a generic term that
encompasses all the different types of software that implement W3C specifications.
The W3C merely recommends that a language be implemented in a certain way to ensure that the lan-
guage does what is intended no matter which operating system, browser, or other type of software is
being used. The goal of this standardization is to enable someone using the Netscape browser, for
example, to have the same Internet experience as someone using Internet Explorer, and likewise, for
developers to have a common set of tools to accomplish the task of data presentation. Were it not for
web standards, developing documents for the web might require an entirely different document for a
given user agent. For example, Internet Explorer would require its own proprietary document format,
while Mozilla Firefox would require another. Common community standards provide website develop-
ers with the tools they need to reach an audience, regardless of the platform the audience is using.
As I write this, CSS comes in four different versions, each newer version building on the work of the last.
The first version is called CSS level 1, and became a W3C recommendation in 1996. The second version,
CSS level 2, became a W3C recommendation in 1998. The third version, CSS level 2.1, is currently a
working draft, downgraded from a candidate recommendation since I wrote the first edition of this
book in 2004. A candidate recommendation is the status the W3C applies to a specification when it feels
the specification is complete and ready to be implemented and tested. After the specification has been
implemented and tested by at least a few of the member companies, the candidate recommendation is
then more likely to become a full recommendation. A working draft is the status the W3C applies to an
ongoing work, which is subject to change. The fourth version of CSS is called CSS level 3, and many por-
tions of it are still in development. Although portions of CSS are officially subject to change by the W3C
4
Part I: The Basics
standards body, I may discuss these features anyway if at least one browser maker has implemented the
feature in question. I preface any such discussion with the warning that these features are still under
development and could be subject to change.
This book discusses the portions of CSS available in browsers at the time of this writing — that includes
most of CSS 2 and CSS 2.1, and a little of CSS 3. Some portions of CSS 2.1 contradict CSS 2 and are not
yet implemented in any browser. Where appropriate throughout the book and before introducing a new
CSS feature, I reference the W3C specification in which that CSS feature is documented by including the
phrase Documented in CSS followed by the version number. Later in this chapter, I discuss the browsers
that you need to test and build CSS-enabled web documents.
You can find the W3C website at www.w3.org. Go there to find documents that browser makers refer to
when they are looking to implement languages such as CSS into a browser or other software. Be advised,
these specifications lean heavily toward the technical side. They aren’t intended as documentation for
people who use CSS; rather, they are aimed at those who write programs that interpret CSS. Despite the
heavily technical nature of the W3C specification documents, many web developers refer to the W3C
documents as end-user documentation anyway, since it is the most complete resource.
Now that you know a little about who is responsible for planning and outlining the development of CSS,
the next section describes how a web document makes its way into your browser.
How the Internet Works
As you probably already know, the Internet is a complex network of computers. Most of what goes on
behind the scenes is of little interest to the person developing content for a website, but it is important to
understand some of the fundamentals of what happens when you type an Internet address into your
browser. Figure 1-1 shows a simple diagram of this process.
At the top of the diagram in Figure 1-1, you see a computer labeled server-side and a computer labeled
client-side. The diagram is by no means an exhaustive or complete picture of what happens when you
type in an Internet address, but it serves the purpose of illustrating the portions of the process that the
aspiring web designer needs to understand. The server-side computer houses the documents and data
of the website and is generally always running so that the website’s visitors can access the website at any
time of day. The client-side computer is, of course, your own computer.
The server-side computer contains HTTP server software that handles all the incoming requests for web
pages. When you type an Internet address into a browser, the browser sends out a request that travels
through a long network of computers that act as relays for that request until the address of the remote
(server-side) computer is found. After the request reaches the HTTP server, the HTTP server sees what it
is you are trying to find, searches for the page on the server’s hard drive, and responds to the request
you’ve made, sending the web page that you expect. That response travels back through another long
chain of computers until your computer is found. Your browser then opens the response and reads what
the HTTP server has sent back to it. If that server has sent an HTML document or another type of docu-
ment that your browser can interpret, it reads the source code of that document and processes it into a
displayable web page.
5
Chapter 1: Introducing Cascading Style Sheets
Figure 1-1
This is where CSS enters the picture. If CSS is present in the document, the CSS describes what the
HTML page should look like to the browser. If the browser understands the CSS, it processes the web
page into something you can see and interact with. If the browser understands only some of the CSS, it
generally ignores what it doesn’t understand. If the browser doesn’t understand CSS at all, it usually
displays a plain-looking version of the HTML document.
How CSS Came to Be
During the mid-1990s, use of the Internet exploded. At that time, HTML was the only option for present-
ing a web page. As the Internet began to be used by more regular folks (as opposed to government, edu-
cational institutions, and researchers, as in the early days), users began demanding more control over
the presentation of HTML documents. A great quandary arose — clearly HTML alone was not good
enough to make a document presentable. In fact, not only was it not good enough, HTML alone simply
wasn’t suited for the job. HTML did not have the functionality that professional publishing required and
had no way of making magazine- or newspaper-like presentations of an electronic document.
5. HTTP server sends the web document.
Server-side
Client-side
6. Your browser receives the document.
7. Your browser processes the source code.
8. The browser displays the web page.
4. HTTP server looks up the web document.
3. HTTP server receives the request from the browser.
2. Browser contacts the HTTP server at that address.
1. You type a www address into the browser.
6
Part I: The Basics
At the time, style sheets were not a new invention. In fact, style sheets were part of the plan from the
beginning of HTML in 1990. Unfortunately, however, no standardized method of implementing style
sheets was ever outlined, leaving this function up to the various browsers. In 1994, Tim Berners-Lee
founded the World Wide Web Consortium, and a few days later, Håkon Wium Lie published his first
draft of Cascading HTML Style Sheets. This draft was a proposal for how HTML documents could be
styled using simple declarations.
Of those that responded to Håkon’s draft of Cascading HTML Style Sheets was Bert Bos, who was work-
ing on a style sheet proposal of his own. The two joined forces and came up with cascading style sheets.
They dropped HTML from the title, realizing that CSS would be better as a general style sheet language,
applicable to more than one type of document. CSS caused some controversy at its inception because
part of the underlying fundamentals of the new style sheet language was that it created a balance between
the browser’s style sheet, the user’s style sheet, and the author’s style sheet. Some simply didn’t like the
idea that the user could have control over the presentation of a web document. Ultimately, however, the
Internet community accepted CSS.
Among CSS supporters was Microsoft, who pledged support for the new style sheet language in its
Internet Explorer web browser. Netscape, on the other hand, another popular web browser at the time,
remained skeptical about CSS and went forward with a style sheet language of its own called JavaScript
Style Sheets, or JSSS. Ultimately, Netscape’s style sheets were not successful. Eventually, because of a
series of bad decisions and setbacks on the part of Netscape as a whole and Netscape’s management,
Netscape ultimately began losing market share, and Microsoft’s Internet Explorer (IE) browser grew
more and more popular. At IE’s peak, it held 95 to 98 percent of the browser market share. Although IE
has since lost market share to the likes of Mozilla Firefox and Safari, at the time of this writing, IE is still
the dominant browser, most firms putting IE’s market share at 50 to 85 percent, depending on the web-
site’s audience. Mainstream sites will see upward of 85 percent, but technical websites may see around
50 percent. Your own website’s browser statistics will depend largely on the content of your site. One
such site to reference for statistics is http://www.upsdell.com/BrowserNews/stat.htm. However,
keep in mind the quote, “There are lies, damn lies — and statistics” — Disraeli (later made famous by
Mark Twain).
During the time that CSS was being planned, browsers began allowing HTML features that control pre-
sentation of a document into the browser. This change is the primary reason for much of the bloated and
chaotic source code in the majority of websites operating today on the Internet. Even though HTML was
never supposed to be a presentational language, it grew to become one. Unfortunately, by the time CSS
level 1 was made a full W3C recommendation in 1996, the seed had already been planted. Presentational
HTML had already taken root in mainstream website design and continues today.
However, all is not lost. Today, the most popular browsers have fantastic support for cascading style
sheets. Ironically, the browser exhibiting the least support is Microsoft’s Internet Explorer for Windows,
which still has plenty of CSS support to do away with most presentational HTML design. More ironic
still, among the browsers with the best CSS support is Netscape’s browser, and its open source offspring,
Mozilla Firefox. This may beg the question: If Microsoft was such an avid supporter of cascading style
sheets in the beginning, why is Microsoft’s browser the least standards-compliant today? The answer is
that Microsoft did indeed follow through with its promise for CSS support, and it was the most compre-
hensive and impressive implementation of CSS even up to the release of Internet Explorer 6 in 2001.
Even so, CSS implementation in Internet Explorer has declined since the release of Internet Explorer 5.
We can only speculate as to why Microsoft’s browser declined in its support for CSS.
7
Chapter 1: Introducing Cascading Style Sheets
In the next section, I talk about the different types of browsers that you’ll need to work through the
examples for this book.
Browsers
Because CSS is a standard web language, many browsers support it. Therefore, it stands to reason that
the aspiring web designer would want to harness that standardization to reach the largest audience pos-
sible, regardless of operating system or platform. In this section I provide an overview of each of these
browsers, and where you can look to obtain a new version of that browser. Together, the following
browsers combined comprise over 99 percent of the browser market share for the majority of websites
in operation today:
❑ Internet Explorer 6 and 7 for Windows
❑ Mozilla Firefox for Windows, Mac, and Linux
❑ Opera for Windows, Mac, and Linux
❑ Safari for Mac OS X
In the next section, I discuss Internet Explorer 6 and 7 for Windows.
Internet Explorer
Internet Explorer is Microsoft’s flagship browser that comes preloaded with the Windows operating sys-
tem. The current stable version, as of this writing, is version 7.
Internet Explorer 7
Late in 2004, after the first edition of this book was published, Microsoft finally began work on a new
version of Internet Explorer. IE 7 includes stronger security, tabbed browsing, and other goodies for
users, and for developers — improvements to IE’s support for CSS!
IE 7 comes just over five years after the release of IE 6, which was released in 2001. IE 7 is a fantastic
improvement over IE 6, but it still doesn’t quite meet the level of CSS present in competing browsers
like Apple’s Safari browser, or Mozilla Firefox. Although it doesn’t exhibit the best CSS support, there is
hope that future versions of IE will make significant progress in this area. Internet Explorer developers,
and even Bill Gates, have publicly stated that Microsoft has returned to a more frequent release cycle for
Internet Explorer, and we can expect new versions of Internet Explorer every year for the foreseeable
future. Microsoft has even gone so far as to admit that it made a mistake by waiting too long to release a
new version of IE.
Even though IE 7 is finally here, it will be years still before it achieves sufficient market penetration that
web developers can officially dump support for IE 6. Because of IE 6’s deficiencies, many are chomping
at the bit for that time to come. In the meantime, we’ll have to continue to support it and work around
its shortcomings.
8
Part I: The Basics
IE 7 is available for the following operating systems:
❑ Windows XP Service Pack 2
❑ Windows XP Pro 64-bit Edition
❑ Windows Server 2003
❑ Windows Vista
You can obtain IE 7 from Microsoft’s website at http://www.microsoft.com/ie.
Internet Explorer 6
At the time of this writing Internet Explorer 6 is still the top dog with its browser market share between
50 and 85 percent, depending on the website’s audience (see my discussion of Internet Explorer’s market
share in the section titled “How CSS Came to Be” earlier in this chapter). If you don’t already have IE 6,
you can obtain it from http://www.microsoft.com/windows/ie/ie6/default.mspx.
Installing Multiple Versions of Internet Explorer for Testing
At the time of this writing, you cannot install IE 7 alongside IE 6 on the same copy of Windows. For
development, you need a way to test IE 6 and IE 7 both, since you’ll have visitors to your website on
both browsers. The following are a few ways to do this.
❑ Use PC virtualization/emulation software such as Virtual PC (a product made by Microsoft),
which allows you to install and run different versions of Windows (or other operating systems,
such as Linux) from within Windows or Mac OS X. Essentially, you can load up a new instance
of Windows from your Windows desktop, and have that instance of Windows run in a window,
independently. For example, Figure 1-2 shows a screenshot of me running Windows XP and IE 6
from my Mac OS X desktop, using the open source software Q, which lets me install and run
Windows from within Mac OS X.
❑ Another option is setting up two different physical computers, one with IE 6 installed, and the
other with IE 7.
❑ If you’re feeling particularly adventurous, you can set up two installations of Windows on the
same computer, although for this discussion, this method is a bit too advanced for me to ade-
quately cover here. If you’d like to learn more about installing Windows more than once on the
same computer, more information about that can be found at http://www.microsoft.com/
windowsxp/using/setup/learnmore/multiboot.mspx.
Figure 1-2 shows two instances of Windows XP running in Parallels Desktop for Mac; one is running
IE 6, and the other is running IE 7.
Most people prefer to keep it simple, and have all of their development tools at their fingertips. That
makes the virtualization/emulation method the most attractive, in lieu of actually being able to install
IE 6 alongside IE 7. I discuss this method in further detail in the next section.
9
Chapter 1: Introducing Cascading Style Sheets
Figure 1-2
Installing Windows Using PC Virtualization/Emulation Software
Today many companies make PC virtualization or emulation software, which allows you to run an
entire operating system from a window on your desktop in the manner illustrated in Figure 1-2. More or
less, it’s like having multiple computers all consolidated into one. You can boot up a virtual computer,
with all default settings so you can test your web pages. Here are some of the titles available.
10
Part I: The Basics
❑ VMWare, Player: Available for free from http://www.vmware.com/products/player/ for
Windows and Linux.
❑ Virtual PC: Made by Microsoft, available for $129 from http://www.microsoft.com/windows/
virtualpc (the price does not include a license for running Windows in the Virtual PC).
Requires Windows or a PowerPC-based Mac.
❑ Q (pictured in Figure 1-2): Available for free from http://www.kberg.ch/q. If you’re using
Mac OS X, Q is available as a universal application (it runs on both PowerPC-based and Intel-
based Macs).
❑ Parallels: Available for $49.99 from http://www.parallels.com for Windows, Mac (PowerPC
and Intel-based), and Linux.
The best software for installing Windows from another operating system is software that uses virtualiza-
tion. Without going into the technical details, software using virtualization runs much faster. The other,
slower, much slower, in fact, method is emulation. Parallels and VMWare use virtualization, whereas, at
the time of this writing, Microsoft’s Virtual PC and “Q” both use emulation. Your computer will also
need serious horsepower to run two operating systems at the same time; see each respective website for
the system requirements of each of the aforementioned solutions. In my experience, software like this
works best with at least 1GB of RAM and about a 2 GHz processor.
Without the ability to install and work with Windows virtually using software such as VMWare, your
last resort is to uninstall IE 7 every time you need to test in IE 6, which can throw a pretty big wrench in
the testing process. Currently, the virtual machine solution is the one officially sanctioned and recom-
mended by Microsoft for testing in multiple versions of Internet Explorer. The IE team has responded
to requests from web developers for the ability to install and run multiple versions of Internet Explorer
side-by-side, and have said they are looking at the problem, but have not yet publicly announced a solu-
tion or released software to remedy the problem.
Internet Explorer for PowerPC Mac OS X
For PowerPC Macintosh users, I recommend not using or testing in IE for Mac. The capabilities and
bugs of IE for Windows and IE for Mac are very different. IE for the Macintosh has better support for
CSS (compared to IE 6), but it is an entirely different browser. The name may be the same, but the
browsers are very different. In fact, Microsoft has completely dropped support for IE for Mac, having
stopped development with a public announcement made in 2003, and having completely stopped sup-
port in 2005. It has less than a tenth of a percent of market share, if that much, and it does not run on
Apple’s Intel-based Macs.
For Mac users, I recommend Apple’s own Safari or a Gecko browser, such as Camino or Mozilla Firefox,
which I discuss further in the coming sections. If you don’t have Internet Explorer for Windows, you still
can work through most exercises and examples presented in this book, but if you are serious about web-
site design, you will need to find a way to test your websites in Internet Explorer on Windows, since it
has the majority of market share, and will enjoy that status far into the foreseeable future.
For news on what is transpiring in the world of Internet Explorer development, you might like to check
out the Internet Explorer Team’s blog at http://blogs.msdn.com/ie. New IE features and news of
anything relating to Internet Explorer are announced on the IE Team blog.
11
Chapter 1: Introducing Cascading Style Sheets
The Gecko Browsers: Mozilla Firefox, Netscape, Camino
Gecko was created in January 1998. At that time, Netscape announced that it was making its browser
free to its users and that its browser would be open source, meaning that its source code would be freely
available for modification and distribution. This led to the creation of Mozilla; at the time Mozilla was
the organization charged with developing and managing the Netscape code base. America Online later
purchased Netscape, and until July 2003 Mozilla remained a part of Netscape. In July 2003, the Mozilla
Foundation was created, making Mozilla an independent, not-for-profit corporation. When the Netscape
browser became open source, its rendering engine, the part of the browser software responsible for mak-
ing the source code of a web page into something you can see and interact with, was given the name
Gecko.
Gecko is the foundation that a whole suite of browsers relies on to do the behind-the-scenes work of ren-
dering web pages. Gecko is included in AOL for Mac OS X, Camino, Netscape 6, Netscape 7, Netscape 8,
Mozilla Suite, Mozilla Sea Monkey, and Mozilla Firefox.
Netscape’s browser market share has greatly diminished, whereas Mozilla Firefox continues to gain in
popularity, occupying the number-two spot at between 5 and 30% market share (again, depending on
the website’s audience). Netscape’s (and other Gecko browsers, for that matter) market share is charted
by most statistics at less than one percent.
The following table shows the relationship between other Gecko browsers and Mozilla Firefox. This
table illustrates the version of the underlying Gecko engine that each browser has in common with
Firefox. Each of these browsers can be expected to render a web page identically and have the same
capabilities in the area of CSS and document layout as the version of Firefox cited.
Other Gecko Browser Firefox
Netscape 8.1 Firefox 1.5
Netscape 8.0 Firefox 1.0
Netscape 7.2 Firefox 0.9
Camino 1.0 Firefox 1.5
SeaMonkey 1.0 (formerly Mozilla Suite) Firefox 1.5
Mozilla Suite 1.8 Firefox 1.0
Mozilla Suite 1.7 Firefox 0.9
Mozilla Suite 1.6 Firefox 0.8
Netscape 8.0 and 8.1 both feature the ability to switch between IE and Gecko for rendering a web page
from within the Netscape browser, so essentially it is both Internet Explorer and Gecko in the same
browser. The version of Internet Explorer in Netscape 8.0 and 8.1 is the same as the version of IE
installed on the system. Netscape uses Gecko by default, but may try to “automatically” select the best
rendering engine to use for a given website.
12
Part I: The Basics
You can see that Firefox 0.9 and Mozilla Suite 1.7 can be expected to behave identically where CSS and
design layout is concerned.
Because gecko browsers share the same brain (and because of Firefox’s popularity), for the remainder of
this book, I cite only Firefox when referring to a Gecko browser.
Depending on which Gecko browser you happen to like, you can obtain Gecko browsers from the fol-
lowing places:
❑ Mozilla Firefox for Windows, Mac, and Linux: Available from http://www.mozilla.com/
firefox
❑ Netscape for Windows: Available from http://www.netscape.com/download
❑ Camino for Mac: Available from http://www.caminobrowser.org/
❑ SeaMonkey for Windows, Mac, and Linux: Available from http://www.mozilla.org/
projects/seamonkey/
Safari
The next browser that I discuss is Safari, which is based on Konqueror, an open source browser available
for Linux operating systems. The rendering engine used in the Safari and Konqueror web browsers is
called KHTML. While Konqueror and Safari both have KHTML in common, Safari is a fork of KHTML
(a fork means they shared the exact same source code at one point, but now each is developed indepen-
dently), and features found in Safari may not necessarily appear in Konqueror and vice versa. Despite
this, the two browsers render documents very similar to one another. Apple develops Safari, indepen-
dently of Konqueror, and is the browser included with Macintosh OS X operating systems. Before Safari,
Internet Explorer for Mac and Gecko had been dominant on the Mac.
For the purpose of this book, I note Safari compatibility when appropriate. Safari is available only for
Mac OS X and can be obtained from www.apple.com/safari. Konqueror is only available for Linux
(and any operating system in which KDE, the K Desktop Environment, runs) at the time of this writing;
it can be found at www.konqueror.org.
Opera
Opera is a lesser-known, Norwegian-based company. Opera users are fewer, accounting for only a few per-
cent market share by most statistical estimates. Again, that figure can be much higher or lower depending
on a website’s audience. Also be aware that Opera and Mozilla Firefox browsers can be configured to iden-
tify themselves to a website as Microsoft Internet Explorer browsers. This, of course, can distort statistical
analysis. This spoofing is done because websites often create content targeting Microsoft Internet Explorer
and Netscape specifically, leaving everyone else out in the cold—even though third-party browsers like
Mozilla Firefox and Opera probably support the required functionality.
At the time of this writing, the current version of the Opera browser is 9.0. You can download this
browser for free from www.opera.com. The Opera browser is available for Windows, Macintosh, Linux,
and a variety of other platforms.
13
Chapter 1: Introducing Cascading Style Sheets
Writing CSS
To write CSS, just as is the case when writing HTML source, you will need a text editor. WYSIWYG
(What You See Is What You Get) editors such as Microsoft Word aren’t ideally suited for CSS because the
environment is not ideal for the composition of source code. WYSIWYG programs often have features
like AutoCorrection and line wrapping; a plain text editor is more appealing precisely because it does
not have these automatic features. Furthermore, the more automated WYSIWYG editors are designed to
write the source code for you behind the scenes, so you don’t have complete control over the structure
and formatting of the source code. In contrast, a plain text editor doesn’t insert anything into the source
code beyond what you type into the text editor.
The Windows Notepad program is one example of a text editor that is ideal for composing source code.
To launch Notepad, choose Start ➪ Run and then type Notepad in the Open text box. You can also use
Microsoft FrontPage, but FrontPage is best used in view source mode where you can edit the source code
directly instead of via the WYSIWYG interface. The same holds true for Macromedia Dreamweaver.
On Mac OS X, the Notepad equivalent is TextEdit, which can be found in the Mac OS X Applications
folder.
If Notepad or TextEdit is just too basic for your taste, a text editor that highlights markup and CSS syn-
tax might suit your needs better. The following are full-featured alternative text editors for Windows:
❑ Crimson Editor: www.crimsoneditor.com (free)
❑ HTML-kit: www.chami.com/html-kit (free)
Here are some alternative text editors that work with Mac OS X:
❑ CreaText: http://creatext.sourceforge.net (free)
❑ BBEdit: www.barebones.com (shareware)
If you’re using Linux, you’re probably already familiar with the different text editors that come bundled
with the various distributions.
You must create HTML files with the .html extension. If you use Notepad or TextEdit, beware of your
files being saved with a .txt extension, which will not result in the HTML file you were going for.
To ensure that your files are saved properly on Windows, choose Start ➪ Run and type Explorer (or
right-click Start and choose Explore from the pop-up menu) to open Windows Explorer. After Windows
Explorer is open, choose Tools ➪ Folder Options to open the Folder Options window, click the View tab,
and uncheck the Hide Extensions for Known File Types box (see Figure 1-3). Then click OK.
HTML files are not the only file type in which the document extension is important; other file types
require specific extensions as well. Those file types are covered later in this chapter.
14
Part I: The Basics
Figure 1-3
On Mac OS X, open Finder, and go to Finder ➪ Preferences. Select the Advanced tab, and check the box
for Show All File Extensions, which is depicted in Figure 1-4.
Figure 1-4
Armed with a browser and a text editor, in the next section I present an example of what CSS can do.
Your First CSS-Enabled Document
The following example is designed to introduce you to what CSS is capable of. It is designed to help you
get your feet wet and get straight down to the business of writing style sheets.
15
Chapter 1: Introducing Cascading Style Sheets
You can find the images and source code for the following example at www.wrox.com. While you can
obtain the source code from www.wrox.com, I recommend that you type out the example so that you
can get used to writing the syntax, and take in the different bits that come together in the example.
Try It Out Creating a CSS-Enabled Document
Example 1-1. To write your first CSS-enabled document, follow these steps.
1. In your text editor of choice, enter the following markup:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=’http://www.w3.org/1999/xhtml’ xml:lang=’en’>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8” />
<title>The Gas Giants</title>
<link rel=’stylesheet’ type=’text/css’ href=’solar_system.css’ />
<script type=’text/javascript’>
var fixpng = function($img) {};
</script>
<!--[if lt IE 7]>
<link rel=’stylesheet’ type=’text/css’ href=’solar_system.ie.css’ />
<script type=’text/javascript’>
// This fixes PNG transparency in IE
var fixpng = function($img)
{
var $html =
‘<span ‘ +
(($img.id)? “id=’” + $img.id + “‘ “ : ‘’) +
(($img.className)? “class=’” + $img.className + “‘ “ : ‘’) +
(($img.title)? “title=’” + $img.title + “‘ “ : ‘’) +
‘style=”’ +
‘display: inline-block;’ +
‘width: ‘ + $img.width + ‘px;’ +
‘height: ‘ + $img.height + ‘px;’ +
“filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(“ +
“src=’” + $img.src + “‘, sizingMethod=’scale’); “ +
$img.style.cssText + ‘“ ‘;
if ($img.getAttribute(‘mouseoversrc’))
{
$html += “mouseoversrc=’” + $img.getAttribute(‘mouseoversrc’) + “‘ “;
}
if ($img.getAttribute(‘mouseoutsrc’))
{
$html += “mouseoutsrc=’” + $img.getAttribute(‘mouseoutsrc’) + “‘ “;
}
$html += ‘></span>’;
$img.outerHTML = $html;
16
Part I: The Basics
}
</script>
<![endif]-->
</head>
<body>
<!--
Image reuse guidelines:
http://www.nasa.gov/multimedia/guidelines/index.html
-->
<div id=’solar-system’>
<div class=’planet jupiter’>
<img src=’images/jupiter.png’
alt=’Jupiter’
class=’planet’
onload=’fixpng(this);’ />
<div class=’planet-copy’>
<h1>Jupiter</h1>
<ul>
<li><b>Distance from the Sun:</b> 78,412,020 km</li>
<li><b>Equatorial Radius:</b> 71,492 km</li>
<li><b>Volume:</b> 1,425,500,000,000,000 km<sup>3</sup></li>
<li><b>Mass:</b> 1,898,700,000,000,000,000,000,000,000 kg</li>
<li>
<a href=’http://solarsystem.jpl.nasa.gov/planets/profile.cfm?Object=Jupiter’>
More Facts
</a>
</li>
</ul>
<img src=’images/symbols/jupiter.png’
alt=’Mythological Symbol for Jupiter’
onload=’fixpng(this);’ />
</div>
</div>
<div class=’planet saturn’>
<img src=’images/saturn.png’
alt=’Saturn’
class=’planet’
onload=’fixpng(this);’/>
<div class=’planet-copy’>
<h1>Saturn</h1>
<ul>
<li><b>Distance from the Sun:</b> 1,426,725,400 km</li>
<li><b>Equatorial Radius:</b> 60,268 km</li>
<li><b>Volume:</b> 827,130,000,000,000 km<sup>3</sup></li>
<li><b>Mass:</b> 568,510,000,000,000,000,000,000,000 kg</li>
<li>
<a href=’http://solarsystem.jpl.nasa.gov/planets/profile.cfm?Object=Saturn’>
More Facts
</a>
</li>
</ul>
<img src=’images/symbols/saturn.png’
17
Chapter 1: Introducing Cascading Style Sheets
alt=’Mythological Symbol for Saturn’
onload=’fixpng(this);’ />
</div>
</div>
<div class=’planet uranus’>
<img src=’images/uranus.png’
alt=’Uranus’
class=’planet’
onload=’fixpng(this);’ />
<div class=’planet-copy’>
<h1>Uranus</h1>
<ul>
<li><b>Distance from the Sun:</b> 2,870,972,200 km</li>
<li><b>Equatorial Radius:</b> 25,559 km</li>
<li><b>Volume:</b> 69,142,000,000,000 km<sup>3</sup></li>
<li><b>Mass:</b> 86,849,000,000,000,000,000,000,000 kg</li>
<li>
<a href=’http://solarsystem.jpl.nasa.gov/planets/profile.cfm?Object=Uranus’>
More Facts
</a>
</li>
</ul>
<img src=’images/symbols/uranus.png’
alt=’Mythological Symbol for Uranus’
onload=’fixpng(this);’ />
</div>
</div>
<div class=’planet neptune’>
<img src=’images/neptune.png’
alt=’Neptune’
class=’planet’
onload=’fixpng(this);’ />
<div class=’planet-copy’>
<h1>Neptune</h1>
<ul>
<li><b>Distance from the Sun:</b> 4,498,252,900 km</li>
<li><b>Equatorial Radius:</b> 24,764 km</li>
<li><b>Volume:</b> 62,526,000,000,000 km<sup>3</sup></li>
<li><b>Mass:</b> 102,440,000,000,000,000,000,000,000 kg</li>
<li>
<a href=’http://solarsystem.jpl.nasa.gov/planets/profile.cfm?Object=Neptune’>
More Facts
</a>
</li>
</ul>
<img src=’images/symbols/neptune.png’
alt=’Mythological Symbol for Neptune’
onload=’fixpng(this);’/>
</div>
</div>
</div>
</body>
</html>
18
Part I: The Basics
Another Random Scribd Document
with Unrelated Content
containing a part of this work or any other work associated with
Project Gutenberg™.
1.E.5. Do not copy, display, perform, distribute or redistribute
this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
1.E.7. Do not charge a fee for access to, viewing, displaying,
performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.
1.E.8. You may charge a reasonable fee for copies of or
providing access to or distributing Project Gutenberg™
electronic works provided that:
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You provide a full refund of any money paid by a user who
notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.
• You provide, in accordance with paragraph 1.F.3, a full refund of
any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.E.9. If you wish to charge a fee or distribute a Project
Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.
1.F.
1.F.1. Project Gutenberg volunteers and employees expend
considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite these
efforts, Project Gutenberg™ electronic works, and the medium
on which they may be stored, may contain “Defects,” such as,
but not limited to, incomplete, inaccurate or corrupt data,
transcription errors, a copyright or other intellectual property
infringement, a defective or damaged disk or other medium, a
computer virus, or computer codes that damage or cannot be
read by your equipment.
1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except
for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU AGREE
THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT
LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT
EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE
THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.
1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you
discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person
or entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.
1.F.4. Except for the limited right of replacement or refund set
forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
1.F.5. Some states do not allow disclaimers of certain implied
warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.
1.F.6. INDEMNITY - You agree to indemnify and hold the
Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you
do or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.
Section 2. Information about the Mission
of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.
Volunteers and financial support to provide volunteers with the
assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.
Section 3. Information about the Project
Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status
by the Internal Revenue Service. The Foundation’s EIN or
federal tax identification number is 64-6221541. Contributions
to the Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.
The Foundation’s business office is located at 809 North 1500
West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.
The Foundation is committed to complying with the laws
regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or determine
the status of compliance for any particular state visit
www.gutenberg.org/donate.
While we cannot and do not solicit contributions from states
where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.
International donations are gratefully accepted, but we cannot
make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.
Please check the Project Gutenberg web pages for current
donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.
Section 5. General Information About
Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.
Project Gutenberg™ eBooks are often created from several
printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
This website includes information about Project Gutenberg™,
including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!
ebookultra.com

More Related Content

PDF
Beginning CSS Cascading Style Sheets for Web Design Wrox Beginning Guides 2nd...
PDF
Beginning Css Cascading Style Sheets For Web Design Wrox Beginning Guides 2nd...
PDF
Wiley.HTML.and.CSS.Oct.2011.pdf
PDF
Css Hacks And Filters Making Cascading Stylesheets Work Joseph W Lowery
PDF
[Web开发Css系列].Apress.Pro.Css.Techniques.Nov.2006
PDF
JavaScript 设计模式
PDF
Beginning JavaScript und CSS development with jQuery 1. ed Edition Richard York
PPTX
lec11_CSS.pptx web page description desi
Beginning CSS Cascading Style Sheets for Web Design Wrox Beginning Guides 2nd...
Beginning Css Cascading Style Sheets For Web Design Wrox Beginning Guides 2nd...
Wiley.HTML.and.CSS.Oct.2011.pdf
Css Hacks And Filters Making Cascading Stylesheets Work Joseph W Lowery
[Web开发Css系列].Apress.Pro.Css.Techniques.Nov.2006
JavaScript 设计模式
Beginning JavaScript und CSS development with jQuery 1. ed Edition Richard York
lec11_CSS.pptx web page description desi

Similar to Beginning CSS Cascading Style Sheets for Web Design Wrox Beginning Guides 2nd Edition Richard York (20)

PDF
Beginning JavaScript und CSS development with jQuery 1. ed Edition Richard York
PPT
New Css style
PDF
Build Your Own Website A Comic Guide to HTML, CSS and Wordpress (Nate Cooper)...
PPT
PPT
Ddpz2613 topic8 css
PDF
Taking your talent_to_the_web2
PPT
Introduction to Cascading Style Sheets (CSS)
PPT
PDF
Master Web Design with HTML CSS JavaScript and jQuery Create Stunning Interac...
PDF
Beginning JavaScript und CSS development with jQuery 1. ed Edition Richard York
PPT
Learn CSS From Scratch
PPTX
basic programming language AND HTML CSS JAVApdf
PDF
Chapter 3 - CSS.pdf
PDF
CSS The Definitive Guide Visual Presentation for the Web 4th Edition Eric A. ...
PDF
New Perspectives on HTML5 CSS3 JavaScript 6th Edition Carey Solutions Manual
PPT
Supplement web design
PDF
Css masterclass book
PDF
Get Master Web Design with HTML CSS JavaScript and jQuery Create Stunning Int...
PPTX
Css introduction
PDF
CSS Bootstrap.pdf
Beginning JavaScript und CSS development with jQuery 1. ed Edition Richard York
New Css style
Build Your Own Website A Comic Guide to HTML, CSS and Wordpress (Nate Cooper)...
Ddpz2613 topic8 css
Taking your talent_to_the_web2
Introduction to Cascading Style Sheets (CSS)
Master Web Design with HTML CSS JavaScript and jQuery Create Stunning Interac...
Beginning JavaScript und CSS development with jQuery 1. ed Edition Richard York
Learn CSS From Scratch
basic programming language AND HTML CSS JAVApdf
Chapter 3 - CSS.pdf
CSS The Definitive Guide Visual Presentation for the Web 4th Edition Eric A. ...
New Perspectives on HTML5 CSS3 JavaScript 6th Edition Carey Solutions Manual
Supplement web design
Css masterclass book
Get Master Web Design with HTML CSS JavaScript and jQuery Create Stunning Int...
Css introduction
CSS Bootstrap.pdf
Ad

Recently uploaded (20)

PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
master seminar digital applications in india
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Lesson notes of climatology university.
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
RMMM.pdf make it easy to upload and study
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Complications of Minimal Access Surgery at WLH
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
Microbial disease of the cardiovascular and lymphatic systems
master seminar digital applications in india
Anesthesia in Laparoscopic Surgery in India
Abdominal Access Techniques with Prof. Dr. R K Mishra
Lesson notes of climatology university.
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
RMMM.pdf make it easy to upload and study
TR - Agricultural Crops Production NC III.pdf
Cell Structure & Organelles in detailed.
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Microbial diseases, their pathogenesis and prophylaxis
O7-L3 Supply Chain Operations - ICLT Program
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Complications of Minimal Access Surgery at WLH
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
VCE English Exam - Section C Student Revision Booklet
Basic Mud Logging Guide for educational purpose
Renaissance Architecture: A Journey from Faith to Humanism
Ad

Beginning CSS Cascading Style Sheets for Web Design Wrox Beginning Guides 2nd Edition Richard York

  • 1. Visit https://ebookultra.com to download the full version and explore more ebooks Beginning CSS Cascading Style Sheets for Web Design Wrox Beginning Guides 2nd Edition Richard York _____ Click the link below to download _____ https://ebookultra.com/download/beginning-css- cascading-style-sheets-for-web-design-wrox-beginning- guides-2nd-edition-richard-york/ Explore and download more ebooks at ebookultra.com
  • 2. Here are some suggested products you might be interested in. Click the link to download Beginning JavaScript und CSS development with jQuery 1. ed Edition Richard York https://ebookultra.com/download/beginning-javascript-und-css- development-with-jquery-1-ed-edition-richard-york/ Beginning Visual C 2005 Wrox Beginning Guides 2nd Edition Karli Watson Christian Nagel Jacob Hammer Pedersen Jon D. Reid Morgan Skinner Eric White https://ebookultra.com/download/beginning-visual-c-2005-wrox- beginning-guides-2nd-edition-karli-watson-christian-nagel-jacob- hammer-pedersen-jon-d-reid-morgan-skinner-eric-white/ Beginning Joomla Web Site Development Wrox Programmer to Programmer 1st Edition Cory Webb https://ebookultra.com/download/beginning-joomla-web-site-development- wrox-programmer-to-programmer-1st-edition-cory-webb/ Beginning JSP JSF and Tomcat 2nd Edition Java Web Development Giulio Zambon https://ebookultra.com/download/beginning-jsp-jsf-and-tomcat-2nd- edition-java-web-development-giulio-zambon/
  • 3. Beginning Android Web Apps Development 1st ed. Edition Jon Westfall https://ebookultra.com/download/beginning-android-web-apps- development-1st-ed-edition-jon-westfall/ Beginning ASP NET Web Pages with WebMatrix 1st Edition Mike Brind https://ebookultra.com/download/beginning-asp-net-web-pages-with- webmatrix-1st-edition-mike-brind/ Beginning JSP Jsf and Tomcat Web Development 1st Edition Giulio Zambon https://ebookultra.com/download/beginning-jsp-jsf-and-tomcat-web- development-1st-edition-giulio-zambon/ BEGINNING LUCIFERIAN MAGICK 2nd Edition Michael W. Ford https://ebookultra.com/download/beginning-luciferian-magick-2nd- edition-michael-w-ford/ Beginning Bridge Alan Hiron https://ebookultra.com/download/beginning-bridge-alan-hiron/
  • 5. Beginning CSS Cascading Style Sheets for Web Design Wrox Beginning Guides 2nd Edition Richard York Digital Instant Download Author(s): Richard York ISBN(s): 0470096977 Edition: 2 File Details: PDF, 33.97 MB Year: 2007 Language: english
  • 7. Beginning CSS Cascading Style Sheets for Web Design Second Edition Richard York
  • 11. Beginning CSS Cascading Style Sheets for Web Design Second Edition Richard York
  • 12. Beginning CSS: Cascading Style Sheets for Web Design, Second Edition Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-09697-0 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REP- RESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CON- TENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CRE- ATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CON- TAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FUR- THER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFOR- MATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services or to obtain technical support, please contact our Cus- tomer Care Department within the U.S. at (800) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002. Library of Congress Cataloging-in-Publication Data York, Richard, 1978– Beginning CSS : cascading style sheets for Web design / Richard York. — 2nd ed. p. cm. Includes index. ISBN 978-0-470-09697-0 (paper/website) 1. Web sites—Design. 2. Cascading style sheets. I. Title. TK5105.888.Y67 2007 006.7—dc22 2007008853 Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respec- tive owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.
  • 13. To my own cousin Ryan Wood In the words of Ryan’s favorite comedian, Dave Chappelle, “I’m rich, bitch!” Rest in peace, brother. We love you and we miss you.
  • 15. About the Author Richard York is a web application developer for Trilithic, Inc., a company specializing in test equipment for the telecommunications industry. He wrote his first book, Beginning CSS: Cascading Style Sheets for Web Design (Wrox Press), in 2004. Richard began his web development career taking courses at Indiana University–Purdue University Indianapolis. Since college, he has continued a self-imposed curriculum, mastering various technologies used in web development including HTML/XHTML, CSS, JavaScript, PHP, and MySQL. An avid sup- porter of open source software, he has written an open source webmail application for PHP PEAR and is currently working on an open source PHP library and framework called Hierophant, which he hopes to release in 2007. Richard maintains a personal website at http://www.richard-york.com where you can learn more about his professional and personal interests.
  • 16. Credits Senior Acquisitions Editor Jim Minatel Development Editor Brian MacDonald Technical Editor Alexei Gorkov Technical Reviewers Robert Searing Marybeth Fullmer Copy Editor Mildred Sanchez Editorial Manager Mary Beth Wakefield Production Manager Tim Tate Vice President and Executive Group Publisher Richard Swadley Vice President and Executive Publisher Joseph B. Wikert Project Coordinator Heather Kolter Graphics and Production Specialists Carrie A. Foster Denny Hager Joyce Haughey Alicia B. South Ronald Terry Quality Control Technician John Greenough Proofreader Sossity R. Smith Indexer Aptara Anniversary Logo Design Richard Pacifico
  • 17. Contents Acknowledgments xv Introduction xvii Part I: The Basics Chapter 1: Introducing Cascading Style Sheets 3 Who Creates and Maintains CSS? 4 How the Internet Works 5 How CSS Came to Be 6 Browsers 8 Internet Explorer 8 The Gecko Browsers: Mozilla Firefox, Netscape, Camino 12 Safari 13 Opera 13 Writing CSS 14 Your First CSS-Enabled Document 15 Advantages of Using CSS 21 Summary 22 Chapter 2: The Essentials 25 CSS Rules 25 Selectors 26 Declarations 27 Grouping Selectors 28 CSS Comments 29 Values 31 Keywords 31 Strings 34 Length and Measurement 36 Numbers 45 The URI 51 Including CSS in a Document 52 Including an Embedded Style Sheet 53 Linking to External Style Sheets 54
  • 18. x Contents Importing Style Sheets 56 Inline Styles 56 Summary 57 Exercises 58 Chapter 3: Selectors 59 Class and ID Selectors 60 Class Selectors 60 ID Selectors 63 The Universal Selector 68 Descendant Selectors 71 Direct Child Selectors 75 Next Sibling Selector 79 Attribute Selectors 82 Selection Based on the Value of an Attribute 83 Attribute Substring Selectors 87 Pseudo-Elements :first-letter and :first-line 93 Pseudo-Classes 97 Dynamic Pseudo-Classes 97 The first-child Structural Pseudo-Class 102 Summary 106 Exercises 106 Chapter 4: The Cascade and Inheritance 109 The Cascade 109 Calculating the Specificity of a Selector 112 !important Rules 118 Inheritance 121 Summary 125 Exercises 126 Part II: Properties Chapter 5: Text Manipulation 131 The letter-spacing Property 132 The word-spacing Property 137 Indenting Paragraph Text Using text-indent 141 Aligning Text with the text-align Property 147 The text-decoration Property 150
  • 19. xi Contents The text-transform Property 155 The white-space Property 158 Summary 164 Exercises 164 Chapter 6: Fonts 167 Specifying Fonts with the font-family Property 167 Font Families 169 Generic Font Families 171 The font-style Property 175 The font-variant Property 181 The font-weight Property 183 The font-size Property 185 Absolute Font Sizes 185 Relative Font Sizes 187 Percentage Font Sizes 189 The font Shorthand Property 194 The font Properties 194 System Fonts 200 Summary 203 Exercises 203 Chapter 7: The Box Model 205 Overview 205 Margin 208 Margin Property with Four Values 209 Margin Property with Three Values 211 Margin Property with Two Values 213 Margin Property with One Value 214 Margin Collapsing 216 Horizontally Aligning Elements with the Margin Property 220 Borders 230 border-width 230 border-style 233 border-color 236 Border Shorthand Properties 236 Padding 242 Setting Dimensions 244 width 245 height 247
  • 20. xii Contents Auto Values for width and height 249 Percentage Measurements 255 Quirks Mode width and height in Internet Explorer 256 Minimum and Maximum Dimensions 259 Overflowing Content 271 CSS 3 overflow-x and overflow-y 273 Summary 273 Exercises 274 Chapter 8: CSS Buoyancy: Floating and Vertical Alignment 277 The float Property 277 Floating Box Model 282 The clear Property 293 Float Bugs in IE 6 298 The Peek-A-Boo Bug 298 The Guillotine Bug 300 The Three-Pixel Jog 303 The Double-Margin Bug 305 The vertical-align Property 306 Subscript and Superscript Text 307 The top, middle, and bottom Keywords 308 The text-top and text-bottom Keywords 310 Percentage and Length Value 311 Vertically Aligning the Contents of Table Cells 312 Summary 318 Exercises 319 Chapter 9: List Properties 321 The list-style-type Property 321 Styling Unordered Lists 322 Styling Ordered Lists 324 The list-style-image Property 330 The list-style-position Property 331 The list-style shorthand Property 333 Summary 337 Exercises 337 Chapter 10: Backgrounds 339 The background-color Property 339 The background-image Property 343
  • 21. xiii Contents The background-repeat Property 346 The background-position Property 350 Mixing Different Kinds of Position Values 352 Tiling and Position 354 The background-attachment Property 360 The background shorthand Property 365 Summary 369 Exercises 370 Chapter 11: Positioning 371 Introduction to Positioning 372 Absolute Positioning 372 Relative Positioning 381 Fixed Positioning 389 The z-axis and the z-index Property 428 The z-index Property with an Integer Value 430 Layering Nested Elements 433 The IE 6/IE 7 z-index Bug 434 Other Ways to Apply Positioning 441 Horizontally and Vertically Aligning Positioned Content 441 Multicolumn Layout 444 Summary 452 Exercises 452 Chapter 12: Tables 455 Optional Table Elements 455 Table Captions and the caption-side Property 457 Table Columns 459 Controlling Table Width with the table-layout Property 469 Removing Cell Spacing with the border-collapse Property 478 The border-spacing Property 479 Summary 484 Exercises 484 Part III: Advanced CSS and Alternative Media Chapter 13: Styling for Print 487 Applying Styles Based on Media 487 The @media Rule 491
  • 22. xiv Contents Controlling Page Breaks 497 Summary 500 Exercises 500 Chapter 14: XML 501 Crash Course in XML 502 Creating an XML Schema 505 The XML Declaration 510 The display Property 514 Styling Inline Elements with display: inline 515 Styling Block Elements with display: block 516 Styling List Items with display: list-item 517 Table Display Values 523 Other Display Values 534 Summary 535 Exercises 536 Chapter 15: The Cursor Property 537 Cursor Compatibility 538 Custom Cursors 540 Additional CSS Resources 542 Beginning CSS, Second Edition Online 542 Summary 542 Exercises 543 Appendix A: Answers to Exercises 545 Appendix B: CSS Reference 563 Appendix C: CSS Colors 593 Appendix D: Browser Rendering Modes 607 Index 611
  • 23. Acknowledgments As I wrote this book, so much has happened. Through the course of about 10 months, many people have been instrumental in making this happen, either directly or indirectly. I owe my success to all of you. I’d like to thank my boss at Trilithic, Karalee Slayton. I appreciate all the encouragement, understanding, and help you’ve given me along the way. And I have just one more thing to say, shhhhhhhhht! I’d like to thank Marybeth Fulmer, my colleague and friend. Thanks for always being willing to listen and help. I want to thank again, Jim Minatel from Wiley, for giving me the opportunity to write for Wrox again. Thanks for listening to all my wild ideas, and for being willing to take the risks on all the new things we’ve done with this book. A great big thanks to Brian MacDonald, my development editor. I appreciate your patience and under- standing, and you’ve been truly great to work with. This book owes much to your meticulous attention to every detail. I’d also like to thank my tech editor, Alexei Gorkov. Your incredible attention to detail has been a tremendous asset on this project. I want to thank my friends and family, who have been very supportive through some very difficult times: my aunt, Brenda; my uncle, Johnny; my cousins, Amanda, Kimberly, and Amy. Be strong, but don’t be afraid to talk about your son, your brother, and my cousin, Ryan. Let’s always keep in mind the good times, and the good things that happened, and not dwell on the bad. We can’t change what hap- pened, but we can keep his memory alive. Here’s to you. Here’s to me... I want to thank Richelle Brown. You are a truly awesomely good friend. As we enter the year of our Paul, 5AP, I’m very proud of all of your accomplishments as of late. Egg-cellent! Keep your nose up. Let’s find another Paul McCartney show so we can reset the Paul clock. Thanks to my parents, John and Tammy. Thanks for your help and support. I love you. And finally, I want to thank my best friend, Lisa Ratliff. I’m very sorry that I haven’t been there for you. I should have been. There are so many things that I should have said and done, but didn’t. I regret that we grew apart. Thanks for listening and thanks for understanding. Despite our ups and downs, you should know that I will always be here for you, and I will always love you. Snotface.
  • 25. Introduction Cascading style sheets (CSS) are the modern standard for website presentation. When combined with a structural markup language such as HTML, XHTML, or XML (though not limited to these), cascading style sheets provide Internet browsers with the information that enables them to present all the visual aspects of a web document. Cascading style sheets apply things such as borders, spacing between para- graphs, headings or images, control of font faces or font colors, background colors and images, textual effects such as underlined or strike-through text, layering, positioning, and a number of other presenta- tional effects. CSS controls the presentational aspects of a web page’s design, whereas HTML, XHTML, or XML controls the structure of a web page, which means little more than determining that certain text is a heading, other text is a paragraph, still other text is a list of hyperlinks, and so on. CSS provides enhanced and precise visual rendering; markup languages such as HTML provide meaning and structure. Beginning CSS: Cascading Style Sheets for Web Design, Second Edition covers all the details required to com- bine CSS with HTML, XHTML, or XML to create rich, aesthetically powerful designs. Throughout the book, I focus on combining CSS with XHTML specifically because XHTML is the standard hailed by Internet standards bodies as the successor to HTML and the present and future of website design. CSS and XHTML allow a web document to be presented with less code, resulting in a significantly smaller file size and greatly increased ease of maintenance. CSS also enables the presentation of a web document to be centralized, which allows for the look and feel of an entire website to be written and centralized in one or a few simple documents, which makes updating a website a breeze. With only a few simple edits to a single document, the look and feel of an entire website can be completely changed. By using modern standards like CSS and XHTML, you can drastically reduce the cost of building and maintaining a website when compared to legacy HTML-only pages. You can also greatly reduce the amount of physical bandwidth and hard disk space required, resulting in immediate long-term benefits for any website. In this book, I also discuss how to style XML documents with CSS — XML being a more advanced markup language with multipurpose applications. XML will play an increasingly larger role in the pro- duction of XHTML documents in the future. What’s New in the Second Edition This second edition of Beginning CSS features a near-complete overhaul of the content from the first edi- tion. I listened to what my readers had to say about the first edition and took that feedback to create the most comprehensive introduction on CSS available on the market. Throughout this book, you see CSS broken down into simple examples that focus on a single concept at a time. This allows you to better understand how and why something works, since you aren’t presented with a lot of irrelevant code, and you can better see the bits and pieces that come together that make something work. While these exam- ples may not be particularly pretty, they are extremely valuable learning tools that will help you master cascading style sheets.
  • 26. xviii Introduction To enhance the learning experience, I’ve presented most of the source code examples in syntax-colored code, a special feature in this book. Syntax coloring is a feature that you commonly see in fancy develop- ment software, such as Zend Studio (used to develop PHP), or Microsoft’s Visual Studio (used to develop ASP, C#, and so on), and other software used by professional programmers every day. Syntax coloring is used in these software suites to make programming easier and more intuitive, and I think that it offers tremendous benefits in teaching as well. It allows you to see what the different bits and pieces are in source code, since each of the different bits and pieces has a different coloring to identify its purpose. It helps you to distinguish the building blocks of code more easily, and if you use similar development software to write your CSS and HTML documents, you’ll also find that you make fewer mistakes and typos, since syntax coloring also helps you to write code that is more bug free. I’ve also added annotations to many of the source code examples to highlight important, not-to-be- forgotten bits of information, and to visually point out concepts that are discussed in the surrounding text. This edition also features every screenshot from a browser in color, a first for Wrox. Presenting the browser screenshots in color makes it easier for you to compare your results with what you see in the book. This book also approaches CSS development from a browser-neutral point of view, and provides all the information that you need to get a good healthy start on professional cross-browser, cross-platform web- site design with IE 6, IE 7, Firefox 2, Opera 9, and Safari 2, which will allow you to reach over 99 percent of the web browsing public. You also see comprehensive coverage of bugs, and workarounds for the IE 6 and IE 7 web browsers. Long a thorn in the side of CSS developers, making CSS work in IE 6 can be quite a chore without detailed knowledge of its quirks and shortcomings. I have covered throughout this book many of the hacks and nonstandard workarounds that you may need to develop compatible CSS content in IE 6. IE 7 features many great improvements to CSS support, and though they are much fewer than its predeces- sor, you still need a few tricks to make your web page shine in Microsoft’s latest browser. I have covered the workarounds that you’ll need to make your pages work just as well in IE 7 as they do in all the other popular browsers. In addition, you’ll find the quick reference in Appendix B updated to reflect all of IE 7’s new CSS support. Along with better coverage of Internet Explorer, I’ve also greatly improved coverage of Mac OS X browsers, Safari, Firefox, and Opera. You’ll see that Mac browsers are equally represented among their Windows brethren. I had so much new content that I’ve even written an additional chapter that will appear online, on the Wrox website, which you’ll be able to download for free. In this chapter I discuss additional workarounds for IE 6, and walk you through putting all of the knowledge that you’ve learned throughout the book together in a real-life web page. You can visit the book’s web page at: http://www.wrox.com/go/beginning_css2e The following sections tell you what Beginning CSS: Cascading Style Sheets for Web Design, Second Edition covers, whom this book is intended for, how it is structured, what equipment you need to use it, where you can go if you have a problem or question, and the conventions used in writing it.
  • 27. xix Introduction Whom Is This Book For? This book’s primary audience is anyone seeking to learn how to use cascading style sheets to present web documents. Because cascading style sheets are used to control the presentational layout of a web document, people from backgrounds in art, graphic design, or those who prepare print layouts for pub- lishing will feel at home using CSS. Regardless of your background, CSS is a simple and powerful lan- guage designed so that anyone can understand and use it. To get the most out of this book, you need some experience with markup languages like HTML or XHTML. If you are completely new to website design and development, I recommend you begin learn- ing web programming with Jon Duckett’s Beginning Web Programming with HTML, XHTML, and CSS. Jon Duckett’s book provides a complete overview of website development and design for the complete beginner, whereas Beginning CSS: Cascading Style Sheets for Web Design, Second Edition focuses specifically on the role of CSS in website design. Throughout this book, I present all of the material you need to become comfortable with writing CSS from scratch. What Does This Book Cover? This book covers portions of the CSS Level 1, 2, 2.1, and 3 specifications. These specifications are created by an independent, not-for-profit Internet standards organization called the World Wide Web Consortium (W3C) that plans and defines how Internet documents work. The majority of the book is written using what is defined in the CSS Level 2.1 specification. This book leads you through how to write CSS so that it is compatible with all of the most popular web browsers. I have focused on all of the following popular browsers: ❑ Microsoft Internet Explorer 6 for Windows ❑ Windows Internet Explorer 7 for Windows XP Service Pack 2, Windows Server 2003, Windows XP Professional 64 bit, and Windows Vista ❑ Safari 2 for Mac OS X 10.4 (Tiger) ❑ Mozilla Firefox 2 for Mac OS X, Windows, and Linux ❑ Opera 9 for Mac OS X, Windows, and Linux The preceding browsers make up over 99 percent of the web browser market share at the time of this writing. For your convenience, this book also includes an integrated CSS feature reference throughout the book, as well as notes on browser compatibility. A CSS reference is also included in Appendix B. How This Book Is Structured This book is divided into three parts. The following explains each of these three parts in detail, and what each chapter covers.
  • 28. xx Introduction Part I: The Basics Throughout Chapters 1 through 4 you learn the founding principles of CSS-based web design. ❑ Chapter 1, “Introducing Cascading Style Sheets”: In this first chapter, I talk about what CSS is, why it exists, who created it, where it is maintained, and how it has evolved. I also discuss some of the basic differences among the various CSS specifications—CSS Level 1, CSS Level 2, CSS Level 2.1, and CSS Level 3—and how these specifications define what CSS is. You also learn more about each of the most popular browsers in use today, how to obtain them, and write your first CSS-enabled document. I also show you how to install Internet Explorer 6 and Internet Explorer 7 side-by-side on the same computer for testing. ❑ Chapter 2, “The Essentials”: This chapter introduces the basics of CSS. Now that you have seen an example CSS document, this chapter introduces CSS rules and how selectors and declarations are combined to create rules. I demonstrate the various methods used to include CSS in a docu- ment. I explain how keywords are used in CSS to create predefined behavior, and how strings are used in CSS to refer to font names in a style sheet. I present the various units of measure- ment that CSS supports. Finally, I talk about the different ways of specifying color. ❑ Chapter 3, “Selectors”: Chapter 2 introduced the concept of selectors. In Chapter 3 I talk about complex selectors, and how you apply style to a portion of a document based on its context within the document or user-initiated events. ❑ Chapter 4, “The Cascade and Inheritance”: In Chapter 4, you learn about how to override styles, how precedence works in a style sheet, and how some styles can be considered more important than others, concepts that come together to define the cascade in cascading style sheets. You also learn how once you set some styles in a document, those styles can be inherited to other parts of a document depending on the context in which they are applied. Part II: Properties Throughout Chapters 5 through 12, you learn about properties that are used to manipulate the presenta- tion of a document. ❑ Chapter 5, “Text Manipulation”: In Chapter 5, I present the various properties that CSS pro- vides for text manipulation. These properties provide effects such as controlling the amount of space between the letters of words, controlling the amount of space between the words of a paragraph, controlling text alignment, underlining, overlining, or strike-through text. I also show how to control the case of text by making text all lowercase, uppercase, or capitalized. ❑ Chapter 6, “Fonts”: After you have seen the properties that CSS provides for text manipulation in Chapter 5, Chapter 6 presents the CSS properties you can use to manipulate the presentation of fonts. These effects include applying bold text, setting a font face, setting the font size, setting an italic font, as well as learning to use a property that enables you to specify all CSS’s font effects in one single property. ❑ Chapter 7, “The Box Model”: Chapter 7 elaborates on a design concept fundamental to CSS design: The Box Model. You learn how the box model plays an important role in determining layout dimensions. Using the margin, border, padding, width, and height properties, you can control how much space elements within a document occupy, how much space separates them, whether there are borders around them, whether scroll bars should be included. I also discuss a
  • 29. xxi Introduction CSS phenomenon known as margin collapsing, which is what happens when top or bottom margins come into direct contact with other top or bottom margins in a web document. ❑ Chapter 8, “CSS Buoyancy: Floating and Vertical Alignment”: In Chapter 8, I discuss float and clear, two properties used to control the flow of layout in a web document and often used to flow text beside images. I also discuss the vertical-align property, which is used to create effects like subscript or superscript text, as well as to control vertical alignment in table cells. ❑ Chapter 9, “List Properties”: In this chapter, I look at the properties CSS provides to control pre- sentation of ordered and unordered lists. This discussion includes the options CSS provides for predefined list markers, custom list markers, and the position of list markers. ❑ Chapter 10, “Backgrounds”: In Chapter 10, I present the properties CSS provides to control backgrounds in a web page. This includes properties that set a background color or background image, as well as those that control the position of a background, the tiling of a background, and whether a background remains fixed in place as a web page is scrolled or remains static. Finally, the chapter shows you how to use a property that combines all these individual effects into a single property. ❑ Chapter 11, “Positioning”: I discuss four different types of positioning: static, relative, absolute, and fixed. You use positioning primarily to layer portions of a document. I also describe some of the practical uses for positioning, such as creating a multicolumn layout. ❑ Chapter 12, “Tables”: In Chapter 12, I present the different properties that CSS provides for styling (X)HTML tables. The properties presented in this chapter let you control the spacing between the cells of a table, the placement of the table caption, and whether empty cells are ren- dered. I also look in detail at the available tags and options that (X)HTML provides for structur- ing tabular data. Part III: Advanced CSS and Alternative Media Throughout Chapters 13, 14, and 15 you learn about how to use CSS to make documents for printing, and another kind of document altogether, XML. ❑ Chapter 13, “Styling for Print”: In this chapter, I discuss what steps to take to use CSS to pro- vide alternative style sheets to create a printer-friendly version of a web document. ❑ Chapter 14, “XML”: In this chapter, I show how you can use CSS to style XML content. This chapter focuses specifically on the CSS display property and how you use this property to change the behavior of tags in an XML or HTML/XHTML document. ❑ Chapter 15, “The Cursor Property”: In this chapter, I show you how you can change the user’s mouse cursor using CSS, how you can customize the mouse cursor, and what browsers support which cursor features. ❑ Chapter 16, “Dean Edwards’s ‘IE7’”: In this chapter I talk about one alternative to many of the hacks and workarounds that you need for IE6. I talk about how to install an HTTP server for your website, and how to install and use Dean Edwards’s “IE7” JavaScript, which is a collection of IE6 hacks and workarounds designed to make “IE6” feature compatible with its successor. This chap- ter is available online only, on the Wrox website at www.wrox.com/go/beginning_css2e. ❑ Appendixes: Appendix A contains the answers to chapter exercises. Appendix B, “CSS Reference,” provides a place for you to look up CSS features and browser compatibility on
  • 30. xxii Introduction the fly. Appendix C, “CSS Colors,” provides a reference of CSS named colors. Appendix D, “Browser Rendering Modes,” provides a reference for the browser rendering modes invoked by the presence or absence of a Document Type Declaration (discussed in Chapter 7). What Do You Need to Use This Book? To make use of the examples in this book, you need the following: ❑ Several Internet browsers to test your web pages ❑ Text-editing software Designing content for websites requires being able to reach more than one type of audience. Some of your audience may be using different operating systems or different browsers other than those you have installed on your computer. This book focuses on the most popular browsers available at the time of this writing. I discuss how to obtain and install each of these browsers in greater detail in Chapter 1. The examples in this book also require that web page source code be composed using text-editing software. Chapter 1 also discusses a few different options for the text-editing software available on Windows or Macintosh operating systems. Conventions To help you get the most from the text and keep track of what’s happening, I’ve used a number of con- ventions throughout the book: Tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this. As for styles in the text: ❑ I highlight important words when I introduce them. ❑ I show keyboard strokes like this: Ctrl+A. ❑ I show URLs and code within the text in a special monofont typeface, like this: persistence .properties. ❑ I present code in the following two ways: In code examples, I highlight new and important code with a gray background. The gray highlighting is not used for code that’s less important in the present context, or has been shown before. Boxes like this one hold important, not-to-be-forgotten information that is directly relevant to the surrounding text.
  • 31. xxiii Introduction Source Code As you work through the examples in this book, you may choose either to type the code yourself or use the source code files that accompany the book. All the source code used in this book is available for download at www.wrox.com/go/beginning_css2e. When you arrive at the site, simply click the Download Code link on the book’s detail page to obtain all the source code for the book. Because many books have similar titles, you may find it easiest to search by ISBN; this book’s ISBN is 978-0-470-09697-0. After you download the code, just decompress it with your favorite compression tool. Alternatively, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books. Errata We make every effort to ensure that there are no errors in the text or in the code. However, no one is per- fect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece of code, we would be very grateful for your feedback. By sending in errata you may save another reader hours of frustration; at the same time, you will be helping us provide even higher quality information. To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the book details page, click the Book Errata link. On this page, you can view all errata that has been submitted for this book and posted by Wrox editors. A complete book list including links to each book’s errata is also available at www.wrox.com/misc-pages/booklist.shtml. If you don’t spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport .shtml and complete the form there to send us the error you have found. We’ll check the information and, if appropriate, post a message to the book’s errata page and fix the problem in subsequent editions of the book. p2p.wrox.com For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a web-based sys- tem for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums. At http://p2p.wrox.com you will find a number of different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps: 1. Go to p2p.wrox.com and click the Register link. 2. Read the terms of use and click Agree.
  • 32. xxiv Introduction 3. Complete the required information to join as well as any optional information you wish to pro- vide and click Submit. 4. You will receive an e-mail with information describing how to verify your account and com- plete the joining process. You can read messages in the forums without joining P2P; but, in order to post your own messages, you must join. After you join, you can post new messages and respond to messages other users post. You can read mes- sages at any time on the Web. If you would like to have new messages from a particular forum e-mailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing. For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to ques- tions about how the forum software works, as well as answers to many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.
  • 33. Part I The Basics Chapter 1: Introducing Cascading Style Sheets Chapter 2: The Essentials Chapter 3: Selectors Chapter 4: The Cascade and Inheritance
  • 35. 1 Introducing Cascading Style Sheets Cascading style sheets is a language intended to simplify website design and development. Put simply, CSS handles the look and feel of a web page. With CSS, you can control the color of text, the style of fonts, the spacing between paragraphs, how columns are sized and laid out, what back- ground images or colors are used, as well as a variety of other visual effects. CSS was created in language that is easy to learn and understand, but it provides powerful control over the presentation of a document. Most commonly, CSS is combined with the markup languages HTML or XHTML. These markup languages contain the actual text you see in a web page — the hyperlinks, paragraphs, headings, lists, and tables — and are the glue of a web docu- ment. They contain the web page’s data, as well as the CSS document that contains information about what the web page should look like, and JavaScript, which is another language that pro- vides dynamic and interactive functionality. HTML and XHTML are very similar languages. In fact, for the majority of documents today, they are pretty much identical, although XHTML has some strict requirements about the type of syntax used. I discuss the differences between these two languages in detail in Chapter 2, and I also pro- vide a few simple examples of what each language looks like and how CSS comes together with the language to create a web page. In this chapter, however, I discuss the following: ❑ The W3C, an organization that plans and makes recommendations for how the web should function and evolve ❑ How Internet documents work, where they come from, and how the browser displays them ❑ An abridged history of the Internet ❑ Why CSS was a desperately needed solution ❑ The advantages of using CSS
  • 36. The next section takes a look at the independent organization that makes recommendations about how CSS, as well as a variety of other web-specific languages, should be used and implemented. Who Creates and Maintains CSS? Creating the underlying theory and planning how cascading style sheets should function and work in a browser are tasks of an independent organization called the World Wide Web Consortium, or W3C. The W3C is a group that makes recommendations about how the Internet works and how it should evolve. I emphasize should, because the World Wide Web Consortium has no control over the implementation of the standards that it defines. The W3C is comprised of member companies and organizations that come together to create agreed-upon standards for how the web should function. Many prominent companies and organizations are W3C members, including Microsoft, Adobe, The Mozilla Foundation, Apple, Opera Software, and IBM. The W3C oversees the planning of several web languages including CSS, HTML, XHTML, and XML, all of which are mentioned in this book. CSS is maintained through a group of people within the W3C called the CSS Working Group. The CSS Working Group creates documents called specifications. When a specification has been discussed and officially ratified by W3C members, it becomes a recommendation. These ratified specifications are called recommendations because the W3C has no control over the actual implementation of the language. Independent companies and organizations create that software. The specifications created by the W3C are not limited only to web browsers; in fact, the specifications can be used in a variety of software, including word processor and spreadsheet applications, as well as by different types of hardware devices, such as PDAs and cell phones. For that reason, the software implementing a specification is referred to by the W3C as the user agent, which is a generic term that encompasses all the different types of software that implement W3C specifications. The W3C merely recommends that a language be implemented in a certain way to ensure that the lan- guage does what is intended no matter which operating system, browser, or other type of software is being used. The goal of this standardization is to enable someone using the Netscape browser, for example, to have the same Internet experience as someone using Internet Explorer, and likewise, for developers to have a common set of tools to accomplish the task of data presentation. Were it not for web standards, developing documents for the web might require an entirely different document for a given user agent. For example, Internet Explorer would require its own proprietary document format, while Mozilla Firefox would require another. Common community standards provide website develop- ers with the tools they need to reach an audience, regardless of the platform the audience is using. As I write this, CSS comes in four different versions, each newer version building on the work of the last. The first version is called CSS level 1, and became a W3C recommendation in 1996. The second version, CSS level 2, became a W3C recommendation in 1998. The third version, CSS level 2.1, is currently a working draft, downgraded from a candidate recommendation since I wrote the first edition of this book in 2004. A candidate recommendation is the status the W3C applies to a specification when it feels the specification is complete and ready to be implemented and tested. After the specification has been implemented and tested by at least a few of the member companies, the candidate recommendation is then more likely to become a full recommendation. A working draft is the status the W3C applies to an ongoing work, which is subject to change. The fourth version of CSS is called CSS level 3, and many por- tions of it are still in development. Although portions of CSS are officially subject to change by the W3C 4 Part I: The Basics
  • 37. standards body, I may discuss these features anyway if at least one browser maker has implemented the feature in question. I preface any such discussion with the warning that these features are still under development and could be subject to change. This book discusses the portions of CSS available in browsers at the time of this writing — that includes most of CSS 2 and CSS 2.1, and a little of CSS 3. Some portions of CSS 2.1 contradict CSS 2 and are not yet implemented in any browser. Where appropriate throughout the book and before introducing a new CSS feature, I reference the W3C specification in which that CSS feature is documented by including the phrase Documented in CSS followed by the version number. Later in this chapter, I discuss the browsers that you need to test and build CSS-enabled web documents. You can find the W3C website at www.w3.org. Go there to find documents that browser makers refer to when they are looking to implement languages such as CSS into a browser or other software. Be advised, these specifications lean heavily toward the technical side. They aren’t intended as documentation for people who use CSS; rather, they are aimed at those who write programs that interpret CSS. Despite the heavily technical nature of the W3C specification documents, many web developers refer to the W3C documents as end-user documentation anyway, since it is the most complete resource. Now that you know a little about who is responsible for planning and outlining the development of CSS, the next section describes how a web document makes its way into your browser. How the Internet Works As you probably already know, the Internet is a complex network of computers. Most of what goes on behind the scenes is of little interest to the person developing content for a website, but it is important to understand some of the fundamentals of what happens when you type an Internet address into your browser. Figure 1-1 shows a simple diagram of this process. At the top of the diagram in Figure 1-1, you see a computer labeled server-side and a computer labeled client-side. The diagram is by no means an exhaustive or complete picture of what happens when you type in an Internet address, but it serves the purpose of illustrating the portions of the process that the aspiring web designer needs to understand. The server-side computer houses the documents and data of the website and is generally always running so that the website’s visitors can access the website at any time of day. The client-side computer is, of course, your own computer. The server-side computer contains HTTP server software that handles all the incoming requests for web pages. When you type an Internet address into a browser, the browser sends out a request that travels through a long network of computers that act as relays for that request until the address of the remote (server-side) computer is found. After the request reaches the HTTP server, the HTTP server sees what it is you are trying to find, searches for the page on the server’s hard drive, and responds to the request you’ve made, sending the web page that you expect. That response travels back through another long chain of computers until your computer is found. Your browser then opens the response and reads what the HTTP server has sent back to it. If that server has sent an HTML document or another type of docu- ment that your browser can interpret, it reads the source code of that document and processes it into a displayable web page. 5 Chapter 1: Introducing Cascading Style Sheets
  • 38. Figure 1-1 This is where CSS enters the picture. If CSS is present in the document, the CSS describes what the HTML page should look like to the browser. If the browser understands the CSS, it processes the web page into something you can see and interact with. If the browser understands only some of the CSS, it generally ignores what it doesn’t understand. If the browser doesn’t understand CSS at all, it usually displays a plain-looking version of the HTML document. How CSS Came to Be During the mid-1990s, use of the Internet exploded. At that time, HTML was the only option for present- ing a web page. As the Internet began to be used by more regular folks (as opposed to government, edu- cational institutions, and researchers, as in the early days), users began demanding more control over the presentation of HTML documents. A great quandary arose — clearly HTML alone was not good enough to make a document presentable. In fact, not only was it not good enough, HTML alone simply wasn’t suited for the job. HTML did not have the functionality that professional publishing required and had no way of making magazine- or newspaper-like presentations of an electronic document. 5. HTTP server sends the web document. Server-side Client-side 6. Your browser receives the document. 7. Your browser processes the source code. 8. The browser displays the web page. 4. HTTP server looks up the web document. 3. HTTP server receives the request from the browser. 2. Browser contacts the HTTP server at that address. 1. You type a www address into the browser. 6 Part I: The Basics
  • 39. At the time, style sheets were not a new invention. In fact, style sheets were part of the plan from the beginning of HTML in 1990. Unfortunately, however, no standardized method of implementing style sheets was ever outlined, leaving this function up to the various browsers. In 1994, Tim Berners-Lee founded the World Wide Web Consortium, and a few days later, Håkon Wium Lie published his first draft of Cascading HTML Style Sheets. This draft was a proposal for how HTML documents could be styled using simple declarations. Of those that responded to Håkon’s draft of Cascading HTML Style Sheets was Bert Bos, who was work- ing on a style sheet proposal of his own. The two joined forces and came up with cascading style sheets. They dropped HTML from the title, realizing that CSS would be better as a general style sheet language, applicable to more than one type of document. CSS caused some controversy at its inception because part of the underlying fundamentals of the new style sheet language was that it created a balance between the browser’s style sheet, the user’s style sheet, and the author’s style sheet. Some simply didn’t like the idea that the user could have control over the presentation of a web document. Ultimately, however, the Internet community accepted CSS. Among CSS supporters was Microsoft, who pledged support for the new style sheet language in its Internet Explorer web browser. Netscape, on the other hand, another popular web browser at the time, remained skeptical about CSS and went forward with a style sheet language of its own called JavaScript Style Sheets, or JSSS. Ultimately, Netscape’s style sheets were not successful. Eventually, because of a series of bad decisions and setbacks on the part of Netscape as a whole and Netscape’s management, Netscape ultimately began losing market share, and Microsoft’s Internet Explorer (IE) browser grew more and more popular. At IE’s peak, it held 95 to 98 percent of the browser market share. Although IE has since lost market share to the likes of Mozilla Firefox and Safari, at the time of this writing, IE is still the dominant browser, most firms putting IE’s market share at 50 to 85 percent, depending on the web- site’s audience. Mainstream sites will see upward of 85 percent, but technical websites may see around 50 percent. Your own website’s browser statistics will depend largely on the content of your site. One such site to reference for statistics is http://www.upsdell.com/BrowserNews/stat.htm. However, keep in mind the quote, “There are lies, damn lies — and statistics” — Disraeli (later made famous by Mark Twain). During the time that CSS was being planned, browsers began allowing HTML features that control pre- sentation of a document into the browser. This change is the primary reason for much of the bloated and chaotic source code in the majority of websites operating today on the Internet. Even though HTML was never supposed to be a presentational language, it grew to become one. Unfortunately, by the time CSS level 1 was made a full W3C recommendation in 1996, the seed had already been planted. Presentational HTML had already taken root in mainstream website design and continues today. However, all is not lost. Today, the most popular browsers have fantastic support for cascading style sheets. Ironically, the browser exhibiting the least support is Microsoft’s Internet Explorer for Windows, which still has plenty of CSS support to do away with most presentational HTML design. More ironic still, among the browsers with the best CSS support is Netscape’s browser, and its open source offspring, Mozilla Firefox. This may beg the question: If Microsoft was such an avid supporter of cascading style sheets in the beginning, why is Microsoft’s browser the least standards-compliant today? The answer is that Microsoft did indeed follow through with its promise for CSS support, and it was the most compre- hensive and impressive implementation of CSS even up to the release of Internet Explorer 6 in 2001. Even so, CSS implementation in Internet Explorer has declined since the release of Internet Explorer 5. We can only speculate as to why Microsoft’s browser declined in its support for CSS. 7 Chapter 1: Introducing Cascading Style Sheets
  • 40. In the next section, I talk about the different types of browsers that you’ll need to work through the examples for this book. Browsers Because CSS is a standard web language, many browsers support it. Therefore, it stands to reason that the aspiring web designer would want to harness that standardization to reach the largest audience pos- sible, regardless of operating system or platform. In this section I provide an overview of each of these browsers, and where you can look to obtain a new version of that browser. Together, the following browsers combined comprise over 99 percent of the browser market share for the majority of websites in operation today: ❑ Internet Explorer 6 and 7 for Windows ❑ Mozilla Firefox for Windows, Mac, and Linux ❑ Opera for Windows, Mac, and Linux ❑ Safari for Mac OS X In the next section, I discuss Internet Explorer 6 and 7 for Windows. Internet Explorer Internet Explorer is Microsoft’s flagship browser that comes preloaded with the Windows operating sys- tem. The current stable version, as of this writing, is version 7. Internet Explorer 7 Late in 2004, after the first edition of this book was published, Microsoft finally began work on a new version of Internet Explorer. IE 7 includes stronger security, tabbed browsing, and other goodies for users, and for developers — improvements to IE’s support for CSS! IE 7 comes just over five years after the release of IE 6, which was released in 2001. IE 7 is a fantastic improvement over IE 6, but it still doesn’t quite meet the level of CSS present in competing browsers like Apple’s Safari browser, or Mozilla Firefox. Although it doesn’t exhibit the best CSS support, there is hope that future versions of IE will make significant progress in this area. Internet Explorer developers, and even Bill Gates, have publicly stated that Microsoft has returned to a more frequent release cycle for Internet Explorer, and we can expect new versions of Internet Explorer every year for the foreseeable future. Microsoft has even gone so far as to admit that it made a mistake by waiting too long to release a new version of IE. Even though IE 7 is finally here, it will be years still before it achieves sufficient market penetration that web developers can officially dump support for IE 6. Because of IE 6’s deficiencies, many are chomping at the bit for that time to come. In the meantime, we’ll have to continue to support it and work around its shortcomings. 8 Part I: The Basics
  • 41. IE 7 is available for the following operating systems: ❑ Windows XP Service Pack 2 ❑ Windows XP Pro 64-bit Edition ❑ Windows Server 2003 ❑ Windows Vista You can obtain IE 7 from Microsoft’s website at http://www.microsoft.com/ie. Internet Explorer 6 At the time of this writing Internet Explorer 6 is still the top dog with its browser market share between 50 and 85 percent, depending on the website’s audience (see my discussion of Internet Explorer’s market share in the section titled “How CSS Came to Be” earlier in this chapter). If you don’t already have IE 6, you can obtain it from http://www.microsoft.com/windows/ie/ie6/default.mspx. Installing Multiple Versions of Internet Explorer for Testing At the time of this writing, you cannot install IE 7 alongside IE 6 on the same copy of Windows. For development, you need a way to test IE 6 and IE 7 both, since you’ll have visitors to your website on both browsers. The following are a few ways to do this. ❑ Use PC virtualization/emulation software such as Virtual PC (a product made by Microsoft), which allows you to install and run different versions of Windows (or other operating systems, such as Linux) from within Windows or Mac OS X. Essentially, you can load up a new instance of Windows from your Windows desktop, and have that instance of Windows run in a window, independently. For example, Figure 1-2 shows a screenshot of me running Windows XP and IE 6 from my Mac OS X desktop, using the open source software Q, which lets me install and run Windows from within Mac OS X. ❑ Another option is setting up two different physical computers, one with IE 6 installed, and the other with IE 7. ❑ If you’re feeling particularly adventurous, you can set up two installations of Windows on the same computer, although for this discussion, this method is a bit too advanced for me to ade- quately cover here. If you’d like to learn more about installing Windows more than once on the same computer, more information about that can be found at http://www.microsoft.com/ windowsxp/using/setup/learnmore/multiboot.mspx. Figure 1-2 shows two instances of Windows XP running in Parallels Desktop for Mac; one is running IE 6, and the other is running IE 7. Most people prefer to keep it simple, and have all of their development tools at their fingertips. That makes the virtualization/emulation method the most attractive, in lieu of actually being able to install IE 6 alongside IE 7. I discuss this method in further detail in the next section. 9 Chapter 1: Introducing Cascading Style Sheets
  • 42. Figure 1-2 Installing Windows Using PC Virtualization/Emulation Software Today many companies make PC virtualization or emulation software, which allows you to run an entire operating system from a window on your desktop in the manner illustrated in Figure 1-2. More or less, it’s like having multiple computers all consolidated into one. You can boot up a virtual computer, with all default settings so you can test your web pages. Here are some of the titles available. 10 Part I: The Basics
  • 43. ❑ VMWare, Player: Available for free from http://www.vmware.com/products/player/ for Windows and Linux. ❑ Virtual PC: Made by Microsoft, available for $129 from http://www.microsoft.com/windows/ virtualpc (the price does not include a license for running Windows in the Virtual PC). Requires Windows or a PowerPC-based Mac. ❑ Q (pictured in Figure 1-2): Available for free from http://www.kberg.ch/q. If you’re using Mac OS X, Q is available as a universal application (it runs on both PowerPC-based and Intel- based Macs). ❑ Parallels: Available for $49.99 from http://www.parallels.com for Windows, Mac (PowerPC and Intel-based), and Linux. The best software for installing Windows from another operating system is software that uses virtualiza- tion. Without going into the technical details, software using virtualization runs much faster. The other, slower, much slower, in fact, method is emulation. Parallels and VMWare use virtualization, whereas, at the time of this writing, Microsoft’s Virtual PC and “Q” both use emulation. Your computer will also need serious horsepower to run two operating systems at the same time; see each respective website for the system requirements of each of the aforementioned solutions. In my experience, software like this works best with at least 1GB of RAM and about a 2 GHz processor. Without the ability to install and work with Windows virtually using software such as VMWare, your last resort is to uninstall IE 7 every time you need to test in IE 6, which can throw a pretty big wrench in the testing process. Currently, the virtual machine solution is the one officially sanctioned and recom- mended by Microsoft for testing in multiple versions of Internet Explorer. The IE team has responded to requests from web developers for the ability to install and run multiple versions of Internet Explorer side-by-side, and have said they are looking at the problem, but have not yet publicly announced a solu- tion or released software to remedy the problem. Internet Explorer for PowerPC Mac OS X For PowerPC Macintosh users, I recommend not using or testing in IE for Mac. The capabilities and bugs of IE for Windows and IE for Mac are very different. IE for the Macintosh has better support for CSS (compared to IE 6), but it is an entirely different browser. The name may be the same, but the browsers are very different. In fact, Microsoft has completely dropped support for IE for Mac, having stopped development with a public announcement made in 2003, and having completely stopped sup- port in 2005. It has less than a tenth of a percent of market share, if that much, and it does not run on Apple’s Intel-based Macs. For Mac users, I recommend Apple’s own Safari or a Gecko browser, such as Camino or Mozilla Firefox, which I discuss further in the coming sections. If you don’t have Internet Explorer for Windows, you still can work through most exercises and examples presented in this book, but if you are serious about web- site design, you will need to find a way to test your websites in Internet Explorer on Windows, since it has the majority of market share, and will enjoy that status far into the foreseeable future. For news on what is transpiring in the world of Internet Explorer development, you might like to check out the Internet Explorer Team’s blog at http://blogs.msdn.com/ie. New IE features and news of anything relating to Internet Explorer are announced on the IE Team blog. 11 Chapter 1: Introducing Cascading Style Sheets
  • 44. The Gecko Browsers: Mozilla Firefox, Netscape, Camino Gecko was created in January 1998. At that time, Netscape announced that it was making its browser free to its users and that its browser would be open source, meaning that its source code would be freely available for modification and distribution. This led to the creation of Mozilla; at the time Mozilla was the organization charged with developing and managing the Netscape code base. America Online later purchased Netscape, and until July 2003 Mozilla remained a part of Netscape. In July 2003, the Mozilla Foundation was created, making Mozilla an independent, not-for-profit corporation. When the Netscape browser became open source, its rendering engine, the part of the browser software responsible for mak- ing the source code of a web page into something you can see and interact with, was given the name Gecko. Gecko is the foundation that a whole suite of browsers relies on to do the behind-the-scenes work of ren- dering web pages. Gecko is included in AOL for Mac OS X, Camino, Netscape 6, Netscape 7, Netscape 8, Mozilla Suite, Mozilla Sea Monkey, and Mozilla Firefox. Netscape’s browser market share has greatly diminished, whereas Mozilla Firefox continues to gain in popularity, occupying the number-two spot at between 5 and 30% market share (again, depending on the website’s audience). Netscape’s (and other Gecko browsers, for that matter) market share is charted by most statistics at less than one percent. The following table shows the relationship between other Gecko browsers and Mozilla Firefox. This table illustrates the version of the underlying Gecko engine that each browser has in common with Firefox. Each of these browsers can be expected to render a web page identically and have the same capabilities in the area of CSS and document layout as the version of Firefox cited. Other Gecko Browser Firefox Netscape 8.1 Firefox 1.5 Netscape 8.0 Firefox 1.0 Netscape 7.2 Firefox 0.9 Camino 1.0 Firefox 1.5 SeaMonkey 1.0 (formerly Mozilla Suite) Firefox 1.5 Mozilla Suite 1.8 Firefox 1.0 Mozilla Suite 1.7 Firefox 0.9 Mozilla Suite 1.6 Firefox 0.8 Netscape 8.0 and 8.1 both feature the ability to switch between IE and Gecko for rendering a web page from within the Netscape browser, so essentially it is both Internet Explorer and Gecko in the same browser. The version of Internet Explorer in Netscape 8.0 and 8.1 is the same as the version of IE installed on the system. Netscape uses Gecko by default, but may try to “automatically” select the best rendering engine to use for a given website. 12 Part I: The Basics
  • 45. You can see that Firefox 0.9 and Mozilla Suite 1.7 can be expected to behave identically where CSS and design layout is concerned. Because gecko browsers share the same brain (and because of Firefox’s popularity), for the remainder of this book, I cite only Firefox when referring to a Gecko browser. Depending on which Gecko browser you happen to like, you can obtain Gecko browsers from the fol- lowing places: ❑ Mozilla Firefox for Windows, Mac, and Linux: Available from http://www.mozilla.com/ firefox ❑ Netscape for Windows: Available from http://www.netscape.com/download ❑ Camino for Mac: Available from http://www.caminobrowser.org/ ❑ SeaMonkey for Windows, Mac, and Linux: Available from http://www.mozilla.org/ projects/seamonkey/ Safari The next browser that I discuss is Safari, which is based on Konqueror, an open source browser available for Linux operating systems. The rendering engine used in the Safari and Konqueror web browsers is called KHTML. While Konqueror and Safari both have KHTML in common, Safari is a fork of KHTML (a fork means they shared the exact same source code at one point, but now each is developed indepen- dently), and features found in Safari may not necessarily appear in Konqueror and vice versa. Despite this, the two browsers render documents very similar to one another. Apple develops Safari, indepen- dently of Konqueror, and is the browser included with Macintosh OS X operating systems. Before Safari, Internet Explorer for Mac and Gecko had been dominant on the Mac. For the purpose of this book, I note Safari compatibility when appropriate. Safari is available only for Mac OS X and can be obtained from www.apple.com/safari. Konqueror is only available for Linux (and any operating system in which KDE, the K Desktop Environment, runs) at the time of this writing; it can be found at www.konqueror.org. Opera Opera is a lesser-known, Norwegian-based company. Opera users are fewer, accounting for only a few per- cent market share by most statistical estimates. Again, that figure can be much higher or lower depending on a website’s audience. Also be aware that Opera and Mozilla Firefox browsers can be configured to iden- tify themselves to a website as Microsoft Internet Explorer browsers. This, of course, can distort statistical analysis. This spoofing is done because websites often create content targeting Microsoft Internet Explorer and Netscape specifically, leaving everyone else out in the cold—even though third-party browsers like Mozilla Firefox and Opera probably support the required functionality. At the time of this writing, the current version of the Opera browser is 9.0. You can download this browser for free from www.opera.com. The Opera browser is available for Windows, Macintosh, Linux, and a variety of other platforms. 13 Chapter 1: Introducing Cascading Style Sheets
  • 46. Writing CSS To write CSS, just as is the case when writing HTML source, you will need a text editor. WYSIWYG (What You See Is What You Get) editors such as Microsoft Word aren’t ideally suited for CSS because the environment is not ideal for the composition of source code. WYSIWYG programs often have features like AutoCorrection and line wrapping; a plain text editor is more appealing precisely because it does not have these automatic features. Furthermore, the more automated WYSIWYG editors are designed to write the source code for you behind the scenes, so you don’t have complete control over the structure and formatting of the source code. In contrast, a plain text editor doesn’t insert anything into the source code beyond what you type into the text editor. The Windows Notepad program is one example of a text editor that is ideal for composing source code. To launch Notepad, choose Start ➪ Run and then type Notepad in the Open text box. You can also use Microsoft FrontPage, but FrontPage is best used in view source mode where you can edit the source code directly instead of via the WYSIWYG interface. The same holds true for Macromedia Dreamweaver. On Mac OS X, the Notepad equivalent is TextEdit, which can be found in the Mac OS X Applications folder. If Notepad or TextEdit is just too basic for your taste, a text editor that highlights markup and CSS syn- tax might suit your needs better. The following are full-featured alternative text editors for Windows: ❑ Crimson Editor: www.crimsoneditor.com (free) ❑ HTML-kit: www.chami.com/html-kit (free) Here are some alternative text editors that work with Mac OS X: ❑ CreaText: http://creatext.sourceforge.net (free) ❑ BBEdit: www.barebones.com (shareware) If you’re using Linux, you’re probably already familiar with the different text editors that come bundled with the various distributions. You must create HTML files with the .html extension. If you use Notepad or TextEdit, beware of your files being saved with a .txt extension, which will not result in the HTML file you were going for. To ensure that your files are saved properly on Windows, choose Start ➪ Run and type Explorer (or right-click Start and choose Explore from the pop-up menu) to open Windows Explorer. After Windows Explorer is open, choose Tools ➪ Folder Options to open the Folder Options window, click the View tab, and uncheck the Hide Extensions for Known File Types box (see Figure 1-3). Then click OK. HTML files are not the only file type in which the document extension is important; other file types require specific extensions as well. Those file types are covered later in this chapter. 14 Part I: The Basics
  • 47. Figure 1-3 On Mac OS X, open Finder, and go to Finder ➪ Preferences. Select the Advanced tab, and check the box for Show All File Extensions, which is depicted in Figure 1-4. Figure 1-4 Armed with a browser and a text editor, in the next section I present an example of what CSS can do. Your First CSS-Enabled Document The following example is designed to introduce you to what CSS is capable of. It is designed to help you get your feet wet and get straight down to the business of writing style sheets. 15 Chapter 1: Introducing Cascading Style Sheets
  • 48. You can find the images and source code for the following example at www.wrox.com. While you can obtain the source code from www.wrox.com, I recommend that you type out the example so that you can get used to writing the syntax, and take in the different bits that come together in the example. Try It Out Creating a CSS-Enabled Document Example 1-1. To write your first CSS-enabled document, follow these steps. 1. In your text editor of choice, enter the following markup: <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”> <html xmlns=’http://www.w3.org/1999/xhtml’ xml:lang=’en’> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8” /> <title>The Gas Giants</title> <link rel=’stylesheet’ type=’text/css’ href=’solar_system.css’ /> <script type=’text/javascript’> var fixpng = function($img) {}; </script> <!--[if lt IE 7]> <link rel=’stylesheet’ type=’text/css’ href=’solar_system.ie.css’ /> <script type=’text/javascript’> // This fixes PNG transparency in IE var fixpng = function($img) { var $html = ‘<span ‘ + (($img.id)? “id=’” + $img.id + “‘ “ : ‘’) + (($img.className)? “class=’” + $img.className + “‘ “ : ‘’) + (($img.title)? “title=’” + $img.title + “‘ “ : ‘’) + ‘style=”’ + ‘display: inline-block;’ + ‘width: ‘ + $img.width + ‘px;’ + ‘height: ‘ + $img.height + ‘px;’ + “filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(“ + “src=’” + $img.src + “‘, sizingMethod=’scale’); “ + $img.style.cssText + ‘“ ‘; if ($img.getAttribute(‘mouseoversrc’)) { $html += “mouseoversrc=’” + $img.getAttribute(‘mouseoversrc’) + “‘ “; } if ($img.getAttribute(‘mouseoutsrc’)) { $html += “mouseoutsrc=’” + $img.getAttribute(‘mouseoutsrc’) + “‘ “; } $html += ‘></span>’; $img.outerHTML = $html; 16 Part I: The Basics
  • 49. } </script> <![endif]--> </head> <body> <!-- Image reuse guidelines: http://www.nasa.gov/multimedia/guidelines/index.html --> <div id=’solar-system’> <div class=’planet jupiter’> <img src=’images/jupiter.png’ alt=’Jupiter’ class=’planet’ onload=’fixpng(this);’ /> <div class=’planet-copy’> <h1>Jupiter</h1> <ul> <li><b>Distance from the Sun:</b> 78,412,020 km</li> <li><b>Equatorial Radius:</b> 71,492 km</li> <li><b>Volume:</b> 1,425,500,000,000,000 km<sup>3</sup></li> <li><b>Mass:</b> 1,898,700,000,000,000,000,000,000,000 kg</li> <li> <a href=’http://solarsystem.jpl.nasa.gov/planets/profile.cfm?Object=Jupiter’> More Facts </a> </li> </ul> <img src=’images/symbols/jupiter.png’ alt=’Mythological Symbol for Jupiter’ onload=’fixpng(this);’ /> </div> </div> <div class=’planet saturn’> <img src=’images/saturn.png’ alt=’Saturn’ class=’planet’ onload=’fixpng(this);’/> <div class=’planet-copy’> <h1>Saturn</h1> <ul> <li><b>Distance from the Sun:</b> 1,426,725,400 km</li> <li><b>Equatorial Radius:</b> 60,268 km</li> <li><b>Volume:</b> 827,130,000,000,000 km<sup>3</sup></li> <li><b>Mass:</b> 568,510,000,000,000,000,000,000,000 kg</li> <li> <a href=’http://solarsystem.jpl.nasa.gov/planets/profile.cfm?Object=Saturn’> More Facts </a> </li> </ul> <img src=’images/symbols/saturn.png’ 17 Chapter 1: Introducing Cascading Style Sheets
  • 50. alt=’Mythological Symbol for Saturn’ onload=’fixpng(this);’ /> </div> </div> <div class=’planet uranus’> <img src=’images/uranus.png’ alt=’Uranus’ class=’planet’ onload=’fixpng(this);’ /> <div class=’planet-copy’> <h1>Uranus</h1> <ul> <li><b>Distance from the Sun:</b> 2,870,972,200 km</li> <li><b>Equatorial Radius:</b> 25,559 km</li> <li><b>Volume:</b> 69,142,000,000,000 km<sup>3</sup></li> <li><b>Mass:</b> 86,849,000,000,000,000,000,000,000 kg</li> <li> <a href=’http://solarsystem.jpl.nasa.gov/planets/profile.cfm?Object=Uranus’> More Facts </a> </li> </ul> <img src=’images/symbols/uranus.png’ alt=’Mythological Symbol for Uranus’ onload=’fixpng(this);’ /> </div> </div> <div class=’planet neptune’> <img src=’images/neptune.png’ alt=’Neptune’ class=’planet’ onload=’fixpng(this);’ /> <div class=’planet-copy’> <h1>Neptune</h1> <ul> <li><b>Distance from the Sun:</b> 4,498,252,900 km</li> <li><b>Equatorial Radius:</b> 24,764 km</li> <li><b>Volume:</b> 62,526,000,000,000 km<sup>3</sup></li> <li><b>Mass:</b> 102,440,000,000,000,000,000,000,000 kg</li> <li> <a href=’http://solarsystem.jpl.nasa.gov/planets/profile.cfm?Object=Neptune’> More Facts </a> </li> </ul> <img src=’images/symbols/neptune.png’ alt=’Mythological Symbol for Neptune’ onload=’fixpng(this);’/> </div> </div> </div> </body> </html> 18 Part I: The Basics
  • 51. Another Random Scribd Document with Unrelated Content
  • 52. containing a part of this work or any other work associated with Project Gutenberg™. 1.E.5. Do not copy, display, perform, distribute or redistribute this electronic work, or any part of this electronic work, without prominently displaying the sentence set forth in paragraph 1.E.1 with active links or immediate access to the full terms of the Project Gutenberg™ License. 1.E.6. You may convert to and distribute this work in any binary, compressed, marked up, nonproprietary or proprietary form, including any word processing or hypertext form. However, if you provide access to or distribute copies of a Project Gutenberg™ work in a format other than “Plain Vanilla ASCII” or other format used in the official version posted on the official Project Gutenberg™ website (www.gutenberg.org), you must, at no additional cost, fee or expense to the user, provide a copy, a means of exporting a copy, or a means of obtaining a copy upon request, of the work in its original “Plain Vanilla ASCII” or other form. Any alternate format must include the full Project Gutenberg™ License as specified in paragraph 1.E.1. 1.E.7. Do not charge a fee for access to, viewing, displaying, performing, copying or distributing any Project Gutenberg™ works unless you comply with paragraph 1.E.8 or 1.E.9. 1.E.8. You may charge a reasonable fee for copies of or providing access to or distributing Project Gutenberg™ electronic works provided that: • You pay a royalty fee of 20% of the gross profits you derive from the use of Project Gutenberg™ works calculated using the method you already use to calculate your applicable taxes. The fee is owed to the owner of the Project Gutenberg™ trademark, but he has agreed to donate royalties under this paragraph to the Project Gutenberg Literary Archive Foundation. Royalty
  • 53. payments must be paid within 60 days following each date on which you prepare (or are legally required to prepare) your periodic tax returns. Royalty payments should be clearly marked as such and sent to the Project Gutenberg Literary Archive Foundation at the address specified in Section 4, “Information about donations to the Project Gutenberg Literary Archive Foundation.” • You provide a full refund of any money paid by a user who notifies you in writing (or by e-mail) within 30 days of receipt that s/he does not agree to the terms of the full Project Gutenberg™ License. You must require such a user to return or destroy all copies of the works possessed in a physical medium and discontinue all use of and all access to other copies of Project Gutenberg™ works. • You provide, in accordance with paragraph 1.F.3, a full refund of any money paid for a work or a replacement copy, if a defect in the electronic work is discovered and reported to you within 90 days of receipt of the work. • You comply with all other terms of this agreement for free distribution of Project Gutenberg™ works. 1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™ electronic work or group of works on different terms than are set forth in this agreement, you must obtain permission in writing from the Project Gutenberg Literary Archive Foundation, the manager of the Project Gutenberg™ trademark. Contact the Foundation as set forth in Section 3 below. 1.F. 1.F.1. Project Gutenberg volunteers and employees expend considerable effort to identify, do copyright research on, transcribe and proofread works not protected by U.S. copyright
  • 54. law in creating the Project Gutenberg™ collection. Despite these efforts, Project Gutenberg™ electronic works, and the medium on which they may be stored, may contain “Defects,” such as, but not limited to, incomplete, inaccurate or corrupt data, transcription errors, a copyright or other intellectual property infringement, a defective or damaged disk or other medium, a computer virus, or computer codes that damage or cannot be read by your equipment. 1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for the “Right of Replacement or Refund” described in paragraph 1.F.3, the Project Gutenberg Literary Archive Foundation, the owner of the Project Gutenberg™ trademark, and any other party distributing a Project Gutenberg™ electronic work under this agreement, disclaim all liability to you for damages, costs and expenses, including legal fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE. 1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you discover a defect in this electronic work within 90 days of receiving it, you can receive a refund of the money (if any) you paid for it by sending a written explanation to the person you received the work from. If you received the work on a physical medium, you must return the medium with your written explanation. The person or entity that provided you with the defective work may elect to provide a replacement copy in lieu of a refund. If you received the work electronically, the person or entity providing it to you may choose to give you a second opportunity to receive the work electronically in lieu of a refund.
  • 55. If the second copy is also defective, you may demand a refund in writing without further opportunities to fix the problem. 1.F.4. Except for the limited right of replacement or refund set forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PURPOSE. 1.F.5. Some states do not allow disclaimers of certain implied warranties or the exclusion or limitation of certain types of damages. If any disclaimer or limitation set forth in this agreement violates the law of the state applicable to this agreement, the agreement shall be interpreted to make the maximum disclaimer or limitation permitted by the applicable state law. The invalidity or unenforceability of any provision of this agreement shall not void the remaining provisions. 1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation, the trademark owner, any agent or employee of the Foundation, anyone providing copies of Project Gutenberg™ electronic works in accordance with this agreement, and any volunteers associated with the production, promotion and distribution of Project Gutenberg™ electronic works, harmless from all liability, costs and expenses, including legal fees, that arise directly or indirectly from any of the following which you do or cause to occur: (a) distribution of this or any Project Gutenberg™ work, (b) alteration, modification, or additions or deletions to any Project Gutenberg™ work, and (c) any Defect you cause. Section 2. Information about the Mission of Project Gutenberg™
  • 56. Project Gutenberg™ is synonymous with the free distribution of electronic works in formats readable by the widest variety of computers including obsolete, old, middle-aged and new computers. It exists because of the efforts of hundreds of volunteers and donations from people in all walks of life. Volunteers and financial support to provide volunteers with the assistance they need are critical to reaching Project Gutenberg™’s goals and ensuring that the Project Gutenberg™ collection will remain freely available for generations to come. In 2001, the Project Gutenberg Literary Archive Foundation was created to provide a secure and permanent future for Project Gutenberg™ and future generations. To learn more about the Project Gutenberg Literary Archive Foundation and how your efforts and donations can help, see Sections 3 and 4 and the Foundation information page at www.gutenberg.org. Section 3. Information about the Project Gutenberg Literary Archive Foundation The Project Gutenberg Literary Archive Foundation is a non- profit 501(c)(3) educational corporation organized under the laws of the state of Mississippi and granted tax exempt status by the Internal Revenue Service. The Foundation’s EIN or federal tax identification number is 64-6221541. Contributions to the Project Gutenberg Literary Archive Foundation are tax deductible to the full extent permitted by U.S. federal laws and your state’s laws. The Foundation’s business office is located at 809 North 1500 West, Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up to date contact information can be found at the Foundation’s website and official page at www.gutenberg.org/contact
  • 57. Section 4. Information about Donations to the Project Gutenberg Literary Archive Foundation Project Gutenberg™ depends upon and cannot survive without widespread public support and donations to carry out its mission of increasing the number of public domain and licensed works that can be freely distributed in machine-readable form accessible by the widest array of equipment including outdated equipment. Many small donations ($1 to $5,000) are particularly important to maintaining tax exempt status with the IRS. The Foundation is committed to complying with the laws regulating charities and charitable donations in all 50 states of the United States. Compliance requirements are not uniform and it takes a considerable effort, much paperwork and many fees to meet and keep up with these requirements. We do not solicit donations in locations where we have not received written confirmation of compliance. To SEND DONATIONS or determine the status of compliance for any particular state visit www.gutenberg.org/donate. While we cannot and do not solicit contributions from states where we have not met the solicitation requirements, we know of no prohibition against accepting unsolicited donations from donors in such states who approach us with offers to donate. International donations are gratefully accepted, but we cannot make any statements concerning tax treatment of donations received from outside the United States. U.S. laws alone swamp our small staff. Please check the Project Gutenberg web pages for current donation methods and addresses. Donations are accepted in a number of other ways including checks, online payments and
  • 58. credit card donations. To donate, please visit: www.gutenberg.org/donate. Section 5. General Information About Project Gutenberg™ electronic works Professor Michael S. Hart was the originator of the Project Gutenberg™ concept of a library of electronic works that could be freely shared with anyone. For forty years, he produced and distributed Project Gutenberg™ eBooks with only a loose network of volunteer support. Project Gutenberg™ eBooks are often created from several printed editions, all of which are confirmed as not protected by copyright in the U.S. unless a copyright notice is included. Thus, we do not necessarily keep eBooks in compliance with any particular paper edition. Most people start at our website which has the main PG search facility: www.gutenberg.org. This website includes information about Project Gutenberg™, including how to make donations to the Project Gutenberg Literary Archive Foundation, how to help produce our new eBooks, and how to subscribe to our email newsletter to hear about new eBooks.
  • 59. Welcome to our website – the ideal destination for book lovers and knowledge seekers. With a mission to inspire endlessly, we offer a vast collection of books, ranging from classic literary works to specialized publications, self-development books, and children's literature. Each book is a new journey of discovery, expanding knowledge and enriching the soul of the reade Our website is not just a platform for buying books, but a bridge connecting readers to the timeless values of culture and wisdom. With an elegant, user-friendly interface and an intelligent search system, we are committed to providing a quick and convenient shopping experience. Additionally, our special promotions and home delivery services ensure that you save time and fully enjoy the joy of reading. Let us accompany you on the journey of exploring knowledge and personal growth! ebookultra.com