Professional Documents
Culture Documents
Textbook Css The Definitive Guide Visual Presentation For The Web 4Th Edition Eric A Meyer Ebook All Chapter PDF
Textbook Css The Definitive Guide Visual Presentation For The Web 4Th Edition Eric A Meyer Ebook All Chapter PDF
https://textbookfull.com/product/grid-layout-in-css-interface-
layout-for-the-web-1st-edition-eric-a-meyer/
https://textbookfull.com/product/interior-design-visual-
presentation-a-guide-to-graphics-models-and-presentation-
techniques-4th-edition-mitton/
https://textbookfull.com/product/fashion-the-definitive-visual-
guide-caryn-franklin/
https://textbookfull.com/product/php-for-the-web-visual-
quickstart-guide-5th-edition-larry-ullman/
The Complete Human Body The Definitive Visual Guide
Second Edition Alice Roberts
https://textbookfull.com/product/the-complete-human-body-the-
definitive-visual-guide-second-edition-alice-roberts/
https://textbookfull.com/product/modern-css-master-the-key-
concepts-of-css-for-modern-web-development-joe-attardi/
https://textbookfull.com/product/modern-css-master-the-key-
concepts-of-css-for-modern-web-development-joe-attardi-2/
https://textbookfull.com/product/cassandra-the-definitive-guide-
distributed-data-at-web-scale-2nd-edition-jeff-carpenter/
https://textbookfull.com/product/the-classic-car-book-the-
definitive-visual-history-1st-edition-giles-chapman/
1. 1. Basic Visual Formatting
1. Basic Boxes
1. A Quick Refresher
2. The Containing Block
2. Altering Element Display
1. Changing Roles
2. Block Boxes
3. Horizontal Formatting
4. Horizontal Properties
5. Using auto
6. More Than One auto
7. Negative Margins
8. Percentages
9. Replaced Elements
10. Vertical Formatting
11. Vertical Properties
12. Percentage Heights
13. Auto Heights
14. Collapsing Vertical Margins
15. Negative Margins and Collapsing
16. List Items
3. Inline Elements
1. Line Layout
2. Basic Terms and Concepts
3. Inline Formatting
4. Inline Nonreplaced Elements
5. Building the Boxes
6. Vertical Alignment
7. Managing the line-height
8. Scaling Line Heights
9. Adding Box Properties
10. Changing Breaking Behavior
11. Glyphs Versus Content Area
12. Inline Replaced Elements
13. Adding Box Properties
14. Replaced Elements and the Baseline
15. Inline-Block Elements
16. Run-in Elements
17. Computed Values
4. Summary
2. 2. Colors and Backgrounds
1. Colors
1. Foreground Colors
2. Affecting Borders
3. Affecting Form Elements
4. Inheriting Color
2. Backgrounds
1. Background Colors
2. Clipping the Background
3. Background Images
4. Background Positioning
5. Changing the Positioning Box
6. Background Repeating (or Lack Thereof)
7. Getting Attached
8. Sizing Background Images
9. Bringing It All Together
10. Multiple Backgrounds
3. Gradients
1. Linear Gradients
2. Radial Gradients
3. Manipulating Gradient Images
4. Repeating Gradients
4. Summary
3. 3. Floating and Shapes
1. Floating
1. Floated Elements
2. Floating: The Details
3. Applied Behavior
4. Floats, Content, and Overlapping
2. Clearing
3. Float Shapes
1. Creating a Shape
2. Shaping With Image Transparency
3. Adding a Shape Margin
4. Summary
4. 4. Grid Layout
1. Creating a Grid Container
2. Basic Grid Terminology
3. Placing Grid Lines
1. Fixed-Width Grid Tracks
2. Flexible Grid Tracks
3. Repeating Grid Lines
4. Grid Areas
4. Attaching Elements to the Grid
1. Using Column and Row Lines
2. Row and Column Shorthands
3. The Implicit Grid
4. Error Handling
5. Using Areas
6. Grid Item Overlap
5. Grid Flow
6. Automatic Grid Lines
7. The grid Shorthand
1. Subgrids
8. Opening Grid Spaces
1. Grid Gutters (or Gaps)
2. Grid Items and the Box Model
9. Aligning and Grids
1. Aligning and Justifying Individual Items
2. Aligning and Justifying All Items
10. Layering and Ordering
11. Summary
5. 5. Padding, Borders, Outlines, and Margins
1. Basic Element Boxes
1. Width and Height
2. Padding
1. Replicating Values
2. Single-Side Padding
3. Percentage Values and Padding
4. Padding and Inline Elements
5. Padding and Replaced Elements
3. Borders
1. Borders with Style
2. Border Widths
3. Border Colors
4. Shorthand Border Properties
5. Global Borders
6. Borders and Inline Elements
7. Image Borders
4. Outlines
1. Outline Styles
2. Outline Width
3. Outline Color
4. How They Are Different
5. Margins
1. Length Values and Margins
2. Percentages and Margins
3. Single-Side Margin Properties
4. Margin Collapsing
5. Negative Margins
6. Margins and Inline Elements
6. Summary
6. 6. Positioning
1. Basic Concepts
1. Types of Positioning
2. The Containing Block
2. Offset Properties
3. Width and Height
1. Setting Width and Height
2. Limiting Width and Height
4. Content Overflow and Clipping
1. Overflow
5. Element Visibility
6. Absolute Positioning
1. Containing Blocks and Absolutely Positioned Elements
2. Placement and Sizing of Absolutely Positioned Elements
3. Auto-edges
4. Placing and Sizing Nonreplaced Elements
5. Placing and Sizing Replaced Elements
6. Placement on the z-axis
7. Fixed Positioning
8. Relative Positioning
9. Sticky Positioning
10. Summary
7. 7. Table Layout in CSS
1. Table Formatting
1. Visually Arranging a Table
2. Table Display Values
3. Anonymous Table Objects
4. Table Layers
5. Captions
2. Table Cell Borders
1. Separated Cell Borders
2. Collapsing Cell Borders
3. Table Sizing
1. Width
2. Height
3. Alignment
4. Summary
8. 8. Transforms
1. Coordinate Systems
2. Transforming
1. The Transform Functions
3. More Transform Properties
1. Moving the Origin
2. Choosing a 3D Style
3. Changing Perspective
4. Dealing with Backfaces
4. Summary
9. 9. CSS Transitions and Animations
1. 12 Basic Principles of Animation
2. Animation and Transition Considerations
10. 10. Transitions
1. CSS Transitions
2. Fallbacks: Transitions Are Enhancements
3. Transition Properties
1. The transition-property Property
2. The transition-duration Property
3. The transition-timing-function Property
4. The transition-delay Property
5. The transition Shorthand Property
4. In Reverse: Transitioning Back to Baseline
5. Animatable Properties and Values
1. How Property Values Are Interpolated
2. Animatable Properties
3. transition Events Revisited
11. 11. Animation
1. Keyframes
2. Setting Up Your Keyframe Animation
3. Keyframe Selectors
1. Omitting from and to Values
2. Repeating Keyframe Properties
3. Animatable Properties
4. Nonanimatable Properties That Aren’t Ignored
5. Dynamically Changing @keyframes Animations
4. Animated Elements
1. The animation-name Property
2. The animation-duration Property
3. The animation-iteration-count Property
4. The animation-direction Property
5. The animation-delay Property
6. Animation Events
7. The animation-timing-function Property
8. The animation-play-state property
9. The animation-fill-mode Property
10. The animation Shorthand Property
5. Animation, Specificity, and Precedence Order
1. Specificity and !important
2. Animation Order
3. Animation Iteration and display: none;
4. Animation and the UI Thread
5. Seizure Disorders
6. Animation Events and Prefixing
1. animationstart
2. animationend
3. animationiteration
7. Other Considerations
1. Printing Animations
12. 12. CSS and Documents
1. A Brief History of (Web) Style
2. Elements
1. Replaced and Nonreplaced Elements
2. Element Display Roles
3. Bringing CSS and HTML Together
1. The link Tag
2. The style Element
3. The @import Directive
4. HTTP Linking
5. Inline Styles
4. Style Sheet Contents
1. Markup
2. Rule Structure
3. Whitespace Handling
4. CSS Comments
5. Media Queries
1. Usage
2. Simple Media Queries
3. Media Types
4. Media Descriptors
5. Media Feature Descriptors
6. New Value Types
6. Feature queries
7. Summary
13. 13. Fonts
1. Font Families
1. Using Generic Font Families
2. Specifying a Font Family
2. Using @font-face
1. Required Descriptors
2. Other Font Descriptors
3. Combining Descriptors
3. Font Weights
1. How Weights Work
2. Getting Bolder
3. Lightening Weights
4. Font Size
1. Absolute Sizes
2. Relative Sizes
3. Percentages and Sizes
4. Font Size and Inheritance
5. Using Length Units
6. Automatically Adjusting Size
5. Font Style
1. The font-style Descriptor
6. Font Stretching
1. The font-stretch Descriptor
7. Font Kerning
8. Font Variants
1. Level 3 Values
9. Font Features
1. The font-feature-settings Descriptor
10. Font Synthesis
11. The font Property
1. Adding the Line Height
2. Using Shorthands Properly
3. Using System Fonts
12. Font Matching
13. Summary
14. 14. Text Properties
1. Indentation and Horizontal Alignment
1. Indenting Text
2. Horizontal Alignment
3. Aligning the Last Line
2. Vertical Alignment
1. The Height of Lines
2. Vertically Aligning Text
3. Word Spacing and Letter Spacing
1. Word Spacing
2. Letter Spacing
3. Spacing and Alignment
4. Text Transformation
5. Text Decoration
1. Weird Decorations
6. Text Rendering
7. Text Shadows
8. Handling White Space
1. Setting Tab Sizes
9. Wrapping and Hyphenation
1. Wrapping Text
10. Text Direction
11. Summary
15. 15. Selectors
1. Basic Style Rules
1. Element Selectors
2. Declarations and Keywords
2. Grouping
1. Grouping Selectors
2. Grouping Declarations
3. Grouping Everything
3. Class and ID Selectors
1. Class Selectors
2. Multiple Classes
3. ID Selectors
4. Deciding Between Class and ID
4. Attribute Selectors
1. Simple Attribute Selectors
2. Selection Based on Exact Attribute Value
3. Selection Based on Partial Attribute Values
4. A Particular Attribute Selection Type
5. Using Document Structure
1. Understanding the Parent-Child Relationship
2. Descendant Selectors
3. Selecting Children
4. Selecting Adjacent Sibling Elements
5. Selecting Following Siblings
6. Pseudo-Class Selectors
1. Combining Pseudo-Classes
2. Structural Pseudo-Classes
3. Dynamic Pseudo-Classes
4. UI State Pseudo-Classes
5. The :target Pseudo-Class
6. The :lang Pseudo-Class
7. The Negation Pseudo-Class
7. Pseudo-Element Selectors
1. Styling the First Letter
2. Styling the First Line
3. Restrictions on ::first-letter and ::first-line
4. Styling (Or Creating) Content Before and After
Elements
8. Summary
16. 16. Specificity and the Cascade
1. Specificity
1. Declarations and Specificity
2. Universal Selector Specificity
3. ID and Attribute Selector Specificity
4. Inline Style Specificity
5. Importance
2. Inheritance
3. The Cascade
1. Sorting by Weight and Origin
2. Sorting by Specificity
3. Sorting by Order
4. Non-CSS Presentational Hints
4. Summary
17. 17. Values, Units, and Colors
1. Keywords, Strings, and Other Text Values
1. Keywords
2. Strings
3. URLs
4. Images
5. Identifiers
2. Numbers and Percentages
1. Integers
2. Numbers
3. Percentages
3. Distances
1. Absolute Length Units
2. Resolution Units
3. Relative Length Units
4. Calculation values
5. Attribute Values
6. Color
1. Named Colors
2. Colors by RGB and RGBa
3. Colors by HSL and HSLa
4. Bringing the Colors Together
7. Angles
8. Time and Frequency
9. Position
10. Summary
11. Color Equivalence Table
CSS: The Definitive Guide
4th Edition
Eric A. Meyer
CSS: The Definitive Guide
by Eric A. Meyer
While the publisher and the author(s) have used good faith efforts to
ensure that the information and instructions contained in this work
are accurate, the publisher and the author(s) disclaim all
responsibility for errors or omissions, including without limitation
responsibility for damages resulting from the use of or reliance on
this work. Use of the information and instructions contained in this
work is at your own risk. If any code samples or other technology
this work contains or describes is subject to open source licenses or
the intellectual property rights of others, it is your responsibility to
ensure that your use thereof complies with such licenses and/or
rights.
978-1-449-39319-9
[FILL IN]
Chapter 1. Basic Visual
Formatting
This book is all about the theoretical side of visual rendering in CSS.
Why is it necessary to spend an entire book (however slim) on the
theoretical underpinnings of visual rendering? The answer is that
with a model as open and powerful as that contained within CSS, no
book could hope to cover every possible way of combining properties
and effects. You will obviously go on to discover new ways of using
CSS. In the course of exploring CSS, you may encounter seemingly
strange behaviors in user agents. With a thorough grasp of how the
visual rendering model works in CSS, you’ll be able to determine
whether a behavior is a correct (if unexpected) consequence of the
rendering engine CSS defines, or whether you’ve stumbled across a
bug that needs to be reported.
Basic Boxes
At its core, CSS assumes that every element generates one or more
rectangular boxes, called element boxes. (Future versions of the
specification may allow for nonrectangular boxes, and indeed there
are proposals to change this, but for now everything is rectangular.)
Each element box has a content area at its center. This content area
is surrounded by optional amounts of padding, borders, outlines,
and margins. These areas are considered optional because they
could all be set to a width of zero, effectively removing them from
the element box. An example content area is shown in Figure 1-1,
along with the surrounding regions of padding, borders, and
margins.
Each of the margins, borders, and the padding can be set using
various side-specific properties, such as margin-left or border-
bottom, as well as shorthand properties such as padding. The outline,
if any, does not have side-specific properties. The content’s
background—a color or tiled image, for example—is applied within
the padding by default. The margins are always transparent,
allowing the background(s) of any parent element(s) to be visible.
Padding cannot have a negative length, but margins can. We’ll
explore the effects of negative margins later on.
bvfc 0101
Normal flow
Nonreplaced element
Replaced element
Root element
This is the element at the top of the document tree. In HTML
documents, this is the element html. In XML documents, it can
be whatever the language permits; for example, the root
element of RSS files is rss.
Block box
Inline box
Inline-block box
This is a box that is like a block box internally, but acts like an
inline box externally. It acts similar to, but not quite the same
as, a replaced element. Imagine picking up a div and sticking it
into a line of text as if it were an inline image, and you’ve got
the idea.
There are several other types of boxes, such as table-cell boxes, but
they won’t be covered in this book for a variety of reasons—not the
least of which is that their complexity demands a book of its own,
and very few authors will actually wrestle with them on a regular
basis.
The Containing Block
There is one more kind of box that we need to examine in detail,
and in this case enough detail that it merits its own section: the
containing block.
Every element’s box is laid out with respect to its containing block; in
a very real way, the containing block is the “layout context” for a
box. CSS defines a series of rules for determining a box’s containing
block. We’ll cover only those rules that pertain to the concepts
covered in this book in order to keep our focus.
In this very simple markup, the containing block for the p element’s
block box is the div element’s block box, as that is the closest
ancestor element box that is a block or a list item (in this case, it’s a
block box). Similarly, the div’s containing block is the body’s box.
Thus, the layout of the p is dependent on the layout of the div,
which is in turn dependent on the layout of the body element.
And above that, the layout of the body element is dependent on the
layout of the html element, whose box creates what is called the
initial containing block. It’s a little bit unique in that the viewport—
the browser window in screen media, or the printable area of the
page in print media—determines its dimensions, not the size of the
content of the root element. It’s a subtle distinction, and usually not
a very important one, but it does exist.
Altering Element Display
You can affect the way a user agent displays by setting a value for
the property display. Now that we’ve taken a close look at visual
formatting, let’s consider the display property and discuss two more
of its values using concepts from earlier in the book.
display
Initial
inline
value:
Inherited: No
We’ll ignore the table-related values, since they’re far too complex
for this text, and we’ll also ignore the value list-item since it’s very
similar to block boxes. We’ve spent quite some time discussing block
and inline boxes, but let’s spend a moment talking about how
altering an element’s display role can alter layout before we look at
inline-block and run-in.
Changing Roles
When it comes to styling a document, it’s obviously handy to be able
to change the type of box an element generates. For example,
suppose we have a series of links in a nav that we’d like to lay out as
a vertical sidebar:
<nav>
<a href="index.html">WidgetCo Home</a>
<a href="products.html">Products</a>
<a href="services.html">Services</a>
<a href="fun.html">Widgety Fun!</a>
<a href="support.html">Support</a>
<a href="about.html" id="current">About Us</a>
<a href="contact.html">Contact</a>
</nav>
We could put all the links into table cells, or wrap each one in its
own nav—or we could just make them all block-level elements, like
this:
nav a {display: block;}
This will make every a element within the navigation nav a block-
level element. If we add on a few more styles, we could have a
result like that shown in Figure 1-2.
bvfc 0102
Changing display roles can be useful in cases where you want non-
CSS browsers to get the navigation links as inline elements but to lay
out the same links as block-level elements. With the links as blocks,
you can style them as you would div or p elements, with the
advantage that the entire element box becomes part of the link.
Thus, if a user’s mouse pointer hovers anywhere in the element box,
she can then click the link.
You may also want to take elements and make them inline. Suppose
we have an unordered list of names:
<ul id="rollcall">
<li>Bob C.</li>
<li>Marcio G.</li>
<li>Eric M.</li>
<li>Kat M.</li>
<li>Tristan N.</li>
<li>Arun R.</li>
<li>Doron R.</li>
<li>Susie W.</li>
</ul>
Given this markup, say we want to make the names into a series of
inline names with vertical bars between them (and on each end of
the list). The only way to do so is to change their display role. The
following rules will have the effect shown in Figure 1-3:
#rollcall li {display: inline; border-right: 1px solid;
padding: 0 0.33em;}
#rollcall li:first-child {border-left: 1px solid;}
bvfc 0103
Be careful to note, however, that you are changing the display role
of elements—not changing their inherent nature. In other words,
causing a paragraph to generate an inline box does not turn that
paragraph into an inline element. In XHTML, for example, some
elements are block while others are inline. (Still others are “flow”
elements, but we’re ignoring them right now.) An inline element can
be a descendant of a block element, but the reverse is not true.
Thus, while a span can be placed inside a paragraph, a span cannot
be wrapped around a paragraph. This will hold true no matter how
you style the elements in question. Consider the following markup:
<span style="display: block;">
<p style="display: inline;">this is wrong!</p>
</span>
The markup will not validate because the block element (p) is nested
inside an inline element (span). The changing of display roles does
nothing to change this. display has its name because it affects how
the element is displayed, not because it changes what kind of
element it is.
With that said, let’s get into the details of different kinds of boxes:
block boxes, inline boxes, inline-block boxes, list-item boxes, and
run-in boxes.
Block Boxes
Block boxes can behave in sometimes predictable, sometimes
surprising ways. The handling of box placement along the horizontal
and vertical axes can differ, for example. In order to fully understand
how block boxes are handled, you must clearly understand a number
of boundaries and areas. They are shown in detail in Figure 1-4.
bvfc 0104
box-sizing
Inherited: No
Computed
As specified
value:
This property is how you change what the width and height values
actually do. If you declare width: 400px and don’t declare a value for
box-sizing, then the element’s content box will be 400 pixels wide;
any padding, borders, and so on will be added to it. If, on the other
hand, you declare box-sizing: border-box, then it will be 400 pixels
from the left outer border edge to the right outer border edge; any
border or padding will be placed within that distance, thus shrinking
the width of the content area. This is illustrated in Figure 1-5.
bvfc 0105
It has been well said—I think by the man who wrote the sub-titles
for “Cage-Birds of Society” (began the Oldest Member)—that wealth
does not always bring happiness. It was so with Bradbury Fisher, the
hero of the story which I am about to relate. One of America’s most
prominent tainted millionaires, he had two sorrows in life—his
handicap refused to stir from twenty-four and his wife disapproved of
his collection of famous golf relics. Once, finding him crooning over
the trousers in which Ouimet had won his historic replay against
Vardon and Ray in the American Open, she had asked him why he
did not collect something worth while, like Old Masters or first
editions.
Worth while! Bradbury had forgiven, for he loved the woman, but
he could not forget.
For Bradbury Fisher, like so many men who have taken to the
game in middle age, after a youth misspent in the pursuits of
commerce, was no half-hearted enthusiast. Although he still
occasionally descended on Wall Street in order to pry the small
investor loose from another couple of million, what he really lived for
now was golf and his collection. He had begun the collection in his
first year as a golfer, and he prized it dearly. And when he reflected
that his wife had stopped him purchasing J. H. Taylor’s shirt-stud,
which he could have had for a few hundred pounds, the iron seemed
to enter into his soul.
The distressing episode had occurred in London, and he was now
on his way back to New York, having left his wife to continue her
holiday in England. All through the voyage he remained moody and
distrait; and at the ship’s concert, at which he was forced to take the
chair, he was heard to observe to the purser that if the alleged
soprano who had just sung “My Little Grey Home in the West” had
the immortal gall to take a second encore he hoped that she would
trip over a high note and dislocate her neck.
Bradbury Fisher looked out upon a world that swam and danced
before his eyes. He had not been prepared for this sort of thing. The
way things were shaping, he felt that it would hardly surprise him
now if the cups were to start jumping up and snapping at Bott’s ball
like starving dogs.
“Three up,” said Gladstone Bott.
With a strong effort Bradbury Fisher mastered his feelings. His
mouth set grimly. Matters, he perceived, had reached a crisis. He
saw now that he had made a mistake in allowing himself to be
intimidated by the importance of the occasion into being scientific.
Nature had never intended him for a scientific golfer, and up till now
he had been behaving like an animated illustration out of a book by
Vardon. He had taken his club back along and near the turf, allowing
it to trend around the legs as far as was permitted by the movement
of the arms. He had kept his right elbow close to the side, this action
coming into operation before the club was allowed to describe a
section of a circle in an upward direction, whence it was carried by
means of a slow, steady, swinging movement. He had pivoted, he
had pronated the wrists, and he had been careful about the lateral
hip-shift.
And it had been all wrong. That sort of stuff might suit some
people, but not him. He was a biffer, a swatter, and a slosher; and it
flashed upon him now that only by biffing, swatting, and sloshing as
he had never biffed, swatted, and sloshed before could he hope to
recover the ground he had lost.
Gladstone Bott was not one of those players who grow careless
with success. His drive at the eighth was just as steady and short as
ever. But this time Bradbury Fisher made no attempt to imitate him.
For seven holes he had been checking his natural instincts, and now
he drove with all the banked-up fury that comes with release from
long suppression.
For an instant he remained poised on one leg like a stork; then
there was a whistle and a crack, and the ball, smitten squarely in the
midriff, flew down the course and, soaring over the bunkers, hit the
turf and gambolled to within twenty yards of the green.
He straightened out the kinks in his spine with a grim smile.
Allowing himself the regulation three putts, he would be down in five,
and only a miracle could give Gladstone Bott anything better than a
seven. “Two down,” he said some minutes later, and Gladstone Bott
nodded sullenly.
It was not often that Bradbury Fisher kept on the fairway with two
consecutive drives, but strange things were happening to-day. Not
only was his drive at the ninth a full two hundred and forty yards, but
it was also perfectly straight.
“One down,” said Bradbury Fisher, and Bott nodded even more
sullenly than before.
There are few things more demoralising than to be consistently
outdriven; and when he is outdriven by a hundred and seventy yards
at two consecutive holes the bravest man is apt to be shaken.
Gladstone Bott was only human. It was with a sinking heart that he
watched his opponent heave and sway on the tenth tee; and when
the ball once more flew straight and far down the course a strange
weakness seemed to come over him. For the first time he lost his
morale and topped. The ball trickled into the long grass, and after
three fruitless stabs at it with a niblick he picked up, and the match
was squared.
At the eleventh Bradbury Fisher also topped, and his tee-shot,
though nice and straight, travelled only a couple of feet. He had to
scramble to halve in eight.
The twelfth was another short hole; and Bradbury, unable to curb
the fine, careless rapture which had crept into his game, had the
misfortune to over-shoot the green by some sixty yards, thus
enabling his opponent to take the lead once more.
The thirteenth and fourteenth were halved, but Bradbury, driving
another long ball, won the fifteenth, squaring the match.
For a man with anything on his mind, any little trouble calculated to
affect the joie de vivre, there are few spots less cheering than the
Customs sheds of New York. Draughts whistle dismally there—now
to, now fro. Strange noises are heard. Customs officials chew gum
and lurk grimly in the shadows, like tigers awaiting the luncheon-