McGraw Hill - Cascading Style Sheets 2.0 Programmers Reference (2001).pdf

(2485 KB) Pobierz
Microsoft Word - Document1
32006673.001.png
Cascading Style Sheets 2.0 Programmer's Reference
Cascading Style Sheets 2.0 Programmer’s Reference
Eric A. Meyer
Osborne/ McGraw-Hill
2600 Tenth Street
Berkeley, California 94710
U.S.A.
To arrange bulk purchase discounts for sales promotions, premiums, or fund-raisers, please contact
Osborne/ McGraw-Hill at the above address. For information on translations or book distributors outside
the U.S.A., please see the International Contact Information page immediately following the index of this
book.
Cascading Style Sheets 2.0 Programmer’s Reference
Copyright © 2001 by The McGraw-Hill Companies. All rights reserved. Printed in the United States of
America. Except as permitted under the Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a database or retrieval system,
without the prior written permission of the publisher, with the exception that the program listings may be
entered, stored, and executed in a computer system, but they may not be reproduced for publication.
1234567890 DOC DOC 01987654321
ISBN 0-07-213178-0
Publisher
Brandon A. Nordin
Vice President & Associate Publisher
Scott Rogers
Acquisitions Editor
Jim Schachterle
Project Editor
Madhu Prasher
Acquisitions Coordinator
Tim Madrid
Copy Editor
Mike McGee
Proofreader
Paul Tyler
Indexer
Claire Splan
Computer Designers
Tara Davis and Lucie Ericksen
Illustrator
Michael Mueller
Series Design
Peter F. Hancik
This book was composed with Corel VENTURA™ Publisher.
Information has been obtained by Osborne/ McGraw-Hill from sources believed to be reliable. However,
because of the possibility of human or mechanical error by our sources, Osborne/ McGraw-Hill , or
others, Osborne/ McGraw-Hill does not guarantee the accuracy, adequacy, or completeness of any
information and is not responsible for any errors or omissions or the results obtained from use of such
information.
To my wife, Kathryn, and a secluded dance
under a starry California sky
About the Author
Eric A. Meyer has been working with the Web since late 1993. After six years as campus Webmaster at
Case Western Reserve University, he joined The OPAL Group ( www.theopalgroup.com ) , an information
technology consulting firm in Cleveland, Ohio, which is a much nicer city than you might have heard.
Eric is an invited expert with the W3C’s CSS Working Group, and coordinated the creation of the CSS
Test Suite for the W3C ( www.w3.org ). As of this writing, he is author of three highly popular HTML
tutorials, three books, and dozens of articles on CSS and Web design. Eric also teaches CSS classes
online and gives talks at various conferences and seminars. Anyone with an ear for early 20 th -century
swing and jazz is invited to check out his show, “Your Father’s Oldsmobile,” which is heard weekly on
WRUW 91.1-FM in Cleveland ( www.wruw.org ). When not otherwise busy, Eric is usually bothering his
wife Kathryn in some fashion.
1
 
Cascading Style Sheets 2.0 Programmer's Reference
Table of Contents
Cascading Style Sheets 2.0 Programmer’s Reference - 1
Part I Reference
Chapter 1 - Basic CSS Concepts - 3
Chapter 2 - Values - 18
Chapter 3 - Selectors, Pseudo-Classes, Pseudo-Elements, and At-Rules - 24
Chapter 4 - Visual Media Styles - 35
Chapter 5 - Paged Media Styles - 124
Chapter 6 - Aural Media Styles - 134
Part II Summaries
Chapter 7 - Browser Compatibility - 151
Chapter 8 - CSS2 Quick Reference - 165
Chapter 9 - Useful Resources - 172
2
Introduction - 3
Cascading Style Sheets 2.0 Programmer's Reference
Introduction
In the beginning, there was HTML. And it was pretty good, but not great. You couldn’t really create nifty
visual designs with it, which gave rise to table-based layout and single-pixel GIF tricks. And that was
pretty bad. So CSS was born, and it was very good—in theory, anyway. There was a long struggle to
make CSS a viable technology, thanks to imperfect interpretations of the specification, but lo! The day
arrived when CSS could be used without fear and dread. And the people rejoiced.
Thanks to CSS, designers can cut back on the FONT and table tricks they’ve been forced to cobble
together, and dramatically clean up their markup. With the coming of XHTML and XML, both of which
are deeply semantic and must rely on some styling mechanism to become visually appealing, CSS is
growing more and more popular. It’s a flexible, easy-to-understand language which offers designers a
lot of power. Because it reduces markup clutter, it makes pages easier to maintain. And its centralized
styling abilities lets designers adjust page layout with quick, easy edits of the styles, not dramatic
changes to the markup. In fact, CSS makes it possible to completely reshape the look of a document
without changing a single character inside the BODY element.
This book endeavors to efficiently describe the properties and values of CSS2, which was the latest
CSS standard when the book was written, and to provide details on property interactions, common
authoring mistakes, and other information which designers should find useful.
The text has been arranged to present basic concepts first, with details on important CSS algorithms
and behaviors ( Chapter 1 ). This is followed with “core” information which describes the types of values
that can be used in CSS2 ( Chapter 2 ), and the various ways in which elements can be selected for
styling ( Chapter 3 ) . This first part of the book does its best to describe the foundation of CSS, for the
rest of it would not function without the values and concepts presented.
The middle of the book (Chapters 4 through 6) is the largest portion, and is probably the area where
readers will spend the most time—all of the properties found in CSS2 are defined, described, and
annotated with notes. These properties are broken up into separate chapters, with Chapter 4 devoted to
visual-media properties, Chapter 5 to paged-media properties, and Chapter 6 to aural-media properties.
Each property is described in terms of its allowed values, its initial (or default) value, and other common
aspects. There are also detailed descriptions of the meaning of each allowed value, notes about how
the property works, examples of the property in use, and a list of related properties.
The final part of the book (Chapters 7 through 9) contains other useful information about CSS, including
a browser support chart, a CSS2 property quick reference, and a list of useful online resources.
Between the contents of this book and the resources provided, it should be possible to decipher any
CSS conundrums you may encounter. Although CSS can sometimes seem a bit mystifying, it is more
than worth the effort of learning its secrets. Enjoy!
Part I: Reference
Chapter List
Chapter 1: Basic CSS Concepts
Chapter 2: Values
Chapter 3: Selectors, Pseudo-Classes, Pseudo-Elements, and At-Rules
Chapter 4: Visual Media Styles
Chapter 5: Paged Media Styles
Chapter 6: Aural Media Styles
Chapter 1: Basic CSS Concepts
In order to comprehend how CSS affects the presentation of a document, there are some key concepts
that must be grasped. Once these are understood, even in part, it becomes easier to see how the
properties and values of CSS work. Do not, however, feel that you must completely understand
everything in this chapter before experimenting with CSS. In fact, it is better to review this chapter first,
then refer back to it as properties are used.
3
32006673.002.png
Cascading Style Sheets 2.0 Programmer's Reference
Associating Styles with Documents
There are four ways to associate styles with a document. These range from associating a separate
stylesheet with your document to embedding style information in the document itself.
LINK Element
The LINK element is found in HTML and XHTML, and is used to associate an external stylesheet with a
document.
Generic Syntax
<link rel="..." type="text/css" href="..." media="...">
Attributes
rel=“...”
This attribute describes the relation of the LINKed file to the document itself. For external stylesheets,
there are two possible values: stylesheet and alternate stylesheet . Any LINK with a rel of
stylesheet will be used in the styling of the document. The value alternate stylesheet is used
to refer to stylesheets that are not used in the default rendering of the document, but which can, in
theory, be selected by the user and thus change the presentation. The user agent must provide a
mechanism to do so in order for this to work, and unfortunately most user agents do not provide such a
mechanism. This attribute is required .
href=“...”
The value of this attribute is the URL of the external stylesheet. Either relative or absolute URLs may be
used. This attribute is required .
type=“text/css”
This is used to declare the type of data which is being LINKed to the document. When associating a
CSS stylesheet, the only allowed value is text/css . Other stylesheet languages will call for different
values (e.g., text/xsl ). This attribute is required .
media=“...”
Using this attribute, one can declare a stylesheet to apply only to certain media. The default value is
all , which means that the styles will be used in all media in which the document is presented.
Recognized values under CSS are all , screen , print , projection , aural , braille , embossed ,
handheld , tty , and tv . Any number of these values can be used in a media attribute by formatting
them as a comma-separated list. This attribute is optional.
Note
Examples
<link rel="stylesheet" type="text/css"
href="http://www.my.site/styles/basic.css">
<link rel="stylesheet" type="text/css" href="article.css"
media="screen,projection">
<link rel="stylesheet" type="text/css" href="printout.css"
media="print">
STYLE Element
The STYLE element is found in HTML and XHTML, and is used as a container for an embedded
stylesheet.
Generic Syntax
<style type="text/css" media="...">
Attributes
type=“text/css”
This attribute is handled the same as that used on the LINK element. This attribute is required .
4
In this approach, the stylesheet is placed in its own file. Such files are usually
given an extension of .css, such as main-styles.css. The LINK element must be
placed inside the HEAD element in HTML and XHTML, but XML-based markup
languages may have other requirements.
32006673.003.png
Zgłoś jeśli naruszono regulamin