Speaking in Styles - Fundamentals of CSS For Web Designers
Speaking in Styles - Fundamentals of CSS For Web Designers
Compositor:
Jason Cranford Teague Notice of Rights
Marketing Manager: All rights reserved. No part of this book may be reproduced or transmitted in any
Glenn Bisignani form by any means, electronic, mechanical, photocopying, recording, or other-
wise, without the prior written permission of the publisher. For information on
Indexer: Emily getting permission for reprints and excerpts, contact permissions@peachpit.com.
Glossbrenner
Cover and Interior
Designer: Notice of Liability
Jason Cranford Teague The information in this book is distributed on an “As Is” basis without warranty.
Cover Production: While every precaution has been taken in the preparation of the book, neither the
Andreas DeDanaan author nor Peachpit shall have any liability to any person or entity with respect
to any loss or damage caused or alleged to be caused directly or indirectly by the
instructions contained in this book or by the computer software and hardware
products described in it.
Trademarks
Many of the designations used by manufacturers and sellers to distinguish their
products are claimed as trademarks. Where those designations appear in this
book, and Peachpit was aware of a trademark claim, the designations appear as
requested by the owner of the trademark. All other product names and services
identified throughout this book are used in editorial fashion only and for the
benefit of such companies with no intention of infringement of the trademark.
No such use, or the use of any trade name, is intended to convey endorsement or
other affiliation with this book.
Printed and bound in the United States of America
ISBN 13: 978-0-321-57416-9
ISBN 10: 0-321-57416-8
987654321
Printed and bound in the United States of America
In Memory of
&
Thanks…
Tara
Johnny
8 L ayou t . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Head and Body . . . . . . . . . . . . . . . . . . . . . . . . 210
The HTML Framework for CSS . . . . . . . . . . . . . . 212
Adding CSS . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Default Styles . . . . . . . . . . . . . . . . . . . . . . . . 216
Resetting Browser Default Styles . . . . . . . . . . . . 216
Setting Your Default Styles . . . . . . . . . . . . . . . . 216
The Grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Rows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
11 C hrome . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Using Transparent Images . . . . . . . . . . . . . . 258
Fixing Transparent PNGs in IE6 . . . . . . . . . . . . . 260
Defining the Grid. . . . . . . . . . . . . . . . . . . . . . 262
Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Rows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
Logos and Forms . . . . . . . . . . . . . . . . . . . . . 266
Logos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Defining Sections . . . . . . . . . . . . . . . . . . . . . 268
Alternate Version for Ads. . . . . . . . . . . . . . . . . . 268
Final Flourishes . . . . . . . . . . . . . . . . . . . . . . . . 270
B B : CSS Va lu es . . . . . . . . . . . . . . . . . .303
Lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
Pixels or Ems? . . . . . . . . . . . . . . . . . . . . . . . . . 304
Fonts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Color Opacity . . . . . . . . . . . . . . . . . . . . . . . . . . 310
In d ex . . . . . . . . . . . . . . . . . . . . . . . . . . . .324
This page intentionally left blank
Introduction
To design is to
communicate clearly by
whatever means you can
control or master.
— Milton Glaser
Design is a way to communicate ideas visually. Unlike speaking or
writing, however, visual communication happens almost instanta-
neously on a visceral level. Within seconds of seeing something,
we should be able to understand its visual message. Obviously
some designs such as illustrations may take additional decipher-
ing, but when we look at something we can’t help trying to inter-
pret its meaning.
Introduction
Verbalizing the Visual
I want you to think of a shape. It can be any shape you want—a
circle, a square, a triangle, an eight-pointed star, or an ameboid
glob—but keep it to a single continuous shape. I want you to
hold that shape in your mind, or, if you need to, scratch it out on
a piece of paper (or, if you are really far gone) on a computer.
Now I want you to think about how you would describe the
shape without making reference to any shape. You can use “line,”
but not any shape names.
Let’s say you draw a simple square. You might describe a square
like this:
Draw four lines the same length that touch, two horizontally and
two vertically.
What is needed is a language that you can use to quickly and pre-
cisely describe your designs in such a way that the computer will
understand them without fault. That language is called Cascading
Style Sheets (CSS), and it is a language you need to master to be
a successful Web designer.
Why CSS?
Cascading Style Sheets (CSS) is the language you use to tell
computers how you want your designs to look on the Web.
With CSS, you can specify details including widths, heights,
colors, margins, padding, borders, backgrounds, and type styles.
Understanding this language, then, becomes critical to achieving
the best online designs.
The good news is that speaking CSS is not that different from
speaking in English or any other “human” language—it just
takes a little adjustment to get used to its particular syntax (how
things are said), semantics (what things mean), and vocabulary
(what to say).
For example, consider this simple design:
The border is solid red and 5 pixels thick; the background is pink;
there is a 25 pixel padding around the content; the font is Arial at 8
pixels; and the text is double spaced.
Appendixes
Includes all of the code for Part 3; the length, font, and color
values you use with CSS; and a list of common fixes for deal-
ing with the bugs in Internet Explorer.
Reading the Code
I have tried to simplify the examples as much as possible, keeping
code and the results of that code as close as possible on the page.
This often means that the full context of the code is not given.
Content in code
HTML code
CSS code
JavaScript code
Code references in the text will look like (01-03), and the refer-
enced code will always be on the same page or on the page imme-
diately to the right.
Safari Sa 3, 4
Opera Op 8, 9, 10
Chrome Ch 1, 2
PART 1
In which the reader will learn about the three core components of a Web page,
discover the tools needed to construct one, and uncover the truth about many
17 Web De s ig ne r ’s To o lb ox
35 T he My t hs of CSS
A Web Primer
Take a look behind a Web page, any Web page, and you’ll find
that it’s a combination of just three types of code: HTML, CSS,
and JavaScript. Regardless of what happens between your com-
puter (the client) and the computer that is holding the informa-
tion about that page (the server), those three technologies are
what the browser combines to get the job done and deliver the
content to the screen (text, images, video, or animation).
Web pages are a little closer to the code than most designers are
used to. Unlike Photoshop and Illustrator, where the code is
never seen, with a Web page we can get in and play around with
it, which is exactly what we will need to do if we want to get the
exact visual results we desire.
CHAPTER 1
What is a web page?
A WE B PR IM ER
WHAT IS A W EB PAG E ?
Speaking in Styles
s pe a k i ng - i n- s ty l e s . c om
2
HTML CSS
Structure Presentation
DOCUMENT
Functionality
JavaScript
3
A WE B PR IM ER
WHAT IS A W EB PAG E ?
Each of the three core Web technologies has its own role to play
in that map:
Web technologies.
4
HTML CSS
De nes Objects Styles Objects
DOM
Document Object Model
Changes Objects
JavaScript
5
A WE B PR IM ER
WHAT IS A W EB PAG E ?
<h1>Welcome</h1>
6
HTML
<h1> Welcome</h1>
h1 { color : red; }
CSS
7
A WE B PR IM ER
WHAT IS A W EB PAG E ?
CSS Genesis
Hypertext Markup Language (HTML), which let him display his research
papers on the Internet with basic styles, such as underline, bold, and italic,
and link these documents into a kind of “web” of documents. At first, all he
wanted was to be able to display text and link relevant content together,
the ability to embed images in the page was added in the first graphics-
Originally, tags were used in HTML documents not only to structure the
document, but to add the styles—so you had bold tags (<b>…</b>) and
italics tags (<i>…</i>) and so forth. This meant the styles were locked into
More and more tags were added to deal with styling documents, but it
was quickly realized that having the styles and the structure together was
unworkable. Håkon Wium Lie and Bert Bos proposed using an existing
technology called style sheets to allow designers to control how the HTML
8
AllofUs
a l l ofu s . c om
9
A WE B PR IM ER
WHAT IS A W EB PAG E ?
The scripts are used mostly to control elements on the page as the
user interacts with them—showing menus, checking that form
data has been entered correctly, and that sort of thing. But the
capabilities of JavaScript have grown over the years so that it is
now possible to create full-blown Web-enabled applications.
h1 { color: rgb(255,0,0);}
Many sites allow users to choose the color scheme they see
while at the site. One way to make this change would be to use
JavaScript to dynamically change the color property:
object.style.color=rgb(153,51,41);
In this code, the variable object stands in for the object we want
to make style changes to. It is derived from the DOM path to the
<h1> tags. The full JavaScript code for finding the object would
be something like:
object=document.getElementByTagName('h1');
This tells the JavaScript to find the header level-1 tags in the
document so that we can make changes to their styles. There are
many ways to find the objects on the page to make changes to
them, but this is a book about CSS, not JavaScript, so we’ll leave
it at that for now.
10
CSS
h1 { color: rgb(255,0,0); }
object.style.color=rgb(153,51,41)
JavaScript
11
A WE B PR IM ER
WHAT I S A WE B PAG E ?
K n o w Yo u r C o d e : J a v a S c r i p t
Generally speaking, designers rarely have to look at, much less create,
and CSS after the page has loaded. This can include making style
changes, dynamic elements like menus and pop-ups, and special effects
mation back and forth between the loaded Web page and the server
without having to reload the entire page. This allows the user to interact
JavaScript Object Notation, or JSON (yes, it’s pronounced like my name, but
I had nothing to do with it) is a quick and easy way for JavaScript to trans-
fer data that’s easier to use and understand than alternatives like XML.
MooTools, jQuery, and Dojo Toolkit are all popular JavaScript libraries that
provide ready-built functionality that takes a lot of the grunt work out of
and animations. Although there is some overlap, each library has its own
strengths and weaknesses, and each has its loyal followers in the Web
developing your own Web site, I recommend checking these libraries out
12
Krista’s Creations at Letter-
Photo
letter-photo.com
13
A WE B PR IM ER
WHAT IS A W EB PAG E ?
Just like CSS with HTML, using CSS with Flash can save you a
lot of time when your client tells you two days before the site is
supposed to launch that they don’t want to use green hypertext
links because green is an unlucky color (yes, this has happened to
me). Without CSS, Flash will embed styles directly into the .swf
file, making them difficult to change on a large scale. Imagine try-
ing to change all of your link colors if you had to open dozens of
individual Flash files! With CSS, you can change a single line of
code to update your entire site to the new color.
Causecast
c a u s ec a s t. c om
14
15
All artists have a tool set that they know and rely upon. Sculptors
choose the best chisels; painters choose the best brushes; cal-
ligraphers choose the best pens. Likewise, Web designers need to
choose the best tools at their disposal not only to visualize their
designs but to also create them in their medium of choice, the
Web browser. The tools you choose will not make you a better
designer, but they can help you make better designs.
CHAPTER 2
Web Designer’s
Toolbox
A WE B P RI ME R
WE B D ESI GNER’ S TO O L B OX
Web Browsers
What browser do you use to surf the Web? Some people have a
favorite browser. Some choose based on their job. Others simply
use the default browser on their machine and may never be aware
that other options exist. Regardless of your personal preference,
however, your designs will need to work on all of the most com-
mon browsers. To compound the issue, when a new version of a
browser is released, older versions do not magically disappear (IF
ONLY!), so you also have to test on legacy browsers.
Panic Software
p a n i c. c om
Web tools.
18
Browser
Differences
19
A WE B P RI ME R
WE B D ESI GNER’ S TO O L B OX
Firefox (FF)
Mac, Windows, and Unix/Linux
fi re fox . co m
20
Safari (Sa)
Mac and Windows
apple. co m/ saf a r i
Opera (Op)
Mac, Windows, and Unix
o pera. co m
21
A WE B P RI ME R
WE B D ESI GNER’ S TO O L B OX
One of the hardest issues to deal with on the Mac is how to test
your designs in IE6, which is still very popular and only available
for Windows. One great and inexpensive solution is a program
called Crossover, which allows you to run many Windows appli-
cations directly on your Mac desktop without having to own or
install Windows on your machine. Currently, it does not support
IE 7 or 8, which is a shame, but these two browsers have fewer
page-rendering inconsistencies than their predecessor.
roughly equivalent.
22
Layout Engines:
The Power Under the Browser Hood
Think of a browser like it’s a car: What you see is just the shell around the
engine, which is what makes the car move. You can take the engine out
layout engines (also called rendering engines) that drive how the browser
displays Web pages. Although there are different layout engines, many
browsers use the same engine, but with a different interface around it.
For example, Firefox uses the open-source rendering engine Gecko, and
so does Camino, Netscape, and Flock. They each add their own user
interface on top, though. All browsers using the same rendering engine
will all display Web pages about the same way. There may be slight varia-
tions, depending on which version of the rendering engine was used and
whether any tweaks were made to it—just like a car engine that has been
KHTML and WebKit Safari, Google Chrome, Shiira, OmniWeb, iCab, Konquerer
23
A WE B P RI ME R
WE B D ESI GNER’ S TO O L B OX
Firefox Add-Ons
Firefox makes a great development browser, not only because it
has strong standards compliance, is available for Mac, Windows,
and Unix/Linux, and is the second most commonly used
browser, but also because you can install a variety of add-ons,
small programs that run within the browser, to enhance its capa-
bilities. Here are a few of my favorites:
Firebug
a ddo ns . moz illa . o rg / fi re fox / 1 8 4 3
Colorzilla
a ddo ns . moz illa . o rg / fi re fox / 271
Allows you to sample the color of any pixels in the Web browser,
displaying the value in both hex and RGB values. Simply choose
the eyedropper, then click a pixel. You can then copy and paste
the color code into another application as needed.
24
Selected element
25
A WE B P RI ME R
WE B D ESI GNER’ S TO O L B OX
Palette Grabber
a ddo ns . moz illa . o rg / fi re fox / 2 2 9 0
Grab all of the color values out of a Web site’s CSS and turn
them into a working color palette for Photoshop and other pro-
grams with Palette Grabber. All it takes is a single click to save
a palette, then you can load it into your favorite image editing
software to start working.
MeasureIt
a ddo ns . moz illa . o rg / fi re fox / 5 3 9
Have you ever had something on the screen and you needed to
find its size? Or noticed that the alignment of two objects wasn’t
quite right but weren’t sure by how much? Then MeasureIt is
the tool for you. You click an icon, select the area width and
height you want to measure, and MeasureIt displays the dimen-
sions in pixels, taking out a lot of the guesswork when precision
is your goal.
Pixel Perfect
a ddo ns . moz illa . o rg / fi re fox / 7 9 4 3
If you like your sites to look exactly like your visual comps, you’ll
need Pixel Perfect. This is actually an add-on to Firebug (an add-
on to an add-on) that allows you to load a a JPEG version of your
visual comp as an onion skin over the top of the live version to
compare your vision to the reality on the Web.
26
Firefox Add-Ons
a d don s . m oz i l l a . or g
27
A WE B P RI ME R
WE B D ESI GNER’ S TO O L B OX
Code Editors
Just as you have a word processor for writing or an illustration
program for drawing, you need a Web development program for
coding. A good code editor will:
» Organize and edit documents, providing suggestions where
needed.
» Preview documents without having to jump between mul-
tiple browsers.
» Download and upload documents as you work on them.
» Analyze and optimize your code.
Coda
Mac
p ani c. c om/ c od a /
TopStyle
Windows
n ew sg ato r. co m / i nd i vi d u a l s / top st y l e
28
CSSEdit
Mac
macrabbit . co m / cs se di t /
Dreamweaver
Windows and Mac
ado be. co m/ dr e a mwe aver
29
A WE B P RI ME R
WE B D ESI GNER’ S TO O L B OX
Online Tools
We typically think of an application as something that you get
on a disk or download and then install onto your computer.
Increasingly, applications are being delivered through the Web,
without requiring you to install or download the specific applica-
tion. Some of the best tools in my arsenal aren’t on my desktop;
they’re online. The line between Web site and Web application (or
just Web app) is gradually being blurred. Like you do with a Web
site, you get to a Web app by using a Web browser and URL, but
Web apps provide functionality like you would expect from
a traditional application.
30
31
A WE B P RI ME R
WE B D ESI GNER’ S TO O L B OX
Typetester
t ypete ste r. or g
SUMO Paint
s u mo pain t. c om
32
33
Over the years, many different myths and misconceptions have grown
up around Cascading Style Sheets—some good and some bad. You may
have heard some of these myths and may still believe them: CSS is com-
puter code; CSS is buggy; CSS is only for styling type and color. Some
of these myths were never true, others are no longer true, and some have
a grain of truth. Before we go any further into learning how to speak in
styles, let’s clear the air about three of the most persistent CSS myths.
CHAPTER 3
The Myths of CSS
A WE B PR IM ER
THE M Y T H S O F CS S
Myth 1:
CSS Is for Developers, Not Designers
False: Many designers coming to CSS for the first time think
that it’s just for the “coders” and not for “real” designers. I hear
this a lot from designers: “I don’t want to learn to program a
computer.” Designers who buy this line of reasoning have three
basic arguments:
36
CSS is for Web Developers, Not Web Designers
CSS is a
style language
anyone can learn to
read and write.
TRUTH
37
A WE B PR IM ER
THE M Y T H S O F CS S
designshack.co.uk/gallery/
38
Web Designer Michela Chiucini
c o l a z i o n e d a m i c hy. i t
39
A WE B PR IM ER
THE M Y T H S O F CS S
Myth 2:
CSS Can’t Handle the Designs I Need
Most designers who believe the myth that CSS can’t handle a
variety of layouts are usually from the old school of Web design,
when the only option for creating a grid-based layout was by
using HTML tables. Yes, tables can do some things that CSS still
cannot do—like creating balanced column heights, although that
will be possible in the future— but the advantages of designing
with CSS far outweigh the advantages of table-based layout. The
techniques that designers use today are vastly different from those
we used just a few years ago. As we’ve had a chance to explore the
capabilities of CSS, new ideas and new methods are constantly
being explored.
40
CSS
CS
CSS Can’t
Can
an’’tt Handle
Hand
an
nddlle the
the Designs
D
Des
Dee iiggn
nss I N
Need
ee
ee
TRUTH
41
A WE B PR IM ER
THE M Y T H S O F CS S
42
CSS Zen Garden
c ss z e n g a r d e n . c om
CSS Zen Garden has a simple mission: Prove that CSS can
handle any layout. Each of these designs was created from the
43
A WE B PR IM ER
THE M Y T H S O F CS S
Myth 3:
CSS Has Too Many Browser Inconsistencies
Every browser has its own quirks when it comes to CSS, but it’s
Microsoft’s Internet Explorer that deviates the most from the
straight and narrow path of Web standards.
That doesn’t mean you can ignore the older versions, but you do
not always have to provide the same experience. Instead, designers
will create a usable but stripped-down design for IE6. The design
still works just fine; it just may not have all of the design bells
and whistles.
44
CSS Still
tillll Has
ti Has Too
Tooo Many
T Maan
ny Browser
Bro
rwwse
seer Inconsistancies
Incon
In on
nsi
siissta
tan
7
6
TRUTH
45
PART 2
In which the reader learns the syntax (how the language is put together),
49 Synt a x
89 Sema nt ic s
123 Vo cabu l a r y
CSS Grammar
Syntax is how you put words together to create meaning:
Punctuation and parts of speech are placed in a specific order
to describe something. How you combine these elements has a
direct effect on the meaning of what you are trying to communi-
cate. To describe your Web designs, you need to understand the
syntax of CSS.
CHAPTER 4
Syntax
Creating Meaning
CSS G RAM MA R
SYN TAX
Let’s keep it simple for now, and start by looking at how we cre-
ate a basic style for the header level 1 HTML tag <h1>. CSS
rules begin with a selector, which is what is being defined, fol-
lowed by a declaration or list of declarations between curly brack-
ets to define the selector’s style.
UGSMAG
u g sm a g . co m
50
Selector Declaration
h1 { color: red; }
Curly Brackets
51
CSS G RAM MA R
SYN TAX
52
Subject
Verb
Object
Selector Colon
Property
53
CSS G RAM MA R
SYN TAX
h1 { color: red }
In this case, color refers to the text color and red is a predefined
keyword that the browser translates into an actual color value.
We could also use the RGB scale:
h1 { color: rgb(255,0,0) }
h1 { color: #ff0000 }
These all say the same thing: The first-level header’s text color is
red. In English this is called a declarative sentence. In CSS this is
called a CSS rule or selector declaration.
You are declaring style properties for the selector, in this case
the h1 selector, which effects the <h1> tag. There are three types
of selectors in CSS. The one shown here is an HTML selector
because it corresponds to a specific HTML tag. We will learn
about class and ID selectors a bit later in this chapter.
54
The level 1 header's text color is red.
h1 { color : red }
h1 { color : rgb(255,0,0) }
h1 { color : #ff0000}
55
CSS G RAM MA R
SYN TAX
The level 1 header’s color is red, the font family is Georgia, and
the font size is 24px.
Why? Because one day you will make a change to that CSS rule.
You will add another declaration at the end of the list and you
will forget to add the semicolon to the previous line, and your
style will simply stop working. You will spend hours trying to
figure out why your styles are not working only to discover it was
because you forgot to add one stupid semicolon. How do I know
this? I have spent far too many hours of my life banging my head
against my keyboard trying to figure out why my styles aren’t
working, all because of a missing semicolon. Learn from my mis-
takes: Always include the semicolon after every declaration.
56
The level 1 header's text color is red, the font
family is Georgia, and the font size is 24px.
h1 {
color : red;
font-family: Georgia; Semicolons
font-size: 24px;
}
57
CSS G RAM MA R
SYN TAX
Combining Rules
What happens when the same styles are being applied to different
selectors? For example, what if you want all of your headers to
be red? You could create three different style rules, one for each
header level:
Now the first three header levels will be red. Besides saving a lot
of space, which is important once your CSS files start getting
large, this also has the advantage of putting all of the selectors
that use this value into a single place, making it easier to change
later. For example, if your boss or client decides they want green
headers instead of red, rather than changing the value in three
places, you only have to change it once:
58
The level 1, level 2, and level 3 header's text
color is red.
59
CSS G RAM MA R
SYN TAX
Types of Selectors
So far, you’ve only seen one kind of selector: the HTML selec-
tor. This allows you to specify how any HTML tag on the page
should be styled. If all you could do was style HTML tags and all
of the paragraphs looked the same, and all of the level 2 headers
looked the same, and all of the lists looked the same, and so forth,
your designs would look pretty boring. You need ways to selec-
tively style HTML tags with CSS.
For example, you might have your level 2 headers look one way
when in the main text of an article, another in the sidebar, and
yet a third when used as the caption for a photo.
CSS provides three distinct selector types that enable you to tai-
lor your design to appear exactly the way you want.
HTML Selector
To define how a particular HTML tag should be styled indis-
criminately across your Web page, use its HTML selector. For
example, if you say that all header level 2 tags should be red:
h2 { color: red; }
<h2>…</h2>
All header level 2 tags on the page will be red, unless you override
its declarations with other declarations. More about that later.
60
The level 2 header's text color is red.
HTML Selector
h2 { color : red; }
<h2>Chapter III</h2>
61
CSS G RAM MA R
SYN TAX
Class Selector
If you don’t want all of your tags to appear exactly the same, you
need a “free agent” selector that can be applied to any HTML
tag. This is the class selector. When defining a class rule, you place
a period immediately before the class name to let the browser
know, “Hey, this is a class selector, not an HTML or ID selector”:
This says:
To apply this class (and thus its styles) to an HTML tag, add
the class attribute to a tag with the class name in quotes. You can
apply the same class to any HTML tag you choose, as many times
as you want:
Notice though that you do not add the period with the class
name when it’s in the HTML tag. The period is only included
when you are setting up the class rule.
62
The hilight class text background color is yellow.
Class Selector
NO Periods
<h2 class="hilight">
Chapter I…</h2>
<p class="hilight">
'I should...</p>
63
CSS G RAM MA R
SYN TAX
If the hilight class is used with a level 2 header, then its back-
ground color is green.
64
If the hilight class is used with a level 2 header,
then its background color is green.
Class Selector
<h2 class="hilight">
Chapter I…</h2>
<p class="hilight">
'I should...</p>
65
CSS G RAM MA R
SYN TAX
When applied to an HTML tag, that tag picks up the styles of all
of the classes applied to it.
N a m i n g Yo u r C l a s s e s a n d I D s
You can call your classes or IDs anything you want as long as you follow
to what the class or ID is for, rather than what styles it applies. For
example, I might call a class “redText” to hilight certain text. But what
happens if later I want to make the hilighted text yellow? The yellow text
66
The highlight class background color is yellow.
The smallprint class font size is extra small.
Space
<h2 class="hilight">
Chapter I…</h2>
.smallprint { font-size: x-small; }
67
CSS G RAM MA R
SYN TAX
ID Selector
The first thing to know about the ID selector is that, on the sur-
face at least, it looks and acts exactly like the class selector. The
only obvious difference is that you use a hash mark at the begin-
ning, to declare it, rather than a period:
Similar to the class selector, you do not add the hash mark with
the ID name when it’s in the HTML tag. The hash mark is only
included when you are setting up the ID rule.
W h a t I D ’s A r e G o o d F o r
in how these selectors work, but in what you use them for:
footer)
navigation, ad)
68
The title01 ID text color is green.
ID Selector
NO Hash Mark
<h2 id="title01">
Chapter I…</h2>
69
CSS G RAM MA R
SYN TAX
Styles in Context
When speaking, context can radically alter the meaning of a
statement. Take the phrase:
If someone said that while whacking you on the head with a pil-
low, it would mean something very different than if they said it
while whacking you on the head with a baseball bat. The context
in which those words are spoken is the difference between the
phrase being a playful euphemism or a menacing threat.
70
Headline
Variety
and in secondary
headlines as well,
headlines a differ-
appear in.
71
CSS G RAM MA R
SYN TAX
72
If a citation is in a level 1 header, its text color
is red.
<h1><cite>
Through the Looking-Glass
</cite></h1>
73
CSS G RAM MA R
SYN TAX
You can create contexts as specific as you like, but keep in mind it
is always the last selector in the list that gets the actual styling.
The above CSS would apply its styles to the following content:
<div id="article"><h1><cite>
Through the Looking-Glass
</cite></h1><div>
74
If a citation is in a paragraph with the intro class
that is within the article ID, its text color is red.
<div id="article"><h1><cite>
Through the Looking-Glass
</cite></h1></div>
<div id="article"><p class="intro"><cite>
Through the Looking-Glass
</cite></p></div>
75
CSS G RAM MA R
SYN TAX
Here, “the white kitten” will be red because the emphasis tag is a
directly within the paragraph. However, if we applied it to this
HTML code:
In this case, “old cat” would not get the red styling because
the strong text is the emphasized text’s direct parent, not the
paragraph.
Although IE7 and above rectifies the situation, IE6 does not support
styling of child and sibling selectors. Make sure when using these
contextual selector types that they are only used as a design enhance-
76
If the emphasis tag is in a paragraph, and does
not have any other parent tags, its color is red.
<p><em>
p>em{ color : red; } the white kitten
</em></p>
<p><strong><em>
the old cat
</em></strong></p>
77
CSS G RAM MA R
SYN TAX
<em>Quotes</em> <strong>from</strong>
<cite>Through the Looking-Glass</cite>
The words “Through the Looking-Glass” would not get the red
styling because the <strong> tag is in the way.
78
If a citation is directly next to emphasized text,
its color is red.
79
CSS G RAM MA R
SYN TAX
Link States
All hypertext links have four “states” that can be styled in reac-
tion to a user action:
a visited state when the user returns after having visited the
linked-to page
80
Link Hover
Active Visited
81
CSS G RAM MA R
SYN TAX
If the link is in the browser history, its text color is dark red.
When the visitor hovers over a link, its text color is hot pink.
82
The default link text color is
red.
If the link is in the browser history, its text color is
dark red.
When the visitor hovers over a link, its text color is
hot pink.
When the visitor clicks a link, its text color is
fuchsia.
<a href="index.html">Welcome…</p>
83
CSS G RAM MA R
SYN TAX
The default text color for the class formField in an input box
is gray.
When the user hovers over an input field with the formField
class, its text color is green.
When the user clicks an input field with the formField class, its
text color is red.
One drawback: IE7 does not support active and focus, and IE6
supports none of these.
84
The default text color for the class formField in
an input box is gray.
When the user hovers over an input field
with the formField class, its text color is green.
When the user clicks an input field with the
formField class, its text color is red.
While the user is typing in an input field with
the formField class, its text color is black.
85
CSS G RAM MA R
SYN TAX
The first letter in a paragraph within any tag with the content
ID has a color of red.
The only drawback to this method is that it will not work in IE6,
which does not recognize the child context.
86
The first letter of each paragraph is red.
The first line of each paragraph is blue.
87
When we speak to each other, we understand as much from the
context of our words as from the words themselves. To be under-
stood, we need to be clear about the context of our statements.
We use semantics to do this, putting ideas together in a logical
manner. We don’t think about it, it’s an instinct like breathing—
we do it all the time.
In CSS, where you place your styles defines where and how they
will be applied. You need to understand how styles cascade down
the document, and how to apply different styles depending on
the medium. With a bit of practice, the semantics of CSS will
also become as instinctual as speaking or even breathing.
CHAPTER 5
Semantics
Making Sense of St yles
CSS G RAM MA R
SEM AN T IC S
Threadless
t hr e ad les s. c om
Threadless.
90
91
CSS G RAM MA R
SEM AN T IC S
h1 { color: red; }
However, CSS allows you to use the style attribute to place style
declarations directly into an HTML tag:
This is called placing the style inline. It has the same effect on the
style of the level 1 header tag as the full CSS rule, but only affects
that single instance of the tag. All other level 1 headers on the
page remain unaffected.
You can add as many different styles as you want to the style attri-
bute, as long as you separate each declaration by a semicolon:
Although useful for quickly adding styles where they are needed
in a design, inline styles have two major drawbacks that diminish
the flexibility of CSS, so they should be used sparingly if at all:
01 Because inline styles affect only that one tag in that one
instance, you can’t easily make global changes to styles.
02 Inline styles are the final word on what styles are applied to
that element, so they cannot be overridden.
92
Style Attribute Declaration
Inline Style:
Affects only the tag it is in.
93
CSS G RAM MA R
SEM AN T IC S
h1 { color: red; }
</style>
94
Style Tag Style Type Media Type
CSS Rule
Embedded Style:
Affects the entire page it is on.
95
CSS G RAM MA R
SEM AN T IC S
For example, say you have a Web page called main.html, with
your content structured using HTML. To style this file, you
would create an external style sheet called default.css, and place
a <link> tag or @import rule in the HTML file pointing to the
external style sheet. Those styles will now be applied to the Web
page just as if the code was embedded in it. However, we could
also link that same file to more files—for example ch01.html or
ch02.html—and get the same styles applied to the content on
those pages.
96
97
CSS G RAM MA R
SEM AN T IC S
h1 { color: red; }
When you are ready, save the file, giving it a meaningful filename
with the extension .css. For example, You might have an external
file called default.css and another one called ch01.css.
98
99
CSS G RAM MA R
SEM AN T IC S
The <link> tag will inject the CSS code from the external style
sheet wherever it is placed in an HTML document, just as if
that code was embedded in the HTML file. As with embedding
the code in the page, though, it’s best to place the link within
the <head> tag and above any JavaScript so that the styles are
available as soon as the page is rendered in the browser window.
Otherwise, you risk having the content load before the styles and
then redraw itself after the styles have been processed.
You can add as many different link tags as you want to your Web
page, allowing you to mix and match different styles. Before you
go too crazy, though, study “The Cascade” section later in this
chapter to understand how different CSS rules interact with and
override each other.
100
Link Tag
<link
rel="stylesheet" Link Relationship
/>
Self-Closing
101
CSS G RAM MA R
SEM AN T IC S
@import url(default.css);
Using the import rule will pull the CSS from the external file,
placing it directly into that position in an HTML document or
in another CSS file, based on the URL provided, either as a rela-
tive path (where the file is in relation to the summoning file) or
an absolute path (the full URL, starting with http://www).
Like the <link> tag, you can add as many @import rules as you
want to your external style sheets and HTML files, but it’s impor-
tant to understand how the cascade works (described later in this
chapter) if you want your styles to work the way you intend them to.
Link or Import?
102
Import Rule
@import url(default.css);
URL for File
103
CSS G RAM MA R
SEM AN T IC S
/*——————————————
Email: jason@brighteyemedia.com
——————————————-*/
Note that in this example, the extra dashes at the top and bottom
are only there to help set off the comment from the rest of the
page. They are not required.
104
Slash
105
CSS G RAM MA R
SEM AN T IC S
Inheritance
It’s important to remember that almost all HTML tags have
styles indirectly applied to them. An inherited style can come
from styles that are predefined by the browser itself (browser-
default styles) or from an element’s parent tags (parent-inherited
styles).
106
<h1>The Characters of
<cite>Through the Looking-Glass</cite></h1>
font-weight: bold
Browser-default
font-style: italic
.hilight { color: purple; }
107
CSS G RAM MA R
SEM AN T IC S
Inheritance continued
Overriding Inheritance
Style declarations are not engraved in stone and can be easily
overridden. The most obvious way to override a style is to simply
restate it later in your CSS. For example, if we wanted to over-
ride an inherited style, we might say something like:
The hilight class’s text color is purple, but the cite tag’s text color
is orange.
the entire header will be purple because of the hilight class, but
the book title, Through the Looking-Glass, will be recolored
orange because the declaration for the citation tag overrides the
parent-inherited style.
108
cite {color: orange; }
.hilight { color: purple; }
color: orange
109
CSS G RAM MA R
SEM AN T IC S
Order
You can override a style for any selector simply by declaring the
rule again with the same attribute but a different value:
The second instance of the hilight class will override the one
before it, basically allowing you to change your mind.
The basic rule of thumb is that the last instance of the style
declared is the one applied to the page.
Why would you want to override styles? This example shows the
change immediately after, but that would not be very likely—you
would just change the first rule. However, once your CSS starts
getting longer and more complex, spanning multiple Web pages
and multiple external CSS files, you may need to override the
style set for one element on one page with another.
The order you place your CSS rules in will have a direct effect on
which style ends up being applied, with the last one listed being
the one that gets used, if there are no other overriding factors
such as specificity, importance, and media type.
110
.hilight { color: orange; }
.hilight {color: purple; }
<h1 class="hilight">The Characters of
<cite>Through the Looking-Glass</cite></h1>
color: purple
111
CSS G RAM MA R
SEM AN T IC S
Specificity
Although the order you place your CSS rules in is important, it
is not the final word in determining whether a style is applied
to an element or not. Specificity refers to how much context you
provide in a given CSS rule. The more specific the context the
rule is to be applied, the more weight it is given when determin-
ing whether or not it is applied, even allowing you to override
the order in which styles are set. If you are unsure what I mean by
context, check Chapter 4’s “Styles In Context” section first.
The basic rule of thumb is that the more specific you are about
the context of a CSS rule, the more likely it is that the style
will be applied to the element.
The first CSS rule tells the browser how to style the hilight class
if it is in a level 1 header tag, whereas the second rule only applies
to the general case of the hilight class. And
is even more specific, so it will win out over the other two rules
that are placed after it in the style sheet.
112
h1 .hilight { color: orange; }
.hilight {color: purple; }
<h1>The Characters of
<cite class="hilight">Through the Looking-Glass</cite></h1>
color: orange
h1.hilight
.hilight {color: orange; }
{color: purple; }
<h1>The Characters of
<cite class="hilight">Through the Looking-Glass</cite></h1>
color: brown
113
CSS G RAM MA R
SEM AN T IC S
Specificity continued
The basic rule of thumb is any rule with ID selectors in the con-
text is going to override most other rules; a rule with a class in
the context will override a rule with just HTML selectors.
114
#content h1 .hilight { color: orange; }
100 + 1 + 10 = 111
color: orange
115
CSS G RAM MA R
SEM AN T IC S
Importance
Inheritance, order, and specificity combine to determine which
styles are applied to which elements, but you still have an ace
in the hole if you need to force particular styles to be applied:
!important will override all other concerns, forcing a style to be
applied. By placing this immediately after a value—but before
the semicolon—you are telling the browser that this is the most
important style declaration being applied, overriding all other
declarations, with the exception of inline styles.
For example, if you have rules for the same selector, but add
!important to the first:
Despite the fact that the purple declaration is second, any text
within the hilight class will be orange. !important will also over-
ride specificity:
.column01 h1 .hilight {
When Is a Style Important?
color: purple !important; }
It could be tempting to throw !important on
Even though the first declaration to use
everything, which could come back to bite
orange for the text color has greater speci-
you later since they are hard to override.
ficity, the second declaration will be used
Important is best reserved for use while because it is important.
prototyping new ideas or if you are creating
116
.highlight { color: orange !important; }
.highlight {color: purple; }
<h1 class="hilight">The Characters of
<cite>Through the Looking-Glass</cite></h1>
color: orange
color: purple
117
CSS G RAM MA R
SEM AN T IC S
Media
We generally think of the Web as a screen-based medium, but
Web pages can be output on a variety of different devices. You
need to be able to create style sheets that tailor your pages to a
variety of media. Earlier in this chapter, when you learned how
to add styles to a Web page or a Web site, I mentioned that you
can also specify a media type to which the style sheet should be
applied. The default is all—that is, apply these styles regard-
less of the device. Although CSS allows for several media types,
really there are only four types you need to worry about:
For details on getting the best results with media types, check out
Chapter 12: “The Last Word.”
118
Screen
Handheld
119
CSS G RAM MA R
SEM AN T IC S
The Cascade
While the browser is rendering your Web page, each style decla-
ration cascades through the Web page with a particular priority
based on its media type, importance, specificity, order, and inher-
itance until its rule matches a particular element. (Sounds pretty
poetic, doesn’t it?) The cascade is predictable, and usually obvious
as long as you don’t try to overthink it.
05 Order The last style declared is the one that gets applied.
120
high
Inline
Media
Important PRIORITY
Specificity
Order
Parent-inherited
Browser-def
r ault
low
121
Vocabulary is what adds diversity to a language. In the examples
I have presented so far, I kept the vocabulary simple so that we
could concentrate on the syntax and semantics. Now, it is time to
broaden your horizons—not to mention your design possibilities
—with a slate of new CSS vocabulary.
CHAPTER 6
Vocabulary
Talking the Talk
CSS G RAM MA R
VOC ABU LA RY
Values
A CSS rule is made up of a selector with one or more declara-
tions separated by semi-colons, and each declaration is made
up of a property and a value (see Chapter 3 if you need more
details). This chapter presents the various properties you will be
using when describing your designs in CSS with a list of possible
values underneath. The values come in two basic types: keywords
and variables.
Keywords
Many of the values you will assign to a CSS property are key-
words—words you type exactly as you see them—and most are
self-explanatory, but a few need some additional explanation:
auto The browser calculates the value.
inherit Sets the property to use the same value as its parent
element.
none Removes any specific value, which prevents the property
from being displayed or removes any limitations.
normal Sets the property to its default value.
transparent Sets the color value to 0% opacity, allowing any-
thing behind the object to show through. However, any length
values associated with the property are still honored.
u rbandi c ti o na r y.co m
124
Variables
Values listed in chevron brackets <> are variables. You will need See Appendix A for
more details on val-
to determine the exact value based on the type of variable:
ues used in CSS.
<color> A chromatic value, based on the amount of red, green,
or blue for the hue. Color values are most commonly expressed
using the hexadecimal notation, RGB values (using percentages
or the 0–255 scale), or as a keyword color name.
<font-name> The name of any font family you want to use.
Keep in mind the browser can only use the font families that See Appendix C for a
are installed on the end-user’s computer. list of Web-safe fonts.
125
CSS G RAM MA R
VOC ABU LA RY
Fonts
Font properties apply directly to individual letter forms to change
their nature and shape. These styles are generally associated with a
unique version of the font within the same font family, or require
that the computer create a faux version of the font on the fly. For
example, italics are associated with a specific version of the font
that has been created in the italic style—typically slanted and
made to look more hand-written than the default style. However,
if no such independent version of the font exists on the end user’s
computer, the browser will synthesize an italics version by slant-
ing the default version by 15 degrees. Browser-synthesized fonts
are not as readable or attractive as those created by a typographer,
so it’s best to use only styles with a true version of the font available.
font The shorthand property that lets you set all of the font
properties listed below at the same time, as well as line height.
Values: inherit | <font-style> <font-variant> <font-weight>
<font-size>/<line-height> <font-family>
126
weight variant line height
WELCOME
127
CSS G RAM MA R
VOC ABU LA RY
Fonts continued
font-family Sets a specific font family by name or a generic font
family of serif, sans-serif, monospace, handwritten, or fantasy.
Font names with two or more words must be in quotes (for
example, "lucida sans"). Generic values will use a font defined
by the browser for that style.
Values: inherit | <font-name> | serif | sans-serif | cursive
| fantasy | monospace
Multiple Values: Include as many font-names as desired,
separated by commas. The browser will try each font in
sequence until it finds one it can use.
font-weight The boldness of the font, generally a thicker ver-
sion of the default. If a bold version of the font does not exist,
the browser will simulate one based on the default pattern.
Values: normal | bold | bolder | lighter | inherit
font-variant Sets the small-cap style, where all letters are capi-
tals, but capitalized letters are slightly larger.
Values: normal | small-caps | inherit
font-style Sets whether a font is italic or oblique. Most brows-
ers will treat both values as italic if a true italic version of the
font exists. If an italic version does not exist, the browser syn-
thesizes an oblique version of the font by slanting the default
version of the font to the right by 15 degrees.
Values: normal | italic | oblique | inherit
font-size Sets an absolute-size, length, relative-size, or percent-
age based on the size of the font of the parent element.
Values: <length> | <percentage-parents-font-size> | smaller
| larger | xx-small | x-small | small | medium | large | x-large
| xx-large | inherit
128
font-family: garamond, georgia, serif;
Garamond, Georgia, Serif
font-weight: bold;
Bold
font-style: italic;
Italic
font-variant: small-caps;
SMALL CAPS
font-size: 12px;
6px 12px 18px 24px
129
CSS G RAM MA R
VOC ABU LA RY
Text
Text styles are properties applied to an entire block of text within
an element, but that do not affect the individual letters them-
selves. This includes text spacing properties such as letter, word,
and line spacing, as well as text alignment, indents, underlining,
overline, strike-through effects, and text capitalization.
color Sets the text color.
Values: <color> | inherit
letter-spacing Places an exact amount of space between each
letter in a block of text to control the letter tracking. This is
not to be confused with kerning , which uses data from the
font to adjust spacing between letters based on pairing context.
Letter spacing is a crude way to adjust spacing between letters,
since it does not take into account the visual appearance of the
letters. It is best reserved for large text such as headlines.
Values: <length> | <percentage-font-size>% | inherit
word-spacing Places an exact amount of space between each
word in a block of text. Like letter spacing, this is a rough way
to adjust spacing and is best used with large text.
Values: normal | <length> | inherit
line-height Controls the spacing between lines in a block
of text. Adjusting line height to at least 1.5 (=150%) or
higher is generally recommended to make large blocks of
text more readable.
Values: normal | <number> | <length>
| <percentage-font-size>% | inherit
white-space By default, Web browsers collapse multiple spaces
in HTML code into a single space in the Web page and will
automatically wrap text rather than allowing a horizontal scroll.
White space allows you to override both of these defaults to
preserve all white space or prevent text from wrapping.
Values: normal | pre | nowrap | pre-wrap | pre-line | inherit
130
color: rgb(128,0,0);
text is maroon
letter-spacing: .1em;
letters are spaced apart
word-spacing: 40px;
words are spaced apart
line-height: 2;
One thing was certain, that One thing was certain, that One thing was certain, that
the white kitten had had the white kitten had had the white kitten had had
nothing to do with it: -- it
was the black kitten's fault nothing to do with it: -- it nothing to do with it: -- it
entirely. was the black kitten's fault
was the black kitten's fault
entirely.
entirely.
1 1.5 2
white-space: pre;
multiple spaces are not collapsed
131
CSS G RAM MA R
VOC ABU LA RY
Text continued
text-align Sets the justification of text to left, right, center, or
full justification of the left and right edges.
Values: left | center | right | justify | inherit
vertical-align Sets the vertical positioning of a block of text
in relation to adjacent elements in the same line. Although
seemingly useful for aligning elements, experience shows it
does not behave as designers would expect, since it only works
on inline elements and can not be used to vertically align
blocks of text. The most common use is for super-scripting
and sub-scripting text.
Values: baseline | sub | super | top | text-top | middle | bottom
| text-bottom | <percentage-line-height>% | <length> | inherit
text-indent Sets an indent for the first line in a block of text.
Values: <length> | <percentage-width>% | inherit
text-decoration Sets a line to be placed over, under, or through
the text in an element. The style of the line cannot be con-
trolled and will be the same color as the text.
Values: none | line-through | underline | overline | blink | inherit
text-transform Sets the capitalization of letters in a block of
text, regardless of the state of the originating text.
Values: lowercase | capitalize | uppercase | none | inherit
132
text-align: center;
One thing was certain, that One thing was certain, that One thing was certain, that One thing was certain, that
the white kitten had had the white kitten had had the white kitten had had the white kitten had had
nothing to do with it: -- it nothing to do with it: -- it nothing to do with it: -- it nothing to do with it: -- it
was the black kitten's fault was the black kitten's fault was the black kitten's fault was the black kitten's fault
entirely. entirely. entirely. entirely.
vertical-align: sub;
super
X X sub
text-indent: 1em;
One thing was
certain, that the white
kitten had had nothing to
do with it: -- it was the black
kitten's fault entirely.
text-decoration: strike-through;
One thing was certain, that One thing was certain, that One thing was certain, that
the white kitten had had the white kitten had had the white kitten had had
nothing to do with it: -- it nothing to do with it: -- it nothing to do with it: -- it
was the black kitten's fault was the black kitten's fault was the black kitten's fault
entirely. entirely. entirely.
text-transform: uppercase;
text case Text Case TEXT CASE
Lowercase Capitalize Uppercase
133
CSS G RAM MA R
VOC ABU LA RY
Background
All elements have a background that fills the area of its element
box behind any content and padding, up to its border (see the
next section for details on the element box). The background can
be a solid color or an image that can be tiled, with its starting
point positioned horizontally and vertically within the box.
background The shorthand property that lets you set all of the
background properties listed below at the same time.
Values: <background-color> <background-image>
<background-repeat> <background-attachment>
<background-position> | none
background-color Sets the color to fill the area of an element
behind the content up to its border. Any area of the back-
ground not covered by a background image will fill with the
background color.
Values: <color> | transparent | inherit
background-image Sets an image to appear behind the ele-
ment’s content and padding. You can use PNG (8, 24, or 32),
JPEG, or GIF image formats.
Values: url(<url>) | none
background-attachment Controls whether an image will scroll
with the content of the element or stay fixed behind it.
Values: scroll | fixed | inherit
134
color repeat position
background-color: rgb(126,0,68);
background-image: url(bg-01.png);
background-attachment: fixed;
had grown in the last few had grown in the last few
'Here!' cried Alice, quite minutes, and she jumped minutes, and she jumped
forgetting in the flurry of up in such a hurry that she up in such a hurry that she
the moment how large she tipped over the jury-box tipped over the jury-box
had grown in the last few with the edge of her skirt, with the edge of her skirt,
minutes, and she jumped upsetting all the jurymen on upsetting all the jurymen on
up in such a hurry that she to the to the
tipped over the jury-box
with the edge of her skirt,
upsetting all the jurymen on
to the
Scroll Fixed
135
CSS G RAM MA R
VOC ABU LA RY
Background continued
Image Repeat
For ideas on using Background image tiling is how a lot of visual design is accom-
backgrounds in lay-
plished, so it’s important to understand how the different tiling
out, see Chapter 8,
“Layout.”
methods work and what they are for.
background-repeat Controls whether or how the background
image repeats (or not). You can set the background to tile, tile
horizontally, tile vertically, or just appear once.
Values: repeat | repeat-x | repeat-y | no-repeat | inherit
repeat Tiles the background image in the box horizontally and
vertically to fill the entire area. Repeat is most often used for
textured backgrounds.
no-repeat The background image appears once and does not
tile. Any area not covered by the background image is filled
with the background color. No-repeat works well for water-
marks and graphic bullets.
repeat-x The background image tiles horizontally across the
element. Any area below the tiling background is filled with
the background color. Repeat-x is often used to create header
designs by repeating a pattern or gradient across the top of an
element.
repeat-y The background image tiles vertically in the element.
Any area of the box to the right of the tiling background is
filled with the background color. Repeat-y is useful for creating
column boundaries.
136
background-repeat: repeat;
repeat no-repeat
repeat-x repeat-y
137
CSS G RAM MA R
VOC ABU LA RY
Background continued
Image Position
By default, all backgrounds are positioned in the top left corner
of the element they are in, but you can offset that position in a
number of different ways. Background positions can be set using
one value or two values to set its horizontal and vertical positions.
background-position Uses one or two values separated by a
space for the distance from the top or left side of the element
to specify where the background will start to appear.
Values: <length> | <percentage-box-width+padding>% | top
| bottom | center | left | right | center | inherit
Multiple Values: One value for both top and left position,
two values separated by a space for top and left respectively.
<length> Places the background a specified distance from
either the top and/or left side of the element. For example, 0 0
is the top left corner. 10px 15px pushes the background start-
ing point down 10px and over to the right by 15px.
<percentage-box-width+padding> Places the background a dis-
tance from the top and/or left side of the element, calculated as
a percentage of the width or height of the element. For exam-
ple, if the box was 10px by 20 px, and the background position
is set to 25%, the background would be pushed down 5px and
over to the right by 3px (rounding up from 2.5).
top Places the top of the background image against the top of
the element.
bottom Places the bottom of the background image against the
bottom of the element.
left Places the left side of the background image against the left
side of the element.
right Places the right side of the background image against the
right side of the element.
center Places the top and/or left corner of the background
image in the center of the element.
138
background-position: 0 0;
00 bottom 25px
139
CSS G RAM MA R
VOC ABU LA RY
Box
All elements are rectangular in shape—a box. Every time you add
an HTML tag to create an element, you are creating an element
box. All element boxes have a top, right, bottom, and left side
that you can style, setting the margin, padding, border, width,
and height, as well as the visibility and float.
140
Margin
g Border Padding Content
Top
p
Bottom
Element Box
141
CSS G RAM MA R
VOC ABU LA RY
Box continued
Display
All elements will have a default display type, which you can
override using the display property that tells the element how to
behave in relation to the elements around it.
display Sets whether the element’s box will be inline, block, a
list item, or whether it appears at all. A value of none removes
the element from the page completely so that a dynamic action
can show it at the right time.
Values: inline | block | list-item | none | inherit
inline Element boxes flow horizontally next to each other
from left to right.
block Element boxes flow vertically, stacking on top of each
other from top to bottom.
list-item Element boxes flow vertically, stacking on top of each
other from top to bottom, like block, but with a list-marker
and indented lines of text.
none The element is completely removed from the document.
inherit Uses the display style of the parent element.
is on to fit.
142
<span id="e1">Element 1</span>
<span id="e2">Element 2</span>
<span id="e3">Element 3</span>
Element 1
Element 2
Element 3
Block
Inline
None
143
CSS G RAM MA R
VOC ABU LA RY
Box continued
Visibility
One way to hide an element is to set the display property to none
and completely remove it from the document. If you want the
element to remain in the document but be invisible, you have
other options:
visibility Sets whether the box is visible or invisible. A hidden
element will still take up space but will appear to be empty, like
the invisible man in a rain storm.
Values: visible | hidden | inherit
opacity Sets the opacity of a box on a scale from 0.0 (clear) to
1.0 (opaque). This value affects the opacity of the element and
all of its content and cannot be overridden by child elements.
Opacity does not currently work in IE.
Values: <0.0-1.0> | inherit
filter: alpha(<0-100>) Sets the opacity of a box in IE on a
scale from 0 (clear) to 100 (opaque). This is not a true CSS
property, but it can be added to any CSS rule. If you set both
the filter: alpha and the opacity, you can be sure you have the
same value set for all browsers, including IE.
144
<span id="e1">Element 1</span>
<span id="e2">Element 2</span>
<span id="e3">Element 3</span>
Element 3
#e1 { opacity: 1;
Element 1
filter: alpha(100); }
#e2 { opacity: .5; Element 2
filter: alpha(50); }
#e3 { opacity: .25; Element 3
filter: alpha(25); }
145
CSS G RAM MA R
VOC ABU LA RY
Box continued
Float
The float property A floating element is one whose box aligns itself to the left or
has become crucial right. Surrounding content then wraps around it. This is often
to multi-column Web
used to float images with or without captions, but can also be
layouts, as explained
in Chapter 8, “Layout.” used for sidebars, pull quotes, or any other elements with a close
association with the main text.
float Positions the box to the left or right within its parent
element. Any content below the element will wrap around it
in moving up into the available space. If multiple elements are
floated next to each other, then they will line up horizontally
as space allows.
Values: left | right | none | inherit
clear When applied to an element that has been placed below
a floating element, floating stops, with the cleared element
again appearing beneath the floating element. Floating can be
specifically cleared on the left, right, or completely cleared on
both sides.
Values: none | left | right | both | inherit
146
<p id="e1">Element 1</p>
<p id="e2">One thing was…</p>
<p id="e3">The way Dinah…</p>
#e1{ One thing was certain, that
the white kitten had had
width: 75px; nothing to do with it: -- it was
the black kitten's fault
147
CSS G RAM MA R
VOC ABU LA RY
Box continued
148
width: 225px;
height: 150px;
overflow: hidden;
Width = 225px
149
CSS G RAM MA R
VOC ABU LA RY
Box continued
Maximum and Minimum
Width and Height
One of the key differences between designing for the Web and
designing for other media, such as print or TV, is that the user
controls the size of the browser viewport—the area in which your
designs are viewed in—and can change the width and height at
will. Instead of setting an absolute width and height, you also
have the option of setting a width and height range to allow the
content to stretch to fit the viewport area, while still not allowing
it to shrink or grow to uncomfortable dimensions.
150
max-width: 225px;
min-width: 150px;
max-height: 190px;
min-height: 150px;
Max-width = 225px
Min-height = 150px
entirely. For the white kitten
had been having its face
Max-height = 190px
Min-width = 150px
151
CSS G RAM MA R
VOC ABU LA RY
Box continued
Border
An element’s border is the rule around its box on the top, right,
bottom, and left. A border can have any thickness and color, and
you can select from a limited number of styles. Set the border on
all four sides to be the same, or set each side individually.
border The shorthand property for setting all of the border
properties for the box in one line, with values separated by a
space. All three values must be declared in order for the border
to appear.
Values: <border-width> <border-color> <border-style>
border-width Sets the thickness of the border.
Values: <length> | thin | medium | thick | inherit
Multiple Values: One value for all four sides, two values
separated by a space for top/bottom and left/right, or four
values separated by spaces for top, right, bottom, and left, in
that order.
border-color Sets the hue of the border.
Values: <color> | transparent | inherit
Multiple Values: Same as border-width.
border-style Sets one of the predefined border patterns.
Values: none | dotted | dashed | solid | double | groove | ridge
| inset | outset | inherit
Multiple Values: Same as border-width.
border-top, border-right, border-bottom, border-left The short-
hand properties for setting the border properties on the indi-
cated side of the box.
Values: <border-width> <border-color> <border-style>
border-width-top, border-width-right, border-width-bottom, bor-
der-width-left, border-style-top, border-style-right, border-style-
bottom, border-style-left, border-color-top, border-color-right,
border-color-bottom, border-color-left Sets the indicated
property for the indicated side of the box.
Values: Varies depending on property.
152
border: 5px solid rgb(67,0,37);
153
CSS G RAM MA R
VOC ABU LA RY
Box continued
Padding
Padding is the space between the content of the element’s box
and the border. Padding is easily confused with the margin, espe-
cially if there is no visible border. Padding, however, is intended
to separate the content of the box from its edges, whereas the
margin is meant to separate the element from other elements on
the screen.
padding The shorthand property for setting the padding on all
four sides of the box simultaneously.
Values: <length> | <percentage-box-width>% | inherit
Multiple Values: One value for all four sides, two values
separated by a space for top/bottom and left/right, or four
values separated by spaces for top, right, bottom, and left, in
that order.
padding-top Sets the space between the content and the top of
the box.
Values: <length> | <percentage-box-width>% | inherit
padding-right Sets the space between the content and the right
side of the box.
Values: <length> | <percentage-box-width>% | inherit
padding-bottom Sets the space between the content and the
bottom of the box.
Values: <length> | <percentage-box-width>% | inherit
padding-left Sets the space between the content and the left
side of the box.
Values: <length> | <percentage-box-width>% | inherit
154
padding: 35px 30px;
Top = 35px
One thing was certain, that
the white kitten had had
nothing to do with it: -- it was
the black kitten's fault
entirely. For the white kitten
had been having its face
washed by the old cat for the
Right = 30px
Left = 30px
Bottom = 35px
155
CSS G RAM MA R
VOC ABU LA RY
Box continued
Margin
The margin is the space between the border of an element and
all other elements on the page. As mentioned, in the absence of
a border or background, margin and padding will appear to be
identical, but it is important to remember that they are different
values. Margin should be used to adjust an element’s position
in relationship to other elements on the page, while padding
should be used to keep content from bumping up against the
edge of the box.
margin The shorthand property setting the margin on all four
sides of the box simultaneously.
Values: <length> | <percentage-box-width>% | inherit
Multiple Values: One value for all four sides, two values
separated by a space for top/bottom and left/right, or four
values separated by spaces for top, right, bottom, and left in
that order.
margin-top Sets the space between the top of the box and the
bottom of other elements.
Values: <length> | <percentage-box-width>% | inherit
margin-right Sets the space between the right edge of the box
and the left edge of other elements.
Values: <length> | <percentage-box-width>% | inherit
margin-bottom Sets the space between the bottom of the box
and the top of other elements.
Values: <length> | <percentage-box-width>% | inherit
margin-left Sets the space between the left edge of the box and
the right edge of other elements.
Values: <length> | <percentage-box-width>% | inherit
156
margin: 15px 20px 35px 25px;
Top = 15px
Right = 20px
washed by the old cat for
Left = 25px
Bottom = 35px
157
CSS G RAM MA R
VOC ABU LA RY
Box continued
Fixing IE
The CSS box model describes how an element should behave in
your designs: The width and height are applied to the content
area of the box, while padding and border lengths are added to
get the apparent width and height, sometimes called the rendered
width and height. At least, this is how the W3C CSS Work
Group specified that the standard for the box model should work.
Unfortunately, the folks who made IE6 didn’t get the memo in
time. They decided that width and height applied to the entire
box, including the margin and padding.
You are OK as long as you do not set the width/height with pad-
ding and a border. But, as soon as you add padding and borders,
in IE6 your designs will look different from standards-compliant
browsers, even IE7.
158
width: 225px; Width = 225px +
padding: 10px; Left/Right Padding = 20px +
border-width: 2px; Left/Right Border = 4px
Apparent Width = 249px
Apparent = 249px
_width: 249px;
Underscore 6
One thing was certain, that One thing was certain, that
the white kitten had had the white kitten had had
nothing to do with it: -- it nothing to do with it: -- it
was the black kitten's fault was the black kitten's fault
entirely. For the white kitten entirely. For the white kitten
had been having its face had been having its face
washed by the old cat for washed by the old cat for
the last quarter of an hour the last quarter of an hour
(and bearing it pretty well, (and bearing it pretty well,
considering); so you see considering); so you see
that it couldn't have had any that it couldn't have had any
The White Kitten The White Kitten
hand in the mischief. hand in the mischief.
The way Dinah washed her children's faces was this: The way Dinah washed her children's faces was this:
first she held the poor thing down by its ear with one first she held the poor thing down by its ear with one
paw, and then with the other paw she rubbed its face paw, and then with the other paw she rubbed its face
all over, the wrong way, beginning at the nose: and just all over, the wrong way, beginning at the nose: and just
now, as I said, she was hard at work on the white now, as I said, she was hard at work on the white
kitten, which was lying quite still and trying to purr -- no kitten, which was lying quite still and trying to purr -- no
doubt feeling that it was all meant for its good. doubt feeling that it was all meant for its good.
159
CSS G RAM MA R
VOC ABU LA RY
Position
All element boxes can be positioned on the screen, either rela-
tive to their natural position (where they would appear if left
untouched) or absolute distance from the edge of its most imme-
diate parent element with positioning set. To set the position of
the box on the screen, you need to set both its position type and
then its actual position.
Position Type
Think of setting the position type as turning on positioning.
Until this is set, all elements have a “natural” position, which
is where the element would appear if left untouched by position-
ing. To turn on positioning, you define how you want the ele-
ment placed.
position Defines the positioning type that the element’s box
will use.
Values: static | relative | absolute | fixed | inherit
static The element’s box cannot be repositioned from its natu-
Fixed elements are ral position.
a great way to cre-
ate headers, footers,
relative The element’s box is positioned from where it would
and menus that stay
have natural position in the design.
on the screen at all absolute The element’s box is positioned relative to the imme-
times. Unfortunately, diate parent with a position type set.
fixed does not work in
IE6. The good news is
fixed The element’s box is positioned relative to the browser
that you can use the
window, and the element does not scroll with the rest of the
box model (shown in
page. Instead it stays fixed in its position.
Appendix C, “Fixing inherit The box inherits the position type from its most imme-
IE6”) to set the posi- diate parent with a position type set.
tion to absolute for
that browser.
160
<span id="e1">1</span>
<span id="e2">2</span>
<span id="e3">3</span>
1 2 3 1 30px 3
50px 2
static relative
30px 30px
50px 2 50px 2
1 3
1 3
absolute fixed
161
CSS G RAM MA R
VOC ABU LA RY
Position continued
162
<span id="e2">Element</span>
Element
25px Element
Element
25px
163
CSS G RAM MA R
VOC ABU LA RY
Position continued
164
<span id="e1">1</span>
<span id="e2">2</span>
<span id="e3">3</span>
#e1{ z-index: 1; }
if positioned
1
1
3
2 3
2
Natural z-index: 2
1 1
3 3
2 2
z-index: 3 z-index: 0
165
CSS G RAM MA R
VOC ABU LA RY
Tables
Tables are used to present data. Any of the font, text, background,
and box properties already mentioned can be applied to them.
Tables have a few special styles, however, that can only be applied
to the various table tags:
border-spacing: Sets the space between table data cells.
Values: <length> | inherit
Multiple Values: One value for all four sides, or two values
separated by a space to set the top/bottom and left/right spac-
ing separately.
border-collapse: Sets how borders between separate table data cells
are treated. Use collapse to have borders between table data cells
shared. Use separate to treat each table data cell as having inde-
pendent borders.
Values: collapse | separate | inherit
caption-side: Sets where a table caption appears, either above or
below the table. Caption side does not work in IE6 or IE7,
but will work in IE8, so you should consider this a design
enhancement.
Values: top | bottom | inherit
166
border-spacing: 6px 2px;
border-collapse: collapse;
collapse sepDrate
caption-side: top;
top
bottom
167
CSS G RAM MA R
VOC ABU LA RY
Lists
Lists are used for a variety of purposes in Web design, not the
least of which is to actually create an ordered (<ol>) or unor-
dered (<ul>) list of items. In addition, lists are often used to help
organize links and menus, even if the actual list markers (bullets,
letters, or numbers) are removed.
168
type position
list-style-type: square;
• Disc A Upper-Alpha 1 Decimal
Circle 01 Decimal-Leading-Zero
a Lower-Roman
Square I Upper-Roman
α Lower-Greek
i Lower-Roman
list-style-image: url(bullet-01.png);
list-style-position: inside;
• One thing was certain, • One thing was certain,
that the white kitten that the white kitten
• had had nothing to do • had had nothing to do
with it with it
• it was the black • it was the black
kitten's fault entirely kitten's fault entirely
Inside Outside
169
CSS G RAM MA R
VOC ABU LA RY
Cursor
The dynamic pseudo- The mouse pointer provides visual feedback to the user when
classes are explained they interact with a given element. The cursor will automatically
in Chapter 4, “Syntax,”
change for some elements such as links and form elements, but
in the section “Styles
for Special Cases.” you can control how the cursor appears over any element using
the dynamic pseudo-classes :hover, :active, and :focus.
cursor Sets the appearance of a cursor. You can choose from
the predefined list of cursors or specify a URL to load a PNG
(8, 24, or 32), JPEG, or GIF image as your cursor.
Values: default | url(<url>) | auto | crosshair | pointer | move
| e-resize | ne-resize | nw-resize | n-resize | se-resize | sw-resize
| s-resize | w-resize | text | wait | help | progress | inherit
170
cursor: move;
default
crosshair n-resize
pointer e-resize
move s-resize
text w-resize
wait ne-resize
help nw-resize
progress se-resize
sw-resize
171
CSS G RAM MA R
VOC ABU LA RY
Design Enhancements
There are a few properties on the cutting edge of CSS design that
haven’t been officially set as standards. While they may not be
ready for prime time quite yet, because they may not be univer-
sally implemented, you can still use them to enhance your designs
for those browsers that do use them.
Shadows
text-shadow Sets a drop shadow for text in an element. You can
control the color, offset, and the amount of blur to get differ-
ent shadow effects.
Browsers: Sa1.1
Values: <color> <length-x-offset> <length-y-offset>
<length-blur-radius>
box-shadow, -moz-box-shadow, -webkit-box-shadow Sets a drop
shadow for the box. You can control the color, offset, and
the amount of blur to get different shadow effects. Although
eventually the property will be called box-shadow, Firefox and
Safari have implemented their own version: -moz and -webkit.
Include all three to ensure cross-browser compatibility.
Browsers: Sa3, FF3
Values: <color> <length-x-offset> <length-y-offset>
<length-blur-radius>
172
text-shadow: rgb(0,0,0) 4px 2px 6px;
Text Shadow
box-shadow: rgb(0,0,0) 4px 2px 6px;
-moz-box-shadow: rgb(0,0,0) 4px 2px 6px;
-webkit-box-shadow: rgb(0,0,0) 4px 2px 6px;
173
CSS G RAM MA R
VOC ABU LA RY
Rounded Corners
Browsers: Sa2, FF1.8
Outline
Browsers: Sa2, FF1.8, Op9, IE7
174
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
outline: 10px solid rgb(67,0,37)
Click Me!
175
PART 3
In which the reader learns a tried and true process for Web development
with CSS, how to create the many elements they will need in their designs,
209 Layo u t
243 N av iga t io n
257 Chrom e
CHAPTER 7
Designing with CSS
SP EA KI NG LI K E A NAT IV E
DESI G NI NG W I T H CS S
01 Plan your site. Before you code, think carefully about what
you are doing, why you are doing it, and how you are doing
it: sketching, wire-framing, mood boards, and visual comps
are the best ways to plan before creating your site with CSS.
180
Sketches
Wire
Frames
PLAN
Mood
Boards
Comps Chrome
ITERATE
Style Guide
BUILD
Alpha Prototype
DEPLOY
Beta Launch
181
SP EA KI NG LI K E A NAT IV E
DESI G NI NG W I T H CS S
Plan
Every project should start with a plan. Whether it’s in your head
or formally spelled out, you need to define what the expectations
are for the project’s success. As the designer, your job is to con-
ceive the successful design solution using a process of discovery
and iteration. As you create your plans in advance of actual cod-
ing, it’s important to keep in mind how you will actually realize
your vision in code.
Sketches
Sketches are not meant to be detailed or complete plans, but to
help you get the rough ideas down and capture notes about the
project and rough dimensions. I like to put information like the
Web site’s purpose, audience, and content, as well as the site’s
message in big letters to remind me what this project is about. In
addition, I’ll quickly throw down different page types, mark stuff
out, redraw them as necessary to experiment, looking for differ-
ent design angles.
182
183
SP EA KI NG LI K E A NAT IV E
DESI G NI NG W I T H CS S
Plan continued
Page Flow
The first question you need to ask yourself when starting your
design is “Will my page be fluid or fixed?” Although fluidity is
generally considered for the width of the design, it can equally
be applied to the height of the design. While most Web designs
are based on a fixed width with a fluid height (that is, it stretches
to the height required to display all of the page content), this is
not your only option:
184
Fixed Width/Fluid Height Fluid Width/Fluid Height
185
SP EA KI NG LI K E A NAT IV E
DESI G NI NG W I T H CS S
Plan continued
Wire Frames
Wire frames are your chance to plan the structure of your page
without the distractions of visual design. They serve as the blue-
prints for construction and need to include placement and mea-
surements of elements in pixels. Here are the basic elements you
will need to include:
186
s.1
UI DESIGN SCREEN
40px
980px
SEARCH B
A
Header
980px by 100px
150px by 20px A Header
980px x 100px
Titles
B Book Search
User can input key words to search book text.
E TOP BOOKS 1. Title
2. Author
C T
TEXT BLOCK Genres
enres Book Cover
3. Full Text
150px by 225px
L
Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Vestibulum commodo metus
sit amet libero. Cras nisl neque, lacinia id,
Category Image
100px by 100px
Category Image
100px by 100px
Category Image
100px by 100px
Category Image
100px by 100px
C Welcome and Main Navigation
300px x *
mollis vel, dictum ac, ante. Vestibulum tortorr
dui, convallis a, dapibus vitae, volutpat nec,
justo. Integer dui. Nunc nec velit. Praesent F I
mollis, dolor ut elementum lobortis, turpis Top Navigation:
orci vulputate tortor, quis condimentum tortoror
leo non est. Maecenas ac elit. Cras porttitorr
• Genres
Preview Audio
porta magna. Duis ultrices. Suspendisse Category Title Category Title Category Title Category Title • About
potenti. Nam posuere lacus in ligula. Fusce ## Books ## Books ## Books ## Books
vitae ligula. Nam nunc ante, laoreet eget, Download Audio • News
adipiscing sit amet, sollicitudin sed, urna.
• Reviews
Read Text
Genres
• Donate
Category Image Category Image Category Image Category Image • Contact
About
100px by 100px 100px by 100px 100px by 100px 100px by 100px Book Title
News
By Author Name
Reviews
Donate
Contact
D Text Ads
Book Cover
300px x *
150px by 225px
Category Title Category Title Category Title Category Title
290px
E Page Header
470px x *
Category Image Category Image Category Image Category Image
Ad
100px by 100px 100px by 100px 100px by 100px 100px by 100px
Preview Audio
Download Audio
F Genre Button
100px x 140px (with text label)
Read Text
Category Title
## Books
Category Title
## Books
Category Title
## Books
Category Title
## Books
G About
470px x *
D Book Title
By Author Name
410px
I
N
Nulla sed felis. Sed et tellus. Vivamus venenatis suscipit magna. Vestibulum hendrerit iaculiss
Book Cover Links
n
nunc. Morbi posuere tempus elit. Ut commodo mattis nisi. Vivamus elit. Nam nisi felis, egestass
e
et, varius in, suscipit at, risus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sedd 150px x 225px
e
eget sapien. Mauris convallis dolor et nisl. Quisque nibh mauris, dictum quis, mollis et,,
e
euismod quis, diam. Sed at purus. Nulla tempus libero non mi. Nulla leo dui, venenatis ut,,
fe
feugiat sit amet, fringilla nec, ligula. Praesent arcu neque, pretium vitae, tincidunt interdum,, Preview Audio
la
laoreet non, felis. J Footer
980px x 20px
Download Audio
H Book Title
By Author Name
mollis vel, dictum ac, ante. Vestibulum tortor mollis vel, dictum ac, ante. Vestibulum tortor
dui, convallis a, dapibus vitae, volutpat nec, dui, convallis a, dapibus vitae, volutpat nec,
justo. Integer dui. Nunc nec velit. Praesent justo. Integer dui. Nunc nec velit. Praesent
mollis, dolor ut elementum lobortis, turpis mollis, dolor ut elementum lobortis, turpis
orci vulputate tortor, quis condimentum tortor orci vulputate tortor, quis condimentum tortor
leo non est. Maecenas ac elit. Cras porttitor leo non est. Maecenas ac elit. Cras porttitor
porta magna. Duis ultrices. Suspendisse porta magna. Duis ultrices. Suspendisse
potenti. Nam posuere lacus in ligula. Fusce potenti. Nam posuere lacus in ligula. Fusce Preview Audio
vitae ligula. Nam nunc ante, laoreet eget, vitae ligula. Nam nunc ante, laoreet eget,
adipiscing sit amet, sollicitudin sed, urna. adipiscing sit amet, sollicitudin sed, urna.
Download Audio
Read Text
Book Title
Reviews
R By Author Name
Book Cover
150px by 225px
TEXT BLOCK TEXT BLOCK
Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Vestibulum commodo metus adipiscing elit. Vestibulum commodo metus
sit amet libero. Cras nisl neque, lacinia id, sit amet libero. Cras nisl neque, lacinia id,
mollis vel, dictum ac, ante. Vestibulum tortor mollis vel, dictum ac, ante. Vestibulum tortor
dui, convallis a, dapibus vitae, volutpat nec, dui, convallis a, dapibus vitae, volutpat nec,
justo. Integer dui. Nunc nec velit. Praesent justo. Integer dui. Nunc nec velit. Praesent Preview Audio
mollis, dolor ut elementum lobortis, turpis mollis, dolor ut elementum lobortis, turpis
orci vulputate tortor, quis condimentum tortor orci vulputate tortor, quis condimentum tortor
leo non est. Maecenas ac elit. Cras porttitor leo non est. Maecenas ac elit. Cras porttitor Download Audio
porta magna. Duis ultrices. Suspendisse porta magna. Duis ultrices. Suspendisse
potenti. Nam posuere lacus in ligula. Fusce potenti. Nam posuere lacus in ligula. Fusce Read Text
vitae ligula. Nam nunc ante, laoreet eget, vitae ligula. Nam nunc ante, laoreet eget,
adipiscing sit amet, sollicitudin sed, urna. adipiscing sit amet, sollicitudin sed, urna.
Book Title
By Author Name
187
SP EA KI NG LI K E A NAT IV E
DESI G NI NG W I T H CS S
Plan continued
Mood Boards
There are many kinds of mood boards—everything from collages
of seemingly random elements that reflect the desired style to
boards that are on the verge of being a design specification docu-
ment. The style you choose should depend on your own strengths
as well as the needs of your client. If you are a strong visual
designer, a poster style format may work best; if you are an infor-
mation architect, a more structured document might be appro-
priate. Whatever style you choose, think carefully about what will
best communicate the flavor of the site you want to create.
Mood boards are meant to help define the visual style of your site
without you actually designing the entire interface. Generally, you
can quickly create two or three “looks” that can then be presented
to a client for feedback, without having to get bogged down in
the details of building the pages. You can include splashes from
the color palette, patterns, textures, typography, photos, and
illustrations. I also recommend including treatments of some
of the standard user interface elements such as form fields, lists,
and tables.
188
189
SP EA KI NG LI K E A NAT IV E
DESI G NI NG W I T H CS S
Plan continued
Visual Comps
Visual comps (short for compositions) combine the wire frames
to create mood boards: a static version of what the final Web
page will look like. If you skipped the mood boards, you may also
be relying on the visual comps to present to your client, possibly
showing several different skins for them to choose from. If you
are working with a developer who will be constructing the site,
this needs to be a pixel-perfect composition.
Once you get more comfortable with creating Web pages in CSS,
however, you may find that you can be less thorough, and can
leave some of the final design polishing until the prototype stage.
Here are some tips to keep in mind for your visual comps:
190
191
SP EA KI NG LI K E A NAT IV E
DESI G NI NG W I T H CS S
Build
The faster you can move from planning to building, the better.
It’s easy to get bogged down trying to plan for every contin-
gency, to the point that the planning takes over the production.
Planning should give you direction, but, in an iterative design
process, you can always revisit wire frames and comps as the situ-
ation on the ground changes.
Cutting Chrome
Putting the chrome Chrome (any graphics or visual effects used to create the user
back together to cre- interface of a Web site) is generally cut from the visual comps.
ate your interface is
How you cut the chrome depends on the software you use to cre-
covered in detail in
Chapter 11, “Chrome.” ate your comps, but regardless of your software of choice, there
are a few guidelines to follow while you are working:
192
193
SP EA KI NG LI K E A NAT I V E
DESI G NI NG W I T H CS S
Build continued
Typography is cov- Typography: The font families, styles, and weights being
ered in Chapter 9, used. You do not need to specify exact sizes or usage here.
“Typography.”
That will be included in the default styles. Because this is
Web design, though, you want to include a prioritized list
of fonts, starting with the most desired and ending with a
generic font-family as the ultimate fallback option.
Color values are Colors: List all of the primary and secondary colors used in
detailed in Appendix
the site, giving the hex and RGB values for each. I also like
B, “CSS Values.”
to give each color a specific project name, which generally
makes it easier to reference during discussions and feedback.
Default styles and Default styles: Defines the global styles such as font-family,
layout are covered in font-size, color, and page background that will be used over
Chapter 8, “Layout.”
most of the pages.
194
Style Guide
Wed Apr 22 2009
voxLIBRIS : Typography & Colors Page 2 of 4
Typography
Family 1
Regular Bold Oblique Bold/Oblique Capitalized
Fontin Sans Fontin Sans Fontin Sans Fontin Sans FONTIN SANS
Optima Optima Optima Optima OPTIMA
Trebuchet MS Trebuchet MS Trebuchet MS Trebuchet MS TREBUCHET MS
Sans-serif Sans-serif Sans-serif Sans-serif SANS-SERIF
Family 2
Regular Bold Italic Bold/Italic Capitalized
Capitali
p zed
Garamond Garamond Garamond Garamond GARAMOND
Cochin Cochin Coch
Cochin Cochin COCHIN
Style Guide Wed Apr 22 2009
Times Times T
Tim
Times voxLIBRIS
Times : Chrome
TIMES
Page 3 of 4
50% to scale
Serif Serif Seri
Serif Serif SERIF
Defaults Chrome
body Welcome
background-color: RGB(0,78,94)
background-image: url(bg-page.png)
color: rgb(105,105,105)
Colors font-family: "fontin sans", optima,
candara, "trebuchet-MS", sans-serif
Primary Colors font-size: 12px
bg-sidebar1-top.png
h1, h2, h3, h4, h5, h6
color: rgb(128,128,128,)
font-family: garamond, cochin,
cambria, times, serif
font-weight: normal
Black Dim Gray Gray Dark Gray Silver White
RGB 0, 204, 255 RGB 105, 105, 105 RGB 128, 128,
28, 128 p,
RGBul,169,
ol 169, 169 RGB 192, 192, 192 RGB 255, 255, 255
#000000 #696969 #808080 line-height:
#a9a9a9 1.5 #c0c0c0 #ffffff bg-sidebar1-mid.png
a
text-decoration: none
a:link bg-sidebar1-bottom.png
bg sidebar1 bottom.png
color: rgb(51, 204, 255)
VLAqua VLLightAqua Gold Yellow
RGB 0, 76, 94 RGB 37, 105, 128 RGB 255, 215,
15, 0 a:visited
RGB 255, 0, 0
color: rgb(51,204,255)
Style Guide
a:hover Wed Apr 22 2009
Secondary Colors color: rgb(255,255,255) voxLIBRIS : Layout
Ads
Page 4 of 4
text-decoration: underline 50% to scale
a:active
A Left Sidebar
40px
40px
C Search Input
padding: 2px 5px
bg-ads-mid.png
B
20px
Design Director
Jason Cranford Teague bg-ads-bottom.png
jason@brighteyemedia.com
60px
30px
Section
10px
flourish-down.png
20px
icon-pointer.png
20px
flourish-up.png
20px
10px
40px
40px
Design Director
Jason Cranford Teague
jason@brighteyemedia.com
30px
Design Director
Jason Cranford Teague
jason@brighteyemedia.com
195
SP EA KI NG LI K E A NAT IV E
DESI G NI NG W I T H CS S
Build continued
Prototype
Ready to start coding? The prototype is where you transform
your static visuals into living Web pages. If you are starting a pro-
totype from scratch (rather than re-skinning an existing site), you
will want to create your HTML first to define the general page
structure to which the CSS is then applied. Keep these tips in
mind while coding your CSS:
196
197
SP EA KI NG LI K E A NAT IV E
DESI G NI NG W I T H CS S
Build continued
Prototype: Writing Your CSS
How you organize the various rules in your style sheet can affect
your workflow and how quickly you can make changes. Of
course, you can always just throw your styles together haphaz-
ardly, but when your style sheets get longer and longer, you will
find yourself spending more and more time tracking down rules
to make changes. Keep these tips in mind:
Easy to edit: As your CSS code gets longer and more com-
plex, it can get harder to find and edit code. Even if it takes
a little more time, anything you can do to make it easier to
sort through it all will save you time and frustration in the
long run.
Once you are ready File size: Every letter, number, space, and character adds to
to deploy your site,
file size. They may seem like grains of sand, but get enough
consider reducing
your CSS file size by
sand and you fill a beach. The larger the file size, the longer it
stripping out all of takes to download. That’s not to say that you have to agonize
the comments and over every space you type, but try to cut code by using the
unnecessary spaces
cascade wherever you can.
using a service like
csscompressor.com.
198
199
SP EA KI NG LI K E A NAT IV E
DESI G NI NG W I T H CS S
Build continued
Prototype: Organizing Your CSS
Here are a few tips on formatting and organizing your styles to
make them easier to edit:
For a full listing of the Place general styles at the top of the style sheet (01–46).
code used to create This sets the default styles for your Web page—most impor-
the voxLibris template, tantly for the <body> element, which is the parent to all
see Appendix A.
other elements. Remember, once a style is set in a parent tag,
you never need to set it again unless you want to override it
for a specific element. Since the body tag is the ultimate par-
ent for all tags, anything you set there will be applied to all
tags on the page, with the exception of form elements.
200
01 /*--------------------------------------------------------------------- 47 /*---------------------------------------------------------------------
02 Reset Browser Inherited Styles 48 Grid
03 ---------------------------------------------------------------------*/ 49 ---------------------------------------------------------------------*/
04 html, body, div, span, applet, object, iframe, h1, h2, 50 #page {
h3, h4, h5, h6, p, blockquote, pre, a, abbr, 51 position: relative;
acronym, address, big, cite, code, del, dfn, em, 52 display: block;
font, img, ins, kbd, q, s, samp, small, strike,
strong, sub, sup, tt, var, dd, dl, dt, li, ol, ul, 53 margin:0 auto;
fieldset, form, label, legend, table, caption, 54 width: 980px;
tbody, tfoot, thead, tr, th, td 55
05 { 56 _width: 960px; }
06 margin: 0; 57 /*---------------------------------------------------------------------
07 padding: 0; 58 Grid - Rows
08 border: 0; 59 ---------------------------------------------------------------------*/
09 outline: 0; 60 .row {
10 background: none; 61 position: relative;
11 font: inherit inherit 100% inherit; 62 display: block;
12 text-align: left; 63 margin:0 auto; }
13 vertical-align: baseline; 64 #header { height: 100px; }
14 list-style: none; } 65 #content { padding-top: 20px; }
15 /*--------------------------------------------------------------------- 66 #footer { height: 20px; }
16 Default Styles 67 /*---------------------------------------------------------------------
17 -------------------------------------------------------------------- 68 Grid - Columns
-*/ 69 ---------------------------------------------------------------------*/
18 body, input, select { 70 .column {
19 color: rgb(105,105,105); 71 position: relative;
20 font-family: “fontin sans”, optima, candara, 72 display: block;
“trebuchet-MS”, sans-serif; } 73 float: left; }
21 74 .alignclear { clear: both; }
22 h1, h2, h3, h4, h5, h6 { 75 #aside1 {
23 color: rgb(128,128,128); 76 top: 60px;
24 font-family: garamond, cochin, cambria, times, 77 left: -80px;
serif; 78 width: 314px; }
25 letter-spacing: 1px; 79 #article1 {
26 font-weight: normal; } 80 left: -40px;
27 81 width: 470px; }
28 h1 { font-size: 2.5em; } 82 #aside2 { width: 190px; }
29 h2 { font-size: 2em; } 83 /*---------------------------------------------------------------------
30 h3 { font-size: 1.25em; } 84 Grid - Sections
31 h4, h5, h6 { font-size: 1em; } 85 ---------------------------------------------------------------------*/
32 p { 86 .section {
33 text-align: left; 87 position: relative;
34 font-size: .75em; 88 display: block; }
35 margin: 5px 0; 89 #header .search {
36 line-height: 1.5; } 90 position: absolute;
37 blockquote { 91 right: 10px;
38 font-size: .75em; 92 top: 10px; }
39 margin: 10px 0; 93 #footer .copyright {
40 padding: 10px 0; 94 margin: 0 20px;
41 border-top: 1px solid rgb(128,128,128); 95 float: left; }
42 border-bottom: 1px solid rgb(128,128,128); 96
43 line-height: 1; } 97 #aside1 .section {
44 li { 98 width: 100%;
45 font-size: .75em; 99 padding-bottom: 60px; }
46 margin: 2px 0; }
201
SP EA KI NG LI K E A NAT IV E
DESI G NI NG W I T H CS S
Build continued
Prototype: Combining Style Sheets
Style sheets can be linked to or imported into the HTML as
detailed in Chapter 5, “Semantics,” in the “Where to Put Style
Rules” section. There are two basic strategies for external style
sheets, each with its strengths and weaknesses:
All In One
Place all of your CSS code into a single file. From an optimiza-
tion standpoint, this is your best bet, as it takes only a single
download to get all of the code. The downside is that this can
mean a lot of extra code per page, and conflicts between styles
are more likely.
Pros
Allows user agent to cache one file that can then be reused
without extra required download time.
Cons
202
Modular Library
A library of CSS files allows you to break down the code by func-
tion. Each function has its own unique file that can be indepen-
dently edited and then imported into a single external CSS file
that is in turn linked to an HTML page. Every page will have a
unique external CSS file, but that file will be composed of mul-
tiple imported CSS files.
Pros
Easy to edit.
Cons
203
SP EA KI NG LI K E A NAT IV E
DESI G NI NG W I T H CS S
Deploy
Once you have built your prototype pages, you are ready to popu-
late them with their initial content and begin getting reactions.
Alpha
Your Web site is not ready for prime time (and is possibly pass-
word protected), but you can share it with people you know and
trust to give you honest feedback and constructive criticism.
Make sure the feedback comes with the following information:
Beta
Sometimes called the “soft launch,” beta launches are becoming
increasingly popular as a way to avoid criticism for any bugs on
the site after it goes public. Generally the site is made available to
the public but not promoted. Prominent feedback functionality
should be provided to report any problems.
Launch
It’s time for the hard launch, but don’t let that stop you from
making improvements.
204
205
SP EA KI NG LI K E A NAT IV E
DESI G NI NG W I T H CS S
Iterate
Design is an iterative process, where new ideas and new concepts
should constantly be explored to make improvements. The Web
makes the job of iteration easy because the means of distribution
are instantaneous. You can make changes and publish them atthe
speed of light (or at least at the speed of your Internet connection).
206
Plan
Iterate
Build Deploy
207
Grids are a time-honored method for creating strong visual
designs with hierarchy, visual rhythm, and context. Although
CSS is not explicitly set up for creating grids—there are no row
or column properties—designers have developed methods to
overcome this limitation.
CHAPTER 8
Layout
SP EA KI NG LI K E A NAT IV E
LAYO UT
Structure
Layout begins with the HTML document, which creates the
structure on which the CSS is applied. A Web page’s structure
can take a variety of forms and will depend greatly on the type
of site you are creating. Still, many Web pages have structural
elements in common. Along with the markup that sets content
elements such as headers, paragraphs, lists, links, and forms; we’ll
add certain IDs and classes that will be used to define those struc-
tural elements.
210
211
SP EA KI NG LI K E A NAT IV E
LAYO UT
Structure continued
Sections (12, 13, 17, 20, 22, 24, 28): Blocks within the grid
containing content and functionality.
212
voxLibris Main
i n d ex . h t m l
see Appendix A.
213
SP EA KI NG LI K E A NAT IV E
LAYO UT
Structure continued
Adding CSS
Different strategies for voxLibris will use the modular library approach to adding exter-
adding external style nal style sheets. The idea is to set up several external files based
sheets are detailed in
on use and import them into a single CSS file, which then gets
Chapter 7, “Designing
with CSS” in the linked to the target HTML file. This gives you the versatility
“Prototype: Combining to quickly change one part of the design or interface simply by
Style Sheets” section. swapping style sheets.
default.css: Resets the browser default styles and sets the site-
wide default styles. This style sheet is detailed later in this
chapter.
layout.css: Defines the grid structure and layout for the page.
This style sheet is detailed later in this chapter.
214
voxLibris Main
m a in . c s s
default.css
aul
ult.cs
ul
ult csss
cs
CSS
@import
layout.css
out
utt.css
csss
@import
CSS
main.css
ain
in
n.css
css <link> index.html
ex.
x ht
html
ml
@import
CSS
HTML
navigation.css
gati
atiion
on.css
n csss
CSS @import
chrome.css
ome
me.css
me csss
CSS
01 /*---------------------------------------------------------------------
02 Imported Styles
03 ---------------------------------------------------------------------*/
04 @import url("default.css");
05 @import url("layout.css");
06 @import url("navigation.css");
07 @import url("chrome.css");
215
SP EA KI NG LI K E A NAT IV E
LAYO UT
Default Styles
It’s an important fact of life with CSS that, once a style is set,
it’s set not only for the particular HTML tag it’s being applied
to, but to all tags within that tag as well. To make adding new
styles as easy as possible, there are two default styles that you
need to know.
216
Default Styles
d e fau l t . c s s
01 /*--------------------------------------------------------------------- 18 /*---------------------------------------------------------------------
02 Reset Browser Inherited Styles 19 Default Styles
03 ---------------------------------------------------------------------*/ 20 ---------------------------------------------------------------------*/
04 html, body, div, span, applet, object, iframe, h1, h2, 21 body, input, select {
h3, h4, h5, h6, p, blockquote, pre, a, abbr, 22 color: rgb(105,105,105);
acronym, address, big, cite, code, del, dfn, em, 23 font-family: “fontin sans”, optima,
font, img, ins, kbd, q, s, samp, small, strike, “trebuchet-MS”, sans-serif; }
strong, sub, sup, tt, var, dd, dl, dt, li, ol, ul,
fieldset, form, label, legend, table, caption, 24 body { background: rgb(0,50,75)
tbody, tfoot, thead, tr, th, td { url(../_images/bg-body.png) repeat 0 0; }
05 margin: 0; 25 h1, h2, h3, h4, h5, h6 {
06 padding: 0; 26 color: rgb(128,128,128);
07 border: 0; 27 font-family: garamond, cochin, times, serif;
08 outline: 0; 28 letter-spacing: 1px;
09 background: none; 29 font-weight: normal; }
10 font-weight: inherit; 30 h1 { font-size: 2.5em; }
11 font-style: inherit; 31 h2 { font-size: 2em; }
12 font-family: inherit; 32 h3 { font-size: 1.25em; }
13 font-size:100%; 33 p {
14 text-align: left; 34 font-size: .75em;
15 line-height: 1; 35 margin: 5px 0;
16 vertical-align: baseline; 36 line-height: 1.5; }
17 list-style: none; } 37 blockquote {
38 font-size: .75em;
39 margin: 10px 0;
40 padding: 10px 0;
41 border-top: 1px solid rgb(128,128,128);
42 border-bottom: 1px solid rgb(128,128,128); }
43 li { font-size: .75em; }
217
SP EA KI NG LI K E A NAT IV E
LAYO UT
The Grid
A simple grid structure uses the HTML framework for CSS
to lay out the page. voxLibris uses page, header, footer, and con-
tent, but other grid sections might be used as defined in the
wire frames while planning the site.
Fluid and fixed grid lay- When you planned your design, one of the first things you
outs are discussed in
needed to decide was whether you would use a fluid or fixed
Chapter 7, “Designing
with CSS” in the “Page
layout. voxLibris uses a fixed width of 980px, so we set that as
Flow” section. the width using the page ID (04). If we wanted to make this
page fluid, we would set the width as a percentage or use max/
min widths.
Rows
The <div> tags used to create each row will include the row class
and a row ID with specific styles.
Create the row class and then IDs for individual rows based
on purpose (header, content, footer).
For the fix to dealing Be careful when using padding with grid elements, since
with padding in IE6, padding will throw the dimensions off in IE6. If padding is
read the “Box Model
added to an axis that does not have an absolute length set,
Problem in IE6” sec-
tion in Chapter 6. there is no problem. If the axis does have an absolute length
set, though, then IE will shrink the box to accommodate
the padding.
218
Grid:
Rows
grid.css
footer.
01 /*--------------------------------------------------------------------- 09 /*---------------------------------------------------------------------
02 Grid 10 Grid - Rows
03 ---------------------------------------------------------------------*/ 11 ---------------------------------------------------------------------*/
04 #page { 12 .row {
05 position: relative; 13 position: relative;
06 display: block; 14 display: block;
07 margin:0 auto; 15 margin:0 auto; }
08 width: 980px; } 16 #header { height: 100px; }
17 #content { padding-top: 20px; }
18 #footer { height: 20px; }
219
SP EA KI NG LI K E A NAT IV E
LAYO UT
Columns
Columns are used to establish a vertical rhythm within the page,
allowing you to present information from left to right and make
better use of screen real estate.
As with other grid elements, set the position property for all
columns so that child elements will position themselves from
the column’s origin (top left corner).
220
Grid: Columns
grid.css
aside2
19 /*---------------------------------------------------------------------
20 Grid - Columns
21 ---------------------------------------------------------------------*/
22 .column {
23 position: relative;
24 display: block;
25 float: left; }
26 .alignclear { clear: both; }
27 #aside1 {
28 top: 60px;
29 left: -80px;
30 width: 314px; }
31 #article1 {
32 left: -40px;
33 width: 470px; }
34 #aside2 { width: 190px; }
221
SP EA KI NG LI K E A NAT IV E
LAYO UT
Sections
Sections (sometimes called modules) are content and functional-
ity blocks within the grid.
As with other grid elements, set the position property for all
sections so that child elements will position themselves from
the column’s origin (top left corner).
222
Grid: Sections
grid.css
are located.
35 /*---------------------------------------------------------------------
36 Grid - Sections
37 ---------------------------------------------------------------------*/
38 .section {
39 position: relative;
40 display: block; }
41 #aside1 .section {
42 width: 100%;
43 padding-bottom: 60px; }
44 #aside1 .section h2 {
45 width: 100%;
46 padding: 80px 0 8px 18%; }
47 #aside1 .section div.content { width: 100%; }
48 #aside1 .section p, #aside1 .section ul {
49 width: 65%;
50 margin: 0 auto;
51 margin-bottom: 5px; }
52 #article1 .section .column { width: 210px; }
53 #article1 .section .column+.column { float: right; }
54 #article1 .section .column p { min-height: 110px; }
223
The fonts you choose convey as much of your Web site’s message
as your words. The initial response to a Web page is a visceral
one—a reaction to the visual design—rather than a conscious
thought. This happens within seconds of the page loading, and
beyond the images, chrome, and colors, one of the first things the
visitor notices is all of the squiggles making words.
The sad fact is, though, Web typography is mostly boring because
the only font families at your disposal (unless you put the text
into a graphic) are the typefaces installed on the end user’s
machine. All this may seem very limiting at first, but it’s not
nearly as bad as most designers believe.
CHAPTER 9
Typography
SPEA KIN G L I KE A N ATI V E
T YPO G R AP HY
Font Choices
The process of defining the typeface for a particular block of
text is relatively straightforward—specify a list of font-family
names, separated by commas, with the last name in the list being
a generic font family (serif, sans-serif, monospace, handwritten,
or fantasy). If a particular font in the list is not available, the
browser moves to the next one, until there is a match.
i love typography
226
Andale Mono
Arial
Arial Black
Courier New
Comic Sans MS
Georgia
Impact
Times New Roman
Trebuchet MS
Verdana
Webdings
227
SPEA KIN G L I KE A N ATI V E
T YPO G R AP HY
Web-Safe Fonts
For a complete list of The 11 core Web fonts are installed almost universally on all com-
the Web-Safe fonts puters. However, there are many other fonts commonly installed
with samples, check
on the end user’s computer that are commonly overlooked. These
out speaking-in-styles.
com/typography/web- fonts can be safely employed in your designs, using CSS:
safe-fonts.
01 Operating system fonts: All operating systems come with
pre-installed fonts. In addition to the core Web fonts,
Windows XP adds 9 typefaces, Windows Vista adds another
7 (16 total), and Mac OS X supplies a whopping 30 fonts.
03 iLife fonts: All Macs (consumer and Pro) have Apple iLife
pre-installed, which has 13 fonts pre-installed.
let’s just keep it that way. Keep in mind that when you are defining
the font property in CSS, you are defining the weight, style, varia-
228
Andale Mono Franklin Gothic Book
Arial Narrow Franklin Gothic Medium
Arial Rounded MT Bold Garamond
Baskerville Old Face Gill Sans MT
Bauhaus 93 Gill Sans Ultra Bold
Bell MT Gloucester MT Extra Condensed
Bernard MT Condensed Goudy Old Style
Book Antiqua Haettenschweiler
Bookman Old Style Harrington
Bradley Hand ITC TT Imprint MT Shadow
Britannic Bold Lucida Bright
Brush Script MT Lucida Calligraphy
Lucida Console
Calisto MT Lucida Fax
Lucida Sans
Lucida Sans Typewriter
Century Lucida Sans Unicode
Century Gothic Mistral
Century Schoolbook
Colonna MT MS Reference Sans Serif
Onyx
Papyrus
Cooper Black Perpetua
Copperplate Gothic Bold Perpetua Titling MT
Copperplate Gothic Light Playbill
Rockwell
Courier New Rockwell Extra Bold
Curlz MT STENCIL
Edwardian Script ITC
Tahoma
Engravers MT Tw Cen MT
Footlight MT Light Wide Latin
229
SPEA KIN G L I KE A N ATI V E
T YPO G R AP HY
Downloadable Fonts
The holy grail of Web typography is downloadable fonts. After
all, Adobe Flash allows you to use any font at your disposal in
your design by embedding the font in the SWF file. Why can’t
we just download a font file (like we do an image file) to be used
by CSS? The short answer is, surprisingly, we can, or at least CSS
has the grammar to allow exactly that.
Using the @fontface rule you can set the source of a font file
and give it a unique name for use within your designs. For
example, placing
at the top of your CSS imports the Open Type font Fontin_
Sans_R_45b.otf, which can be referenced in the CSS as
fontin sans.
Before you get too excited, though, currently, only Sa3.1+ sup-
ports the downloading of the common font formats True Type
(.ttf ) and Open Type (.otf ). Although
How Fast Are Downloadable both Op and FF have plans to add sup-
Fonts? port, the big holdout it is IE. What could
Microsoft possibly have against download-
A font file is a file, so it has to be downloaded,
able fonts? To understand their reasoning,
which can affect performance. Currently
you would first have to understand the
there is no way to subset fonts (just download
vagaries of end user license agreements
the needed glyphs to render the page), but
(EULA) and intellectual property (IP).
the font will be cached, so once downloaded
Still, you can support downloadable fonts
for one page, it’s available for other pages in your designs as long as you are willing
much more quickly. to think fluidly about your typography.
230
Font Face Rule Name You Give It
@font-face {
font-family: "fontin sans";
src: url( fonts/Fontin_Sans_R_45b.otf );
}
URL for File
231
SPEA KIN G L I KE A N ATI V E
T YPO G R AP HY
Fluid Typography
At first, Web typography can seem stiflingly limited, with few
typestyles to choose from and limited controls. This is especially
true if you are a designer who wants your results to look exactly
like in your visual comps. If you are willing to think more fluidly
about your typography, though, giving up some control, you will
find more alternatives.
For the level 1 header, I’m using Garamond from the Web-safe
font list, Times from the core Web fonts list, and Serif as the
generic font.
232
p{ font-family: "fontin sans", optima, "trebuchet-MS", sans-serif; }
233
SPEA KIN G L I KE A N ATI V E
T YPO G R AP HY
Choosing Typefaces
Although fluid typography frees you to try different typefaces,
there are a few important ideas to keep in mind while putting
together your font-family list:
For headline copy, use fonts with similar widths and kerning.
Headlines generally have a finite space they can fill (one or
two lines), so it’s important that the typefaces you choose
run roughly the same length.
For body copy, select fonts with bold, italic, and bold/italic
versions. Fonts that do not have specific weight and style ver-
sions will be synthesized by the browser, which is generally
not as attractive as a true version.
234
Welcome Fontin Sans
Welcome Optima
Welcome Trebuchet-MS
Fontin Sans Optima Trebuchet-MS
Lorem ipsum dolor sit Lorem ipsum dolor sit Lorem ipsum dolor sit
amet, consectetur amet, consectetur amet, consectetur
adipiscing elit. adipiscing elit. adipiscing elit.
Vestibulum commodo Vestibulum commodo Vestibulum commodo
metus sit amet libero. metus sit amet libero. metus sit amet libero.
Cras nisl neque, lacinia Cras nisl neque, lacinia Cras nisl neque, lacinia
id, mollis vel, dictum ac, id, mollis vel, dictum ac, id, mollis vel, dictum
ante. Vestibulum tortor ante. Vestibulum tortor ac, ante. Vestibulum
dui, convallis a, dapibus dui, convallis a, dapibus tortor dui, convallis a,
vitae, volutpat nec, justo. vitae, volutpat nec, justo. dapibus vitae, volutpat
Integer dui. Integer dui. nec, justo. Integer dui.
Downloaded Core
235
SPEA KIN G L I KE A N ATI V E
T YPO G R AP HY
S i z i n g Te x t i n C S S
Although you can set your font size using a variety of units, the most
versatile method is to set the font size to 100% in the body tag
(which uses the browser’s default size as its basis) and then use
ems to set the specific font sizes for individual elements as needed.
Using ems will set font size relative to one another and parent ele-
ments, meaning that the page will scale up and down gracefully if
sizes set in pixels when zooming in and out, so, if you are not into
doing the math to keep up with using ems, you are increasingly safe
using pixels.
236
Exljbris Font Foundry
j o s b u i ve n g a. d e m on . n l
voxLibris site.
237
SPEA KIN G L I KE A N ATI V E
T YPO G R AP HY
Styling Text
Because styles are inherited, the first place to set your default
typographic styles (or to change them from the browser defaults)
is in the body, input, and select HTML selectors. This will
set your defaults over the entire page, so you will only need to
set these properties again if you want to change them for a
specific element.
Headers
Headers are commonly differentiated through font family, color,
size, and weight. You might also want to add some letter or word
spacing , but use those styles sparingly—a little goes a long way.
01 When setting header styles, it’s best to set all of the com-
mon styles first (05).
238
01 body, input, select { 10 h1 { font-size: 2.5em; }
02 font-size: 100%; 11 h2 { font-size: 2em; }
03 color: rgb(105,105,105); 12 h3 { font-size: 1.25em; }
04 font-family: “fontin sans”, optima, candara, 13 h4, h5, h6 { font-size: 1em; }
“trebuchet-MS”, sans-serif; } 14 #column1 .sidebar h2 {
05 h1, h2, h3, h4, h5, h6 { 15 font-variant: small-caps;
06 color: rgb(128,128,128); 16 color: red; }
07 font-family: garamond, cochin, cambria, times, 17 #column3 h2 {
serif; 18 font-size: 1.5em;
08 letter-spacing: 1px; 19 text-align: center;
09 font-weight: normal; } 20 text-transform: uppercase;
21 padding-top: 35px;
22 color: rgb(255,255,255); }
239
SPEA KIN G L I KE A N ATI V E
T YPO G R AP HY
For paragraphs, you may want to make the text a bit smaller
than the standard, set margins above and below, and I always
recommend opening up the line height to at least 1.25 line
spacing (125%) or higher.
For block quotes, you may also want to set a border, back-
ground color, or background image to set the quote off from
other text on the page.
Lists
You can also use the Typographically, lists are indented and often have a lower line
list tag to create a height than paragraphs. Additional, you can set the bullet style,
menu or controls, as
either choosing one of the predefined bullet styles or creating
shown in Chapter 10,
“Navigation.” your own image for the bullet. You might think that using the
list-image property is the easiest way to do that, but that’s not
common practice. Using a background image gives a lot more
versatility.
240
01 p {
02 text-align: left;
03 font-size: .75em;
04 margin: 5px 0;
05 line-height: 1.5; }
06 blockquote {
07 font-size: .75em;
08 margin: 10px 0;
09 border: 1px solid rgb(128,128,128);
10 line-height: 1; }
01 li {
02 font-size: .75em;
03 margin: 5px 0;
04 line-height: 1; }
05 ul li {
06 list-style: none;
07 list-style-position: inside;
08 background: transparent url(../_images/
flourish-left.png) no-repeat 0 center;
09 padding: 25px; }
241
Hypertext links allow you to jump around a Web page, a Web
site, or the entire Web. All links, whether internal or external,
are created using the anchor tag (<a>) to link an image or text
to another location. However, different types of links should be
styled differently.
CHAPTER 10
Navigation
SP EA KI NG LI K E A NAT IV E
N AV I G AT I O N
CSS Sprites
All navigation in a Web browser, whether a hypertext link or
a menu option, relies on the anchor tag (a). This tag has four
distinct states accessed through the link pseudo-classes: a:link,
a:visited, a:hover, and a:active. An effective way of showing the
change in states is swapping the background image. However,
image swapping has two important shortcomings:
Rijksmuseum
ww w.r ijk sm u seu m .n l
244
background: transparent 0 px
url(../_images/icon-pointer-sprite.png) 25 px
no-repeat right 0;
height: 15px; 50 px
_height: 20px; 75 px
padding: 0 40px 5px 0;
icon-pointer-sprite.png
Link
background-position: right 0; Read More
Visited
background-position: right -25px; Read More
Hover
background-position: right -50px; Read More
Active
background-position: right -75px; Read More
245
SP EA KI NG LI K E A NAT IV E
N AV I G AT I O N
Links
Remember to style links not only for how they will appear when
the page first loads, but also for the different states they have as
the user interacts with them. You should style each of the four
link states separately. In addition, since all links are controlled
through the same HTML tag, it’s important to differentiate their
styles based on context.
voxLibris.
246
01 /*---------------------------------------------------------------------
02 Links - Defaults
03 ---------------------------------------------------------------------*/
04 a { text-decoration: none; }
05 a:link { color: rgb(0,85,126); }
06 a:visited { color: rgb(0,50,75); }
07 a:hover { color: rgb(0,170,255); }
08 a:active { color: rgb(255,215,0); }
09 /*---------------------------------------------------------------------
10 Links - Paragraph
11 ---------------------------------------------------------------------*/
12 p a:link, p a:visited {
13 background: transparent
url(../_images/bg-p-a-link.png)
repeat-x 0 -2px; }
14 p a:hover {
background-position: -20px -2px; }
15 p a:active { background-image: none; }
16 p a.readmore {
17 position: relative;
18 background: transparent
url(../_images/icon-pointer-sprite.png)
no-repeat right 0;
19 padding: 0 40px 5px 0;
20 _background: none; }
21 p a.readmore:link {
22 background-position: right 0; }
23 p a.readmore:visited {
24 background-position: right -25px; }
25 p a.readmore:hover {
26 background-position: right -50px; }
27 p a.readmore:active {
28 background-position: right -75px; }
247
SP EA KI NG LI K E A NAT IV E
N AV I G AT I O N
Menus
Menus are a list of links that allow the user to navigate sections
and sub-sections within a Web site. Although the links could
simply be grouped together, it’s better to use the list tag (<li>) to
show their relationship. Navigation links also use the anchor tag,
but some different styles should be added to differentiate them.
Whether the top level (sometimes called “global”) navigation
menus run horizontally or vertically, it’s imperative that they are
clear and easy to identify.
248
29 /*---------------------------------------------------------------------
30 Menus
31 ---------------------------------------------------------------------*/
32 #menumain ul.menu li {
33 display: block;
34 padding: 5px 0;
35 border-top: 1px solid rgb(192,192,192);
36 width: 100%; }
37 /*---------------------------------------------------------------------
38 Menu - Footer
39 ---------------------------------------------------------------------*/
40 #footer ul.menu li {
41 float: left;
42 padding: 3px 20px;
43 margin: 0;
44 background: none;
45 border-left: 1px solid rgb(128,128,128); }
46 #footer ul.menu li a:link,#footer ul.menu li a:visited {
color: rgb(105,105,105); }
249
SP EA KI NG LI K E A NAT IV E
N AV I G AT I O N
UXBooth
u x b oot h . c om
on the Web—uses
a horizontal menu
250
Tw i s to r i
t wi s to r i .c om
251
SP EA KI NG LI K E A NAT IV E
N AV I G AT I O N
Buttons
Buttons are used to highlight important content on a site that
may not fit into a global menu.
252
47 /*---------------------------------------------------------------------
48 Article 1 - Genre List
49 ---------------------------------------------------------------------*/
50 #genrelist .genrelistbuttons { list-style: none; }
51 #genrelist .genrelistbuttons li {
52 background: none;
53 height: auto;
54 padding: 0;
55 font-size: .875em;
56 float: left;
57 text-align: center;
58 background: rgb(105,105,105)
url(../_images/genreicons/icon-adventure.jpg)
no-repeat center center; 92 /*---------------------------------------------------------------------
59 display: block; 93 Article 1 - Genre List - Icons
60 width: 100px; 94 ---------------------------------------------------------------------*/
61 height: 100px; 95 #genrelist .genrelistbuttons li.genre-adventure {
62 margin: 15px 15px 50px 0; 96 background-image: url(../_images/genreicons/
63 -webkit-border-radius: 10px; icon-adventure.jpg); }
64 -moz-border-radius: 10px; 97 #genrelist .genrelistbuttons li.genre-anthropology {
65 border-radius: 10px; 98 background-image: url(../_images/genreicons/
66 -webkit-box-shadow: rgb(0,0,0) 0 0 5px; icon-anthropology.jpg); }
67 -moz-box-shadow: rgb(0,0,0) 0 0 5px; 99 #genrelist .genrelistbuttons li.genre-children {
68 box-shadow: rgb(0,0,0) 0 0 5px; } 100 background-image: url(../_images/genreicons/
icon-children.jpg); }
69 #genrelist .genrelistbuttons li a {
101 #genrelist .genrelistbuttons li.genre-epic {
70 display: block;
102 background-image: url(../_images/genreicons/
71 opacity: 1; icon-epic.jpg); }
72 width: 100%; 103 #genrelist .genrelistbuttons li.genre-fantasy {
73 background: transparent 104 background-image: url(../_images/genreicons/
url(../_images/button-gel-100.png) icon-fantasy.jpg); }
no-repeat 0 0;
105 #genrelist .genrelistbuttons li.genre-history {
74 _background: none;
106 background-image: url(../_images/genreicons/
75 padding-top: 105px; icon-history.jpg); }
76 color: rgb(169,169,169); 107 #genrelist .genrelistbuttons li.genre-humor {
77 -webkit-border-radius: 10px; 108 background-image: url(../_images/genreicons/
78 -moz-border-radius: 10px; icon-humor.jpg); }
79 border-radius: 10px; } 109 #genrelist .genrelistbuttons li.genre-medical {
80 #genrelist .genrelistbuttons li a em { 110 background-image: url(../_images/genreicons/
81 display: block; icon-medical.jpg); }
82 margin-bottom: 5px; 111 #genrelist .genrelistbuttons li.genre-mystery {
83 font-style: normal; 112 background-image: url(../_images/genreicons/
84 line-height: 1; icon-mystery.jpg); }
85 font-size: 1.25em; 113 #genrelist .genrelistbuttons li.genre-philosophy {
86 color: rgb(105,105,105); 114 background-image: url(../_images/genreicons/
87 font-family: icon-philosophy.jpg); }
garamond, cochin, cambria, times, serif; } 115 #genrelist .genrelistbuttons li.genre-romance {
88 #genrelist .genrelistbuttons li a:hover { 116 background-image: url(../_images/genreicons/
89 opacity: .6; icon-romance.jpg); }
90 border-color: rgb(0,170,255); 117 #genrelist .genrelistbuttons li.genre-scifi {
91 color: rgb(0,0,0); } 118 background-image: url(../_images/genreicons/
icon-scifi.jpg); }
253
SP EA KI NG LI K E A NAT IV E
N AV I G AT I O N
other browsers.
as slick looking.
images.
254
CSS3.info
c ss3 .i nfo
spective. At CSS3.info,
it comprehensible.
255
The chrome (or “skin”) of a Web page is made up of the visual ele-
ments that give it its look and feel. Using backgrounds, you can
add visual elements to your page to frame and highlight the con-
tent of your Web page and guide the user’s eye around.
CHAPTER 11
Chrome
SP EA KI NG LI K E A NAT IV E
CHRO M E
PNG-8: Works a lot like the GIF format, indexing all of the
colors in the image down to a maximum of 256.
Support: Fireworks and Photoshop, although Photoshop
does not include the alpha channel indexed transparency,
where a color is either visible or 100% transparent.
c olo u rlove r s. c om
258
Transparent PNG Transparent GIF
259
SP EA KI NG LI K E A NAT IV E
CHRO M E
In IE6, this will appear with a gray background where the image
should be transparent. Now add the following code immediately
underneath in the CSS rule:
_background: none;
Fixing The Fix
_filter: progid:DXImageTransform.
Use this trick sparingly. There are some prob- Microsoft.AlphaImageLoader
lems with links and form fields if they are on (src="../_images/logo-voxlibris.png",
any part of the transparent area of a PNG sizingMethod="crop");
image; they simply will not work. To fix this Now the transparent PNG will appear as
problem, you need to set positioning for that expected using the AlphaImageLoader
link or form element: a { position: relative; }. and the underscore hack to hide this from
other browsers. You have two options for
Using the AlphaImageLoader can also slow
the sizing method: crop and scale. Crop will
down the page loading in IE6. An alternative
show the image once, while scale stretches
is to always use PNG-8 images for the back-
the image to fill the area. You cannot tile
ground and no AlphaImageLoader, but these
backgrounds with the AlphaImageLoader.
will not look quite as good in IE6.
260
background: transparent url(../_images/logo-voxlibris.png)
no-repeat 0 0;
_background: none;
_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader
(src="../_images/logo-voxlibris.png", sizingMethod="crop");
261
SP EA KI NG LI K E A NAT IV E
CHRO M E
Columns
Designers often prefer balanced columns—that is, columns that
appear to be the same height. One of the drawbacks of layout
bg-page.png with CSS is that you cannot bind column heights together, so,
invariably, one column will be shorter than the others.
262
01 /*---------------------------------------------------------------------
02 Chrome - Grid
03 ---------------------------------------------------------------------*/
04 body { background: rgb(0,50,75)
url(../_images/bg-body.png) repeat 0 0; }
05 #page {
06 background: transparent
url(../_images/bg-page.png) repeat-y 0 0;
07 padding: 0 16px;
08 _background: none;
09 _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader
(src="../_images/bg-page.png", sizingMethod="scale"); }
263
SP EA KI NG LI K E A NAT IV E
CHRO M E
Rows
Rows stretch horizontally across the area defined across the page
area and can be visually defined with a solid color background
bg-header.png
color or background image. If you use a gradient, then you may
want to have it only repeat horizontally (repeat-x) so that the gra-
dient doesn’t create a repeating pattern, but make sure to set the
bottom color in your gradient as the background color for the
row so that there is a smooth color transition.
The voxLibris header and footer use the same repeating gradient
image (bg-header.png) as the background. I opted to reuse
the same image in both. Different images could have been used,
but since they have the same appearance, this reduces the number
of images that have to be downloaded, thus speeding up the
page display.
264
10 #header, #footer { background: transparent
url(../_images/bg-header.png) repeat-x 0 0; }
11 #footer { background-position: 0 bottom; }
265
SP EA KI NG LI K E A NAT IV E
CHRO M E
Logos
Text replacement is any process where HTML is replaced by an
image. There are several ways to achieve text replacement, but the
logo-voxlibris.png best is to use the text in a background image, in an element that
includes the text in the HTML.
Begin by specifying the width and height of the element that will
contain your graphic text. Set the background image source to
the image with the text. Then set the line height to three times
the height of the element and set overflow to hidden, so all text is
pushed out of the box and will not be displayed.
The voxLibris logo uses the Fontin Sans font, which is not a stan-
dard font, so we’ll need to put it into a graphic. We’ll use the level
1 header tag in the #header to create the logo, including the text
“voxLibris”. Set the width and height to be the same as the image
and then triple the line height.
Forms
Form elements are often overlooked as an important element to
skin. Most browsers have a default style for form elements that is,
to be polite, hideously ugly, especially if the rest of the site is well
bg-grad01.png
designed.
For voxLibris, simple gradient, border, and font size changes are
all that are needed to spruce up the form fields.
266
12 /*---------------------------------------------------------------------
13 Chrome - Header - voxLIBRIS logo
14 ---------------------------------------------------------------------*/
15 #header h1 {
16 position: absolute;
17 left: 0;
18 bottom: -2px;
19 width: 306px;
20 height: 66px;
21 line-height: 188px;
22 overflow: hidden;
23 background: transparent
url(../_images/logo-voxlibris.png)
no-repeat 0 0;
24 _background: none;
25 _filter: progid:DXImageTransform.Microsoft.
AlphaImageLoader(src=’../_images/logo-
voxlibris.png’, sizingMethod=’crop’);}
26 /*---------------------------------------------------------------------
27 Chrome - Header - Search
28 --------------------------------------------------------------------*/
29 #header .search input, #header .search select {
30 background: transparent
url(../_images/bg-grad01.png) repeat-x
center center;
31 border: 1px solid rgb(102,102,102);
32 height: 25px;
33 width: 200px;
34 font-size: 1.2em;
35 padding: 0 10px;
36 margin-bottom: 5px;
37 -moz-border-radius: 5px;
38 -webkit-border-radius: 5px;
39 border-radius: 5px; }
40 #header .search select {
41 background-image:
url(../_images/bg-grad01.png);
42 padding-right: 0; }
267
SP EA KI NG LI K E A NAT IV E
CHRO M E
Defining Sections
Sections and modules will often have specialized backgrounds to
set them off from surrounding content. The module will have a
header and footer to cap a central content area whose height will
stretch as needed.
Since transparent PNGs are used for all three backgrounds, the
background color is set to transparent.
bg-ad-head.png
bg-ad-mid.png
bg-ad-foot.png
268
43 /*---------------------------------------------------------------------
44 Chrome - Aside 1 - Section
45 ---------------------------------------------------------------------*/
46 #aside1 .section {
47 background: transparent
url(../_images/bg-sidebar1-foot.png)
no-repeat 0 bottom; }
48 #aside1 .section h2 {
49 background: transparent
url(../_images/bg-sidebar1-head.png)
no-repeat 0 0;
50 text-align: left;
51 max-height: 136px;
52 overflow; hidden;
53 font-variant: small-caps;
54 color: red; }
55 #aside1 .section div.content {
56 background: transparent
url(../_images/bg-sidebar1-mid.png) repeat-y
0 0; }
57 #aside1 .section p, #aside1 .section ul {
58 list-style-position: inside;
59 list-style-type: none;}
60 /*---------------------------------------------------------------------
61 Chrome - Aside 1 - Ads
62 ---------------------------------------------------------------------*/
63 #aside1 .ads {
64 background-image:
url(../_images/bg-ads-foot.png); }
65
66 #aside1 .ads h2 {
67 background-image:
url(../_images/bg-ads-head.png); }
68
69 #aside1 .ads div.content {
70 background-image:
url(../_images/bg-ads-mid.png); }
71
72 #aside1 .ads p {
73 color: rgb(0,0,0);
74 padding: 10px 80px; }
269
SP EA KI NG LI K E A NAT IV E
CHRO M E
Final Flourishes
Another way to define sections on the page is to add rules and
flourishes that guide the visitor’s eye to important locations.
flourish-up.png
Flourishes can take a number of forms but should fit with the
general appearance of your design.
flourish-down.png
The flourishes in the voxLibris article1 section are similar to those
in the logo and in other areas throughout the page. They are
added in the backgrounds of the section and the headlines to give
a top and bottom treatment.
270
75 /*---------------------------------------------------------------------
76 Chrome - Article
77 ---------------------------------------------------------------------*/
78 #article1 .section h1 {
79 padding-top: 30px;
80 text-transform: uppercase;
81 text-align: center;
82 background: transparent
url(../_images/flourish-up.png) no-repeat
center top;
83 _background: none; }
84 #article1 .section {
85 background-position: bottom center;
86 padding-bottom: 50px;
87 margin-bottom: 3px;
88 background: transparent
url(../_images/flourish-up.png) no-repeat
center bottom;
89 _background: none;}
90 #article1 .section h2 {
91 font-variant: small-caps;
92 margin: 3px 0 30px 0;
93 height: 35px;
94 background: transparent
url(../_images/flourish-down.png) no-repeat
center 3px;
95 border-top: 1px solid rgb(128,128,128);
96 _background: none; }
97 #article1 .section h3 {
98 font-family: "fontin sans", optima, candara,
"trebuchet-MS", sans-serif;
99 height: 50px;
100 margin-top: 20px; }
101 #article1 .section p {
102 margin-bottom: 20px; }
103 #article1 ul li {
104 list-style: none;
105 list-style-position: inside;
106 background: transparent
url(../_images/flourish-left.png) no-repeat 0
center;
107 padding: 10px 25px;
108 _background: none; }
271
That’s about it. If you’ve read this book front to back, you should
now understand the fundamentals of CSS—how to speak it and
how to understand it. Like any language, there is always more to
learn—nuances that turns humdrum prose into compelling poetry.
In this last chapter, I want to offer a few parting words about the
state of CSS and to review some of the best practices I’ve stressed
throughout the book.
CHAPTER 12
The Last Word
SP EA KI NG LI K E A NAT IV E
THE L AST WORD
CSS Validation
I’ve mentioned throughout this book that CSS is a standard cre-
ated by the World Wide Web Consortium (W3C), and that the
browser manufacturers then interpret this standard—with vary-
ing degrees of success—to create their products. In theory, since
there is an accepted standard CSS, there is “perfect” CSS code
that exactly follows these standards.
The W3C has created a Web site that will validate your CSS
code, checking that it adheres to the W3C specified CSS stan-
dard. To use the W3C Validation Service:
01 Visit jigsaw.w3.org/css-validator/.
If there are problems, don’t sweat it. First check what the errors
are. Some of the “hacks” we use to create Web sites that work
cross-browser will cause errors, even though they do not interfere
with the page displaying.
Good
goo d. is
274
Designing for Web Standards?
Standards are important. The closer we can get to ideal CSS, the
better it is for everybody. If we could simply code to the CSS
standard and know our designs would display the same way in all
browsers, what a wonderful world it would be.
It is far more important that your code Although “errors” in your CSS can be accept-
works, is fast, and is easy to edit than it is able if you need to include code for IE6,
for it to be valid according to the W3C. errors in your HTML can be the cause of
275
SP EA KI NG LI K E A NAT IV E
THE L AST WORD
a grain of salt.
276
CSS Import
cssimpo r t . co m
277
SP EA KI NG LI K E A NAT IV E
THE L AST WORD
CSS Frameworks
A CSS framework is a library of generic styles that can be easily
applied to most Web designs. They come in the form of pre-built
external style sheets that package ready-made design solutions for
common elements such as headers, columns, footers, and sections.
Using a CSS framework allows designers quick and easy access to
well tested, cross-browser compatible, and standards-compliant
CSS code. This tends to speed development of better code.
278
Creating Your Own
CSS Frameworks
If you are working in an environment where multiple sources
are creating your Web content, you need a common library of
styles. To facilitate a consistent layout, you can create your own
CSS framework, often simple editorial styles, that the group then
shares and can apply to their content. This also helps prevent
writers or editors from adding inline or embedded styles when
they need a particular style.
279
SP EA KI NG LI K E A NAT IV E
THE L AST WORD
Mobile Devices
Setting the media Mobile devices are a popular way to access the Web, but not
type is explained
particularly good for displaying Web pages designed for larger
in the “Media” sec-
tion of Chapter 5,
screens. Fortunately, CSS allows you to set style sheets specifically
“Semantics.” for mobile screens, but you need to keep a few things in mind
when creating mobile designs:
280
Print
Viewing a printed Web page is a very different experience than
viewing it on a screen (even a small screen). Paper, by its very
nature, is not hyper-textual. However, paper is more portable and
cheaper than a computer, and many of your visitors will opt to
print Web pages rather than reading them on the screen. To that
end, you should adapt your designs for print:
281
SP EA KI NG LI K E A NAT IV E
THE L AST WORD
General
External style sheets Use external style sheets.
are explained in
The power of using CSS comes in its ability to make a single
“Where to Put Style
Rules” in Chapter 5,
change that effects an entire Web site. This power is only
“Semantics.” possible, though, when styles are collected into external style
sheet files.
282
Avoid inline styles.
Inline styles cannot be overridden, making it impossible to
change whatever styles they set and limiting design flexibil-
ity. Inline styles also increase the code-to-text ratio, dimin-
ishing search engine optimization (SEO) and lowering your
ranking in many search engines.
283
SP EA KI NG LI K E A NAT IV E
THE L AST WORD
Design
Use <img> tags for image content (photos, illustrations,
diagrams, and so on), not for your interface.
Placing an image in your HTML means that it cannot be
easily styled or changed. Virtually all interface chrome—
including icons, logos, controls, and buttons—can be added
to the interface using background images in your CSS. This
will cut down on the amount of code in your HTML, which
is better for SEO, and allow for greater versatility when
redesigning.
284
Coding
Add comments to your CSS wherever possible to help Comments are
explained in the sec-
explain what’s going on.
tion “Adding Notes to
Notes can be added as a last step in development, but should CSS” in Chapter 5,
be included to help future designers and developers. “Semantics.”
Use ems for all sizes or ems for font sizing, pixels for
absolute sizes, and percentages for relative sizes.
There is an ongoing debate as to whether ems or pixels are
better for creating Web designs. If you choose to go with all
ems, you need to become familiar with a good pixel-to-em
calculator, like Em Calculator (riddle.pl/emcalc).
285
SP EA KI NG LI K E A NAT IV E
THE L AST WORD
Optimizing
Use CSS property shortcuts wherever possible.
Many CSS properties can be combined into a single prop-
erty using a shortcut. For example,
border-top:5px; border-right:5px;
border-bottom:1px; border-left:2px;
can better be expressed as:
border:5px 5px 1px 2px;
Use as few IDs as possible, and use each only once per
Web page.
The more IDs you have, the more complicated your code
gets. Generally you can get by with only a few IDs for major
page grid sections. If you can use more than one ID in a con-
textual selector, you’ve got too many IDs.
286
This page intentionally left blank
291 A : vox Li br is Co de
303 B: CSS Va l u es
speaking-in-styles.com/book
APPENDIX A
voxLibris Code
AP PEN D IX ES
A: VOX L IB RI S CO D E
index.html
For details about The content for the page is in the file index.html, which includes
index.css, see Chapter
all of the HTML needed to create the structure of the page, but
8, “Layout.”
none of the styles. As with all HTML pages, it is composed of
metadata between the <head> tags (03–07) and content between
the <body> tags (08–139).
<br class="alignclear"/>
292
01 <!DOCTYPE html PUBLIC "-//W3C//DTD 44 Countdown The Most Outrageous Moments In
XHTML 1.0 Strict//EN"z "http://www. Comic Book History!<br />
w3.org/TR/xhtml1/DTD/xhtml1-strict. 45 <a href="#">www.UGO.com/Comics</a></p>
dtd"> 46 <p><strong>HP Global Citizenship</
02 <html xmlns="http://www.w3.org/1999/xhtml"> strong><br />
03 <head> 47 Why Protecting Privacy is Essential For Socially
04 <meta http-equiv="Content-Type" content="text/ Responsible Companies<br />
html; charset=ISO-8859-1" /> 48 <a href="#">www.hp.com</a></p>
05 <title>voxLIBRIS</title> 49 <p><strong>Environments</strong><br />
06 <link href="_css/main.css" rel="stylesheet" 50 Find Environments & More Environments
type="text/css" media="all"/> Options Here!<br />
07 </head> 51 <a href="#">Octopedia.com</a></p>
08 <body> 52 <p class="textalignright">Ads by <strong>Oogle
09 <div id="page"> </strong></p>
10 <div id="header" class="row"> 53 </div>
11 <h1>voxLIBRIS</h1> 54 </div>
12 <div id="searchmain" class="section search"> 55 </div>
13 <form> 56 <div id="article1" class="column">
14 <input type="text" value="search" /> 57 <div id="genrelist" class="section">
15 <br class="alignclear" /> 58 <h1>Genres</h1>
16 <select> 59 <ul class="genrelistbuttons">
17 <option>titles</option> 60 <li class="genre-adventure">
18 <option>authors</option> <a href="#"><em>Adventure </em>34
19 <option>full text</option> books</a></li>
20 </select> 61 <li class="genre-anthropology">
21 </form> <a href="#"><em>Anthropology
22 </div> </em>12 books</a></li>
23 </div> 62 <li class="genre-children">
24 <div id="content" class="row"> <a href="#"><em>Children </em>90
books</a></li>
25 <div id="aside1" class="column">
63 <li class="genre-epic"><a href="#"><em>Epic
26 <div id="menumain" class="section"> </em>6 books</a></li>
27 <h2>Welcome</h2> 64 <li class="genre-fantasy"><a
28 <div class="content"> href="#"><em>Fantasy </em>13 books
29 <p>voxLIBRIS provides public domain </a></li>
audiobooks you can download free of 65 <li class="genre-history"><a
charge.</p> href="#"><em>History </em>46 books
30 <ul class="menu"> </a></li>
31 <li><a href="#">Genres</a></li> 66 <li class="genre-humor"><a
32 <li><a href="#">About</a></li> href="#"><em>Humor </em>18 books
33 <li><a href="#">News</a></li> </a></li>
34 <li><a href="#">Reviews</a></li> 67 <li class="genre-medical">
35 <li><a href="#">Donate</a></li> <a href="#"><em>Medical </em>21
36 <li><a href="#">Contact</a></li> books
37 </ul> </a></li>
38 </div> 68 <li class="genre-mystery">
39 </div> <a href="#"><em>Mystery </em>67
40 <div id="ads01" class="section ads"> books</a></li>
41 <h2></h2> 69 <li class="genre-philosophy">
42 <div class="content"> <a href="#"><em>Philosophy </em>2
books</a></li>
43 <p><strong>Top 50 WTF Comic Moments
</strong><br />
293
AP PEN D IX ES
A: VOX L IB RI S CO D E
index.html CONTINUED
294
main.css
All external CSS code for voxLibris is imported into main.css. For details about
01 /*---------------------------------------------------------------------
02 Imported Styles
03 ---------------------------------------------------------------------*/
04 @import url(default.css);
05 @import url(layout.css);
06 @import url(navigation.css);
07 @import url(chrome.css);
295
AP PEN D IX ES
A: VOX L IB RI S CO D E
default.css
For details about Default styles for the site reset the browser defaults—giving us a
default.css, see
level playing field for the different browsers—and set site specific
Chapter 8, “Layout.”
general styles for the HTML.
01 /*--------------------------------------------------------------------- 19 /*---------------------------------------------------------------------
02 Reset Browser Inherited Styles 20 Default Styles
03 ---------------------------------------------------------------------*/ 21 ---------------------------------------------------------------------*/
04 22 body, input, select {
05 html, body, div, span, applet, object, iframe, h1, h2, 23 color: rgb(105,105,105);
h3, h4, h5, h6, p, blockquote, pre, a, abbr, 24 font-family: "fontin sans", optima, candara,
acronym, address, big, cite, code, del, dfn, em, "trebuchet-MS", sans-serif; }
font, img, ins, kbd, q, s, samp, small, strike, 25
strong, sub, sup, tt, var, dd, dl, dt, li, ol, ul,
26 h1, h2, h3, h4, h5, h6 {
fieldset, form, label, legend, table, caption,
tbody, tfoot, thead, tr, th, td 27 color: rgb(128,128,128);
06 { 28 font-family: garamond, cochin, cambria, times,
07 margin: 0; serif;
08 padding: 0; 29 letter-spacing: 1px;
09 border: 0; 30 font-weight: normal; }
31
10 outline: 0;
11 background: none; 32 h1 { font-size: 2.5em; }
12 font-weight: inherit; 33 h2 { font-size: 2em; }
13 font-style: inherit; 34 h3 { font-size: 1.25em; }
14 font-family: inherit; 35 h4, h5, h6 { font-size: 1em; }
15 font-size:100%; 36 p {
16 text-align: left; 37 text-align: left;
17 vertical-align: baseline; 38 font-size: .75em;
18 list-style: none; } 39 margin: 5px 0;
40 line-height: 1.5; }
41 blockquote {
42 font-size: .75em;
43 margin: 10px 0;
44 padding: 10px 0;
45 border-top: 1px solid rgb(128,128,128);
46 border-bottom: 1px solid rgb(128,128,128);
47 line-height: 1; }
48 li {
49 font-size: .75em;
50 margin: 2px 0; }
296
layout.css
The layout styles establish the layout grid in the design, defining For details about lay-
out.css, see Chapter
how rows, columns, and sections should be placed.
8, “Layout.”
01 /*--------------------------------------------------------------------- 36 /*---------------------------------------------------------------------
02 Grid 37 Grid - Sections
03 ---------------------------------------------------------------------*/ 38 ---------------------------------------------------------------------*/
04 #page { 39 .section {
05 position: relative; 40 position: relative;
06 display: block; 41 display: block; }
07 margin:0 auto; 42 #header .search {
08 width: 980px; 43 position: absolute;
09 _width: 960px; } 44 right: 10px;
10 /*--------------------------------------------------------------------- 45 top: 10px; }
11 Grid - Rows 46 #footer .copyright {
12 ---------------------------------------------------------------------*/ 47 margin: 0 20px;
13 .row { 48 float: left; }
14 position: relative; 49 #aside1 .section {
15 display: block; 50 width: 100%;
16 margin:0 auto; } 51 padding-bottom: 60px; }
17 #header { height: 100px; } 52 #aside1 .section h2 {
18 #content { padding-top: 20px; } 53 width: 100%;
19 #footer { height: 20px; } 54 padding: 80px 0 8px 18%; }
20 /*--------------------------------------------------------------------- 55 #aside1 .section div.content { width: 100%; }
21 Grid - Columns 56 #aside1 .section p, #aside1 .section ul {
22 ---------------------------------------------------------------------*/ 57 width: 65%;
23 .column { 58 margin: 0 auto;
24 position: relative; 59 margin-bottom: 5px; }
25 display: block; 60 #article1 .section .column { width: 210px; }
26 float: left; } 61 #article1 .section .column+.column { float: right; }
27 .alignclear { clear: both; } 62 #article1 .section .column p { min-height: 110px; }
28 #aside1 {
29 top: 60px;
30 left: -80px;
31 width: 314px; }
32 #article1 {
33 left: -40px;
34 width: 470px; }
35 #aside2 { width: 190px; }
297
AP PEN D IX ES
A: VOX L IB RI S CO D E
navigation.css
For details about All link, menu, and button styles are set in navigation.css.
navigation.css,
Remember to set the styles for all of the different link states
see Chapter 10,
“Navigation.”
(:link, :visited, :active, and :hover).
01 /*--------------------------------------------------------------------- 30 /*---------------------------------------------------------------------
02 Links 31 Menus
03 ---------------------------------------------------------------------*/ 32 ---------------------------------------------------------------------*/
04 a { text-decoration: none; } 33 ul.menu li a {
05 a:link { color: rgb(0,85,126); } 34 font-family: garamond, cochin, cambria, times,
06 a:visited { color: rgb(0,50,75); } serif;
07 a:hover { color: rgb(0,170,255); } 35 text-transform: uppercase; }
08 a:active{ color: rgb(255,215,0); } 36 /*---------------------------------------------------------------------
09 /*--------------------------------------------------------------------- 37 Menus - Menu
10 Links - Paragraph 38 ---------------------------------------------------------------------*/
11 ---------------------------------------------------------------------*/ 39 #menumain ul.menu li {
12 p a:link, p a:visited { 40 display: block;
13 background: transparent url(../_images/bg-p- 41 padding: 5px 0;
a-link.png) repeat-x 0 -2px; } 42 border-top: 1px solid rgb(192,192,192);
14 p a:hover { background-position: -20px -2px; 43 width: 100%; }
} 44 /*---------------------------------------------------------------------
15 p a:active { background-image: none; } 45 Navigation - Footer
16 46 ---------------------------------------------------------------------*/
17 p a.readmore { 47 #footer ul.menu li {
18 position: relative; 48 float: left;
19 background: transparent url(../_images/icon- 49 padding: 3px 20px;
pointer-sprite.png) no-repeat right 0; 50 margin: 0;
20 padding: 0 40px 5px 0; 51 background: none;
21 _background: none; } 52 border-left: 1px solid rgb(128,128,128); }
22 p a.readmore:link { 53 #footer ul.menu li a:link,#footer ul.menu li a:visited {
23 background-position: right 0; } color: rgb(105,105,105); }
24 p a.readmore:visited {
25 background-position: right -20px; }
26 p a.readmore:hover {
27 background-position: right -40px; }
28 p a.readmore:active {
29 background-position: right -60px; }
298
54 /*--------------------------------------------------------------------- 97 #genrelist .genrelistbuttons li.genre-adventure {
55 Article 1 - Genre List 98 background-image: url(../_images/genreicons/
56 ---------------------------------------------------------------------*/ icon-adventure.jpg); }
57 #genrelist .genrelistbuttons { list-style: none; } 99 #genrelist .genrelistbuttons li.genre-anthropology {
58 #genrelist .genrelistbuttons li { 100 background-image: url(../_images/genreicons/
59 background: none; icon-anthropology.jpg); }
60 height: auto; 101 #genrelist .genrelistbuttons li.genre-children {
61 padding: 0; 102 background-image: url(../_images/genreicons/
icon-children.jpg); }
62 font-size: .875em;
103 #genrelist .genrelistbuttons li.genre-epic {
63 float: left;
104 background-image: url(../_images/genreicons/
64 text-align: center; icon-epic.jpg); }
65 background: rgb(105,105,105) url(../_images/ 105 #genrelist .genrelistbuttons li.genre-fantasy {
genreicons/icon-adventure.jpg) no-repeat
center center; 106 background-image: url(../_images/genreicons/
icon-fantasy.jpg); }
66 display: block;
107 #genrelist .genrelistbuttons li.genre-history {
67 width: 100px;
108 background-image: url(../_images/genreicons/
68 height: 100px; icon-history.jpg); }
69 margin: 15px 15px 50px 0; 109 #genrelist .genrelistbuttons li.genre-humor {
70 -webkit-border-radius: 10px; 110 background-image: url(../_images/genreicons/
71 -moz-border-radius: 10px; icon-humor.jpg); }
72 border-radius: 10px; 111 #genrelist .genrelistbuttons li.genre-medical {
73 -webkit-box-shadow: rgb(0,0,0) 0 0 5px; 112 background-image: url(../_images/genreicons/
74 -moz-box-shadow: rgb(0,0,0) 0 0 5px; icon-medical.jpg); }
75 box-shadow: rgb(0,0,0) 0 0 5px; } 113 #genrelist .genrelistbuttons li.genre-mystery {
76 #genrelist .genrelistbuttons li a { 114 background-image: url(../_images/genreicons/
77 display: block; icon-mystery.jpg); }
78 opacity: 1; 115 #genrelist .genrelistbuttons li.genre-philosophy {
79 width: 100%; background: transparent 116 background-image: url(../_images/genreicons/
url(../_images/button-gel-100.png) no-repeat icon-philosophy.jpg); }
0 0; 117 #genrelist .genrelistbuttons li.genre-romance {
80 padding-top: 105px; 118 background-image: url(../_images/genreicons/
81 color: rgb(169,169,169); icon-romance.jpg); }
82 -webkit-border-radius: 10px; 119 #genrelist .genrelistbuttons li.genre-scifi {
83 -moz-border-radius: 10px; 120 background-image: url(../_images/genreicons/
84 border-radius: 10px; } icon-scifi.jpg); }
85 #genrelist .genrelistbuttons li a em {
86 display: block;
87 margin-bottom: 5px;
88 font-style: normal;
89 line-height: 1;
90 font-size: 1.25em;
91 color: rgb(105,105,105);
92 font-family: garamond, cochin, cambria, times,
serif; }
93 #genrelist .genrelistbuttons li a:hover {
94 opacity: .6;
95 border-color: rgb(0,170,255);
96 color: rgb(0,0,0); }
299
AP PEN D IX ES
A: VOX L IB RI S CO D E
chrome.css
For details about The site’s visual appearance is set primarily by the chrome.css file.
chrome.css, see
Chapter 11, “Chrome.”
01 /*--------------------------------------------------------------------- 27 /*---------------------------------------------------------------------
02 Chrome - Grid 28 Chrome - Header - Search
03 ---------------------------------------------------------------------*/ 29 --------------------------------------------------------------------
04 body { background: rgb(0,50,75) url(../_images/ -*/
bg-body.png) repeat 0 0; } 30 #header .search input, #header .search select {
05 #page { 31 background: transparent url(../_images/
06 background: transparent url(../_images/ bg-grad01.png) repeat-x center center;
bg-page.png) repeat-y 0 0; 32 border: 1px solid rgb(102,102,102);
07 padding: 0 16px; 33 height: 25px;
08 34 width: 200px;
09 _background: none; 35 font-size: 1.2em;
10 _filter: progid:DXImageTransform.Microsoft. 36 padding: 0 10px;
AlphaImageLoader(src="../_images/bg-page. 37 margin-bottom: 5px;
png", sizingMethod="scale"); } 38 -moz-border-radius: 5px;
11 #header, #footer { background: transparent url(../_ 39 -webkit-border-radius: 5px;
images/bg-header.png) repeat-x 0 0; }
40 border-radius: 5px; }
12 #footer { background-position: 0 bottom; }
41 #header .search select {
13 /*---------------------------------------------------------------------
42 background-image: url(../_images/bg-grad01.
14 Chrome - Header - voxLIBRIS logo png);
15 ---------------------------------------------------------------------*/ 43 padding-right: 0; }
16 #header h1 {
17 position: absolute;
18 left: 0;
19 bottom: -2px;
20 width: 306px;
21 height: 66px;
22 line-height: 188px;
23 overflow: hidden;
24 background: transparent url(../_images/logo-
voxlibris.png) no-repeat 0 0;
25 _background: none;
26 _filter: progid:DXImageTransform.Microsoft.
AlphaImageLoader(src=’../_images/logo-
voxlibris.png’, sizingMethod=’crop’);}
300
44 /*--------------------------------------------------------------------- 73 /*---------------------------------------------------------------------
45 Chrome - Aside 1 - Section 74 Chrome - Article
46 ---------------------------------------------------------------------*/ 75 ---------------------------------------------------------------------*/
47 #aside1 .section { 76 #article1 .section h1 {
48 background: transparent url(../_images/ 77 padding-top: 30px;
bg-sidebar1-bottom.png) no-repeat 0 bottom; 78 text-transform: uppercase;
} 79 text-align: center;
49 #aside1 .section h2 { 80 background: transparent url(../_images/
50 background: transparent url(../_images/ flourish-up.png) no-repeat center top; }
bg-sidebar1-top.png) no-repeat 0 0; 81 #article1 .section {
51 text-align: left; 82 background-position: bottom center;
52 max-height: 136px; 83 padding-bottom: 50px;
53 overflow; hidden; 84 margin-bottom: 3px;
54 font-variant: small-caps; 85 background: transparent url(../_images/
55 color: red; } flourish-up.png) no-repeat center bottom; }
56 #aside1 .section div.content { 86 #article1 .section h2 {
57 background: transparent url(../_images/ 87 font-variant: small-caps;
bg-sidebar1-mid.png) repeat-y 0 0; } 88 margin: 3px 0 30px 0;
58 #aside1 .section p, #aside1 .section ul { 89 height: 35px;
59 list-style-position: inside; 90 background: transparent url(../_images/
60 list-style-type: none;} flourish-down.png) no-repeat center 3px;
61 /*--------------------------------------------------------------------- 91 border-top: 1px solid rgb(128,128,128); }
62 Chrome - Aside 1 - Ads 92 #article1 .section h3 {
63 ---------------------------------------------------------------------*/ 93 font-family: "fontin sans", optima, candara,
64 #aside1 .ads { "trebuchet-MS", sans-serif;
65 background-image: url(../_images/bg-ads- 94 height: 50px;
bottom.png); } 95 margin-top: 20px; }
66 #aside1 .ads h2 { 96 #article1 .section p {
67 background-image: url(../_images/bg-ads-top. 97 margin-bottom: 20px; }
png); } 98 #article1 ul li {
68 #aside1 .ads div.content { 99 list-style: none;
69 background-image: url(../_images/bg-ads-mid. 100 list-style-position: inside;
png); }
101 background: transparent url(../_images/
70 #aside1 .ads p { flourish-left.png) no-repeat 0 center;
71 color: rgb(0,0,0); 102 padding: 10px 25px;
72 padding: 10px 80px; } 103 _background: none;
104 _filter: progid:DXImageTransform.Microsoft.
AlphaImageLoader
105 (src="../_images/flourish-left.png",
sizingMethod="crop|scale"); }
301
In Chapter 6, we briefly discussed the values that could be used
with different CSS properties. In this appendix, we’ll look at val-
ues for lengths, fonts, URLs, and colors in more detail.
APPENDIX B
CSS Values
AP PEN D IX ES
B: CS S VA LUE S
Lengths
Lengths (width or height) can be set using a variety of units, but
there are two basic types of length values:
Pixels or Ems?
Although you have several unit types to choose from, most Web
designs are created using pixels or ems (or a combination of the
two). Pixels have the advantage of being easy to understand and
apply to screen-based layouts, but ems, a relative rather than abso-
lute measurement, allow for more fluid control that can be grace-
fully scaled on most browsers.
Generally, I use pixels for all non-typographic lengths and ems for
all font and text-based lengths.
Web-Safe Fonts
I have put together an extensive list of fonts that are likely to be installed
on Mac and Windows machines. You can sort the list to see fonts with dif-
characters.
304
Relative Length Values
305
AP PEN D IX ES
B: CS S VA LUE S
Fonts
Font family names are derived from the name of the font.
Entering the entire name as it appears in your operating system.
Font names are not case-sensitive (it doesn’t matter whether you
use upper or lowercase letters), but font names with spaces must
be placed in quotes:
The table on the next few pages shows a list of fonts that are likely
to be installed on both Macs and Windows computers.
speaking-in-styles.com/web-typography/web-safe-fonts
306
Name Weight & Style Sample
Britannic Bold ABC abc 0123
Brush Script MT ABC abc 0123
Calibri Bold, Italic, Bold Italic ABC abc 0123
Calisto MT Bold, Italic, Bold Italic ABC abc 0123
Cambria Bold, Italic, Bold Italic
Ͳͳʹ͵
Candara Bold, Italic, Bold Italic ABC abc 0123
Century ABC abc 0123
Century Gothic Bold, Italic, Bold Italic ABC abc 0123
Century Schoolbook Bold, Italic, Bold Italic ABC abc 0123
Colonna MT ABC abc 0123
Comic Sans MS Bold ABC abc 0123
Consolas Bold, Italic, Bold Italic ABC abc 0123
Constantia Bold, Italic, Bold Italic ABC abc 0123
Cooper Black ABC abc 0123
Copperplate Gothic Bold ABC abc 0123
Copperplate Gothic Light ABC abc 0123
Corbel Bold, Italic, Bold Italic ABC abc 0123
Courier New ABC abc 0123
Curlz MT ABC abc 0123
Edwardian Script ITC
ABC abc 0123
Engravers MT ABC abc 0123
Footlight MT Light ABC abc 0123
Franklin Gothic Book Italic ABC abc 0123
Franklin Gothic Medium Italic ABC abc 0123
Garamond Bold, Italic ABC abc 0123
Georgia Bold, Italic, Bold Italic ABC abc 0123
Gill Sans MT Bold, Italic, Bold Italic ABC abc 0123
Gill Sans Ultra Bold ABC abc 0123
Gloucester MT Extra Condensed ABC abc 0123
307
AP PEN D IX ES
B: CS S VA LUE S
308
URLs
A Uniform Resource Locator (URL) is the unique address of
an item on the Web. It could be an HTML document, external
CSS file, image, JavaScript file, Flash file, a sound file, or any
resource that can be accessed by the Web browser. There are
two types of URLs:
309
AP PEN D IX ES
B: CS S VA LUE S
Color
Colors in CSS are specified either by values specifying the mix-
ture of red, green, and blue used to create the color, or with a spe-
cific color keyword. Keywords are simply shorthand for specific
color values.
Color Opacity
Opacity is set as a property or can be included as part of the RGB
Alpha color format, which includes a decimal value between 0
(transparent) and 1 (opaque). However, this is not currently sup-
ported by all browser. Include both the RGB and RGBA to cover
all browsers:
color: rgb(255,0,0);
color: rgba(255,0,0,.5);
310
Keyword Hex RGB Numeric
aliceblue #F0F8FF 240,248,255
antiquewhite #FAEBD7 250,235,215
aqua #00FFFF 0,255,255
aquamarine #7FFFD4 127,255,212
azure #F0FFFF 240,255,255
beige #F5F5DC 245,245,220
bisque #FFE4C4 255,228,196
black #000000 0,0,0
blanchedalmond #FFEBCD 255,235,205
blue #0000FF 0,0,255
blueviolet #8A2BE2 138,43,226
brown #A52A2A 165,42,42
burlywood #DEB887 222,184,135
cadetblue #5F9EA0 95,158,160
chartreuse #7FFF00 127,255,0
chocolate #D2691E 210,105,30
coral #FF7F50 255,127,80
cornflowerblue #6495ED 100,149,237
cornsilk #FFF8DC 255,248,220
crimson #DC143C 220,20,60
cyan #00FFFF 0,255,255
darkblue #00008B 0,0,139
darkcyan #008B8B 0,139,139
darkgoldenrod #B8860B 184,134,11
darkgray #A9A9A9 169,169,169
darkgreen #006400 0,100,0
darkgrey #A9A9A9 169,169,169
darkkhaki #BDB76B 189,183,107
darkmagenta #8B008B 139,0,139
darkolivegreen #556B2F 85,107,47
darkorange #FF8C00 255,140,0
311
AP PEN D IX ES
B: CS S VA LUE S
Color continued
Keyword Hex RGB Numeric
darkorchid #9932CC 153,50,204
darkred #8B0000 139,0,0
darksalmon #E9967A 233,150,122
darkseagreen #8FBC8F 143,188,143
darkslateblue #483D8B 72,61,139
darkslategray #2F4F4F 47,79,79
darkturquoise #00CED1 0,206,209
darkviolet #9400D3 148,0,211
deeppink #FF1493 255,20,147
deepskyblue #00BFFF 0,191,255
dimgray #696969 105,105,105
dimgrey #696969 105,105,105
dodgerblue #1E90FF 30,144,255
firebrick #B22222 178,34,34
floralwhite #FFFAF0 255,250,240
forestgreen #228B22 34,139,34
fuchsia #FF00FF 255,0,255
gainsboro #DCDCDC 220,220,220
ghostwhite #F8F8FF 248,248,255
gold #FFD700 255,215,0
goldenrod #DAA520 218,165,32
gray #808080 128,128,128
green #008000 0,128,0
greenyellow #ADFF2F 173,255,47
grey #808080 128,128,128
honeydew #F0FFF0 240,255,240
hotpink #FF69B4 255,105,180
indianred #CD5C5C 205,92,92
indigo #4B0082 75,0,130
ivory #FFFFF0 255,255,240
khaki #F0E68C 240,230,140
312
Keyword Hex RGB Numeric
lavender #E6E6FA 230,230,250
lavenderblush #FFF0F5 255,240,245
lawngreen #7CFC00 124,252,0
lemonchiffon #FFFACD 255,250,205
lightblue #ADD8E6 173,216,230
lightcoral #F08080 240,128,128
lightcyan #E0FFFF 224,255,255
lightgoldenrodyellow #FAFAD2 250,250,210
lightgray #D3D3D3 211,211,211
lightgreen #90EE90 144,238,144
lightgrey #D3D3D3 211,211,211
lightpink #FFB6C1 255,182,193
lightsalmon #FFA07A 255,160,122
lightseagreen #20B2AA 32,178,170
lightskyblue #87CEFA 135,206,250
lightslategray #778899 119,136,153
lightslategrey #778899 119,136,153
lightsteelblue #B0C4DE 176,196,222
lightyellow #FFFFE0 255,255,224
lime #00FF00 0,255,0
limegreen #32CD32 50,205,50
linen #FAF0E6 250,240,230
magenta #FF00FF 255,0,255
maroon #800000 128,0,0
mediumaquamarine #66CDAA 102,205,170
mediumblue #0000CD 0,0,205
mediumorchid #BA55D3 186,85,211
mediumpurple #9370DB 147,112,219
mediumseagreen #3CB371 60,179,113
mediumslateblue #7B68EE 123,104,238
mediumspringgreen #00FA9A 0,250,154
313
AP PEN D IX ES
B: CS S VA LUE S
Color continued
Keyword Hex RGB Numeric
mediumturquoise #48D1CC 72,209,204
mediumvioletred #C71585 199,21,133
midnightblue #191970 25,25,112
mintcream #F5FFFA 245,255,250
mistyrose #FFE4E1 255,228,225
moccasin #FFE4B5 255,228,181
navajowhite #FFDEAD 255,222,173
navy #000080 0,0,128
oldlace #FDF5E6 253,245,230
olive #808000 128,128,0
olivedrab #6B8E23 107,142,35
orange #FFA500 255,165,0
orangered #FF4500 255,69,0
orchid #DA70D6 218,112,214
palegoldenrod #EEE8AA 238,232,170
palegreen #98FB98 152,251,152
paleturquoise #AFEEEE 175,238,238
palevioletred #DB7093 219,112,147
papayawhip #FFEFD5 255,239,213
peachpuff #FFDAB9 255,218,185
peru #CD853F 205,133,63
pink #FFC0CB 255,192,203
plum #DDA0DD 221,160,221
powderblue #B0E0E6 176,224,230
purple #800080 128,0,128
red #FF0000 255,0,0
rosybrown #BC8F8F 188,143,143
royalblue #4169E1 65,105,225
saddlebrown #8B4513 139,69,19
salmon #FA8072 250,128,114
sandybrown #F4A460 244,164,96
314
Keyword Hex RGB Numeric
seagreen #2E8B57 46,139,87
seashell #FFF5EE 255,245,238
sienna #A0522D 160,82,45
silver #C0C0C0 192,192,192
skyblue #87CEEB 135,206,235
slateblue #6A5ACD 106,90,205
slategray #708090 112,128,144
slategrey #708090 112,128,144
snow #FFFAFA 255,250,250
springgreen #00FF7F 0,255,127
steelblue #4682B4 70,130,180
tan #D2B48C 210,180,140
teal #008080 0,128,128
thistle #D8BFD8 216,191,216
tomato #FF6347 255,99,71
turquoise #40E0D0 64,224,208
violet #EE82EE 238,130,238
wheat #F5DEB3 245,222,179
white #FFFFFF 255,255,255
whitesmoke #F5F5F5 245,245,245
yellow #FFFF00 255,255,0
yellowgreen #9ACD32 154,205,50
315
In Chapter 3, Myth 3 mentions that, although there are still some
compatibility issues between the different browsers, the main
culprit is Internet Explorer with version 6 being the most trouble-
some. Although newer versions (7 and 8) have improved on their
predecessor, they have their issues as well.
APPENDIX C
Fixing Internet
Explorer
AP PEN D IX ES
C: F I XI NG I NT E RN ET E XPLO R ER
Understanding Quirks
As I have mentioned throughout this book, CSS is an inter-
preted language. The browser manufacturers take the standard
and implement it to the best of their abilities. However, older
browsers were often created before the standards had been fully
defined. When the browser maker implemented a standard dif-
ferently from the way it was later specified by the W3C, it’s called
a quirk.
Quirks Mode
quirksmode.com
solutions.
318
Fix 1: Doctype Switching
The simplest solution to IE quirks is to declare a Doctype at the
top of your HTML, defining the version of HTML or XHTML
you are using. This is generally set by the developer when they
create the HTML, but if you are doing your own development, I
recommend sticking with XHTML transitional:
319
AP PEN D IX ES
C: F I XI NG I NT E RN ET E XPLO R ER
<!--[if IE 6]>
<link src="css/ie6.css" type="text/css" media="all" />
<![endif ]-->
This will load the style sheet ie6.css only if the browser being used
is IE6. You can replace the “6” in if IE6 with another version
number or leave it out entirely and the style sheet will affect all
versions of IE.
You can now place any styles you want in the external file to “fix”
any problems you see in the Web page. For example, you might
include different padding to fix the box model problem described
in Chapter 6.
320
Fix 3: Underscore Hack
Although possibly the least elegant solution, the underscore hack
is the simplest and most direct IE fix. Place an underscore charac-
ter immediately before a line of CSS code that you want only IE6
to see, and it is hidden from all other browsers. For example:
width: 250px;
padding: 25px;
_width: 300px;
If the browser is in quirks mode, this will reset the width of the
box from 250px to 300px so it will appear to be the same width
in IE6 as in other browsers.
321
AP PEN D IX ES
C: F I XI NG I NT E RN ET E XPLO R ER
See “Box” in Chapter The Box Model: The width or height of an element appears
6, “Vocabulary,” for longer than in other browsers.
more details on the
Fix: If Doctype switching does not work, use conditional
box model, margins,
and floating. styles or the underscore hack to set a separate length.
322
No Min/Max Width or Min/Max Height: Before version 7, See “Width and
Height” in Chapter 6,
IE did not support the min-width, max-width, min-height, or
“Vocabulary,” for more
max-height properties. details on widths and
Fix: Set conditional styles with the underscore hack to set heights.
absolute width or height. The good news is that IE6 treats
height the way modern browsers treat min-height.
No Alpha Support for PNG: Although it will display PNG See “Using
Transparent Images”
images, IE6 fills any alpha channel with a muddy gray.
in Chapter 11,
Fix: Use conditional styles or the underscore hack to set a “Chrome,” for more
non-transparent PNG source image, or, if the image is in the details on transparent
background, load the image using the IE alpha filter. PNGs.
323
Index
!important, 116, 120, 283 and shadows, 172
@fontface rule, 230–231 and Web standards, 44
@import rule, 90, 96, 102, 203, 282, 295 applications, Web, 30–33
2-D positioning, 162–163 Arial Black font, 226, 227
3-D positioning, 164–165 Arial font, 226, 227
Asynchronous JavaScript and XML, 12
auto keyword, 124
B
<a> tag, 243, 244. See also anchor tags
a:active pseudo-class, 244
absolute position type, 160, 161
absolute URLs, 309 background, 134–139
ActionScript, 14 images. See background images
active state, 80, 81, 82, 170, 244, 298 patterns, 190
ad modules, 268 positioning, 138–139
addons.mozilla.org, 26–27 tiling methods, 136–137, 190
adjacent selectors, 78 background-attachment property, 134, 135
Adobe background-color property, 134, 135
Dreamweaver, 29 background-image property, 134, 135
Fireworks, 32 background images
Flash. See Flash for buttons, 252
Illustrator, 32 defining columns as, 262
Kuler, 30, 31 defining rows as, 264
Photoshop. See Photoshop and design best practices, 284
a:hover pseudo-class, 244 and mobile devices, 280
Ajax, 12 and printed Web pages, 281
alignclear class, 220, 292 using logo as, 260
alignment, text, 130, 132, 133 using logo text in, 266
a:link pseudo-class, 244 background-position value, 138, 139
AllofUs, 9 background property, 134, 135
alpha channels, 258 background-repeat property, 136, 137
alpha Web sites, 204 Berners-Lee, Tim, 8
AlphaImageLoader, 260 best practices, CSS, 282–286
anchor tags, 243, 244, 248, 252 beta launches, 204
Andale Mono font, 226, 227 bitmap images, 32
AOL Explorer, 23 block boxes, 140
Apple iLife, 228 block display type, 142
Apple Safari block elements, 6
and CSS, 21 block quotes, 240
and design enhancements, 254 Blueprint, 278
as development tool, 21 body copy, 234, 238
and downloadable fonts, 230 <body> tag, 210, 292
layout engine, 23 bold font, 128
and rounded corners, 174 bold tags, 8
BooksShouldBeFree.com, 292 browser-default styles, 106, 110, 120, 216–
border-bottom property, 152, 246 217, 296
border-collapse property, 166, 167 browser-inherent styles, 6
border-color-bottom property, 152 browser-synthesized fonts, 126
border-color-left property, 152 browsers, 18–23. See also specific browsers
border-color property, 152 alternatives to leading, 22, 23
border-color-right property, 152 and CSS, 18, 20–21, 44
border-color-top property, 152 and design enhancements, 172, 254
border-left property, 152 and downloadable fonts, 230
border property, 152, 153 and font sizes, 236
border-radius property, 174, 175, 252 graphics-based, 8
border-right property, 152 layout engines for, 23
border-spacing property, 166, 167 legacy, 18
border-style-bottom property, 152 Macintosh, 18, 20–21
border-style-left property, 152 most commonly used, 18
border-style property, 152 and outlines, 174
border-style-right property, 152 and rounded corners, 174
border-style-top property, 152 and shadows, 172
border-top property, 152 viewing Web page on different, 19
border-width-bottom property, 152 Windows, 20–21
border-width-left property, 152 Buivenga, Jos, 237
border-width property, 152 bulleted lists, 168, 240
border-width-right property, 152 buttons, 252–254
border-width-top property, 152
borders, 152–153, 284
Bos, Bert, 8
bottom position property, 138, 162, 163, 220
box model, CSS, 158, 222, 318, 322
C
Camino, 23
box-shadow property, 172, 173, 252, 254 capitalizing text, 130
boxes, 140–165 caption-side property, 166, 167
allowing scrolling in, 148 cascade, 120–121, 198
automatic positioning of, 140 Cascading Style Sheets, 35. See also CSS
components of, 140, 141 case sensitivity, of class/ID names, 66
display types for, 142–143 Causecast, 14–15
floating, 146–147, 322 center position property, 138
handling overflow in, 148, 149 centering elements, 138, 218
hiding, 144, 145 child selectors, 76, 86
inline vs. block, 140 Chiucini, Michela, 39
setting borders for, 152–153 chrome, 257–271
setting margins for, 156–157 as component of style guide, 194
setting opacity for, 144, 145 cutting, 192–193
setting padding for, 154–155 defined, 192, 257
setting position for, 160–165 defining sections, 268–271
setting width/height for, 148–151 defining the grid, 262–265
<br /> tag, 220 logos and forms, 266–267
325
using transparent images, 258–261 contextual rules, 286
Chrome, Google, 23 Courier New font, 226, 227
chrome.css, 214, 300–301 Crossover, 22–23
citations, 74–75 CSS
class names, 66, 270, 279, 283, 286 adding notes to, 104–105
class selector, 62–67, 114 analyzing, 29
clear property, 146, 147 best practices, 282–286
CMYK, 36 box model, 158, 222, 318, 322
Coda, 28 combining code into single file, 202
code, voxLibris, 291–301 as core Web technology, 1, 2
chrome.css, 300–301 design enhancements, 172–175, 254
default.css, 296 as design vs. development tool, 36
index.html, 292–294 and DOM, 4
layout.css, 297 editing, 198
main.css, 295 file-size considerations, 198
navigation.css, 298–299 and Flash, 14
code comments, 104–105, 285 and fonts, 232
code editors, 28–29 frameworks, 212–213, 278–279
CodeWeavers, 22 genesis of, 8
coding best practices, 285 and HTML, 6–9
colazionedamichy.it, 39 vs. HTML tables, 40
colon, in style rules, 52 and JavaScript, 10–13
color codes, 24, 310–315 learning about latest advances in, 255
color gradients, 136, 260, 264, 266 learning to use, 36
color keywords, 310–315 meaning of acronym, 35
color opacity, 310 myths about, 35–45
color property, 130, 131 optimizing, 286
color trends, 258 organizing, 200–201
<color> variable, 125 purpose of, 2
ColorJack, 30, 31 selectors. See selectors
colors semantics. See CSS semantics
defining, 285, 310–315 sizing text in, 236
differentiating link states with, 82–83, 246 specifying colors in, 310
including in style guide, 194 sprites, 168, 192, 244–245, 284
in printed Web pages, 281 stripping out comments from, 198
in wire frames, 186 style guides, 194–195
Colorzilla, 24 style rules. See rules of style
ColourLovers, 256, 258 as style sheet language, 36
columns, 212, 220–221, 262–263, 281, 297 syntax. See CSS syntax
Comic Sans MS font, 226, 227 validating, 274–277, 321
comments, 104–105, 285 versatility of, 40
company logos, 214, 260, 266–267, 270, 284 vocabulary. See CSS vocabulary
compositions, 190. See also visual comps for voxLibris, 291–301
conditional styles, 320, 323 and Web browsers, 18, 20–21, 44, 317
context, styling elements based on, 70–79 and Web design process, 179
326
and Web standards, 44 outlines, 174, 175
and WordPress, 39 padding, 154–155
writing, 198–199 position type, 160–161
.css extension, 98 rounded corners, 174, 175
CSS Gallery, 38 shadows, 172–173
CSS Import, 277 tables, 166–167
CSS semantics, 89–121. See also CSS text styles, 130–133
vocabulary values, 124–125
adding notes to CSS, 104–105 variables, 125
cascade, 120–121 visibility, 144–145
determining CSS rule’s weight, 114–115 width/height properties, 149–151
embedding styles in Web page, 94–95 CSS Work Group, W3C, 158
external styles in Web site, 96–103 CSS Zen Garden, 40, 42–43
importance, 116–117 CSS3.info, 255
inheritance, 106–109 csscompressor.com, 198
inline styles for HTML tag, 92–93 CSSEdit, 29
media types, 118–119 cursor, 170–171
order of style rules, 110–111
specificity in style rules, 112–113
where to put style rules, 90–103
CSS syntax, 49–87
rules of style, 50–59
D
data tables, 166–167
styles for special cases, 80–87 declaration, selector, 54
styles in context, 70–79 default styles, 194, 216–217
types of selectors, 60–69 default.css, 214, 217, 296
unforgiving nature of, 49 dependent class, 64–65
CSS validation, 274–277, 321 deployment, site, 204
CSS vocabulary, 123–175. See also CSS descendent selectors, 72–75
semantics design challenge, CSS Zen Garden, 40
2-D position, 162–163 design enhancements, 172–175, 254, 276
3-D position, 164–165 design iteration, 206–207
background, 134–139 design process, 180–181. See also Web design
borders, 152–153 Design Shack, 38
boxes, 140–159 DHTML, 12
cursor, 170–171 Dictionary, Urban, 122, 124
display type, 142–143 display properties, 142–143
float property, 146–147 <div> tag, 218
font properties, 126–129 Doctype switching, 319, 322
image position, 138–139 Document Object Model, 4. See also DOM
image repeat, 136–137 Dojo Toolkit, 12
keywords, 124 DOM, 4, 10
lists, 168–169 doubling-margins problem, 322
margins, 156–157 downloadable books, 292
maximum width/height properties, 150–151 downloadable fonts, 230–231, 237
minimum width/height properties, 150–151 Dreamweaver, 29
327
drop shadows, 172, 190 market share, 20
Dynamic HTML, 12 and rounded corners, 174
dynamic pseudo-classes, 80, 84, 170, 323 and shadows, 172
dynamic styles, 80 Fireworks, 32, 258
fixed position type, 160, 161
fixed vs. fluid layouts, 184–185, 186, 218
E
element boxes, 140, 141. See also boxes
.fla files, 4
Flash
as core Web technology, 4
Em Calculator, 285 and CSS, 14
Emastic, 278 delivering video with, 14
embedded styles, 90–91, 94–95, 283 and embedded fonts, 230
emphasis tag, 76, 78 float property, 146, 147
ems, 236, 285 floating elements, 146–147, 322
European mobile devices, 21 Flock, 23
Exljbris Font Foundry, 237 flourishes, 270
external style sheets, 96–103 fluid typography, 232–237
creating, 98–99 fluid vs. fixed layouts, 184–185, 186, 218
and CSS best practices, 282 focus, 84, 170
importing, 102–103 fold line, 186
linking to, 100–101 font families, 32, 126, 128. See also fonts
modular approach to adding, 214 font-family property, 128, 129, 198, 226
purpose of, 96 <font-name> variable, 125
strategies for combining, 202 font properties, 126–129
external styles, 90–91, 96 font property, 126–127
font-size property, 128, 129
font-style property, 128, 129
F
feedback
font-variant property, 128, 129
font-weight property, 128, 129
fonts. See also font families; typography
browser-synthesized, 126
and beta launches, 204 choosing, 234–235
and dynamic pseudo-classes, 84, 170 core Web, 226–227
and link pseudo-classes, 80 creating faux versions of, 126
making changes based on, 180 downloadable, 230–231, 237
and mood boards, 188 vs. font family or typeface, 228
filter:alpha property, 144, 145 iLife, 228
Firebug, 24, 25 importance of, 225
Firefox Microsoft Office, 228
add-ons, 24–27 operating system, 228
and border-radius property, 254 setting sizes for, 236, 281, 285
and CSS, 20 testing, 234
as development browser, 24 Web-safe, 32, 228–229, 234, 306–308
and downloadable fonts, 230 footers, 160, 268, 281
layout engine, 23 forms, 266
frameworks, 212–213, 278–279
FTP, 28
328
hover state, 80, 81, 82, 170, 244, 298
G
Gecko, 23
HTML
code, for voxLibris, 291–301
as core Web technology, 1, 2
gel effect, 252 and CSS, 6–9
Georgia font, 226, 227 developer of, 8
GIF image format, 168, 258 and DOM, 4
global navigation menus, 248, 252 dynamic, 12
Good magazine, 272, 274 meaning of acronym, 6
Google Chrome, 23 purpose of, 2, 6
gradients, 136, 260, 264, 266 tags. See HTML tags
graph paper, 182 validating, 275
greek text, 196 HTML framework, 212–213
grid-based layouts, 40, 209, 218–223. See HTML selector, 60–61
also grids HTML tables, 40
Grid System, The, 208, 210 HTML tags
grid.css, 219, 221, 223 adding multiple classes to, 66–67
grids, 190, 209, 210, 218–223, 262–265 binding styles to, 50
guides, 190 creating basic style for, 50
how CSS acts on, 50
inline styles for, 92–93
H
handheld devices, 118, 282
purpose of, 6, 50
styling, 60–61
weight of, 114
hypertext links
hard launch, 204
creating, 243
hash mark, 68
purpose of, 243
<head> tag, 210, 283, 292
styling, 80, 243, 246
header cap image, 268
underlining, 246
header tags, 6
Hypertext Markup Language, 6. See also HTML
headers
basic style rule for, 54–55
combining style rules for, 58–59
creating with fixed elements, 160
declaring multiple styles for, 56–57
I
i love typography, 224, 226
for sidebars vs. main body, 70
tips for styling, 238–239 iCab, 23
headlines, 234 ID names, 4, 66, 270, 283, 286
height, fluid vs. fixed, 184–185, 186 ID selector, 68–69, 114
height property, 148–151 IE. See Internet Explorer
Helvetica font, 226 ie6.css, 320
hex color values, 24, 54, 194, 310–315 iLife fonts, 228
hiding elements, 144–145 Illustrator, 32
hip hop magazine, 50 ilovetypography.com, 224, 226
horizontal menus, 248, 250 image editors, 32, 258
image flashing, 244, 284
329
image position, 138–139 and CSS box model, 158–159, 222, 318,
image swapping, 244 322
image tiling, 136–137, 190 and Doctype switching, 319, 322
ImageReady, 192 and dynamic pseudo-classes, 84, 323
images and fixed elements, 160
background. See background images flaws, 20
embedding directly in page, 257 and inline-block display type, 142
floating, 146–147 and max/min-height properties, 150, 323
transparent, 192, 258–261 and max/min-width properties, 150, 323
<img> tag, 257, 284 and padding/borders, 158
Impact font, 226, 227 and PNG image format, 260, 323
import rule. See @import rule and pseudo-elements, 86
importance, 120 and quirks mode, 318, 319, 321
indents, 130, 132, 200 and stair-stepped elements, 322
index.html, 213, 292–294 testing on Macintosh, 22–23
inherit display type, 142 and underscore hack, 158, 260, 321, 323
inherit keyword, 124 and Web standards, 44, 317
inherit position type, 160 Internet Explorer 7 (IE7), 20, 44, 76, 84, 166,
inheritance, 106–109 317
how it works, 106–107 Internet Explorer 8 (IE8), 20, 44, 166, 254, 317
overriding, 108–109 invisible elements, 144
inline-block display type, 142 italic font, 128
inline boxes, 140 italics tags, 8
inline display type, 142 iteration, 206–207
inline elements, 6
inline styles, 90, 91, 92–93, 120, 283
Internet Channel, 23
Internet Explorer (IE). See also specific IE
versions
J
Java, 23
and CSS, 20 JavaScript
and downloadable fonts, 230 as core Web technology, 1, 2
and font sizes, 236 and CSS, 10–13
and @import rule, 203, 295 and DOM, 4, 10
layout engine, 23 libraries, 12
market share, 18, 20 purpose of, 2
and opacity, 144 JavaScript Object Notation, 12
quirks/fixes, 317–323 jigsaw.w3.org/css-validator, 274, 276
version considerations, 19 josbuivenga.demon.nl, 237
and Web standards, 44, 317 JPEGs, 168, 192
Internet Explorer 5 (IE5), 318 jQuery, 12
Internet Explorer 6 (IE6) JSON, 12
and caption-side property, 166
and child/sibling selectors, 76, 86
and conditional styles, 320, 323
and CSS, 20
330
lipsum.com, 196
K
keywords, 124, 310
list element tags, 6
list-item display type, 142
list-style-image property, 168, 169
KHTML, 23 list-style-position property, 168, 169
Koch, Peter-Paul, 318 list-style property, 168, 169
Konquerer, 23 list-style-type property, 168, 169
Krista’s Creations, 13 list tags, 248
Kuler, 30, 31 lists, 168–169, 240
Lobo, 23
logos, 214, 260, 266–267, 270, 284
331
mobile devices, 21, 280 Open Type fonts, 230
modules, 222, 268 Opera
mood boards, 188–189 and CSS, 21
MooTools, 12 and downloadable fonts, 230
Mosaic, 8 layout engine, 23
mouse pointer, 170 popularity of, 21
-moz-border-radius property, 174, 175 and Web standards, 44
-moz-box-shadow property, 172, 173 Opera Mini, 23
Mozilla operating system fonts, 228
and CSS standards, 44 optimizing, 286
Firefox add-ons, 24–27 order, style, 110, 120
MSN Explorer, 23 ordered lists, 168
myths, CSS, 35–45 outline-color property, 174
outline property, 174, 175
outline-style property, 174
N
navigation, 243–255
outline-width property, 174
outlines, 174, 175, 223
overflow property, 148, 149
and anchor tags, 244
P
buttons, 252–254
and CSS sprites, 244, 284
hiding in printed Web page, 281
links, 246–247 padding, 154–155, 186, 218, 284
menus, 248–251 padding-bottom property, 154
navigation.css, 214, 298–299 padding-left property, 154
Netscape, 23 padding property, 154, 155
NewsGator, 28 padding-right property, 154
Nintendo DS Browser, 23 padding-top property, 154
no-repeat property, 136, 137 page flow, 184–185
none display type, 142 page framework, 212
normal keyword, 124 page header tags, 6. See also headers
NotePad, 98 Palette Grabber, 26
notes, 104–105 Panic Software, 16, 18, 28
<number> variable, 125 paragraph tags, 6
numbered lists, 168 paragraphs, styling, 86–87, 240
parent-inherited styles, 106, 120
<percentage-box-width+padding> value, 138
O
object IDs, 4
<percentage> variable, 125
Photoshop
and chrome, 192
OmniGraffle, 182 color considerations, 190
OmniWeb, 23 creating color palette for, 26
opacity, color, 310 low-cost alternative to, 32
opacity value, 144, 145 Proof Setup options, 190
and transparent PNGs, 192, 258
332
and Web design process, 180 repeat-x property, 136, 137, 264
pixels, 285 repeat-y property, 136, 137
placeholder content, 196 RGB Alpha color format, 310
planning process, 182–191 RGB proof setup, 190
mood boards, 188–189 RGB values, 24, 54, 194, 285, 310–315
page flow, 184–185 right position property, 138, 220
sketches, 182–183 right property, 162, 163
visual comps, 190–191 Rijksmuseum Web site, 242, 244
wire frames, 186–187 rounded corners, 174, 175, 190, 254, 258
PlayStation, 21 rows, 212, 218–219, 264–265, 297
PNG image format, 168, 192, 258–261, 323 rules of style, 50–59
point sizes, 281 basic style rules, 54–55
Portfolio CSS Gallery, 38 combining rules, 58–59
position properties, 138, 220 declaring styles, 56–57
position type, 160–161 how they work, 50
Presto, 23 limiting scope of, 285
print, adapting designs for, 118, 281, 282 parts of style rules, 52–53
print process, 36
printer-friendly Web pages, 118
programming languages, 36
properties, style rule, 52
property shortcuts, 200, 286
S
Safari
prototypes, 180, 196–203 and CSS, 21
pseudo-classes, 80, 82, 170, 323 and design enhancements, 254
pseudo-elements, 80, 86 as development tool, 21
public domain books, 292 and downloadable fonts, 230
pull quotes, 146 layout engine, 23
and rounded corners, 174
Q
and shadows, 172
and Web standards, 44
screen media type, 118
quirks mode, 318, 319, 321 scroll lines, 186
Quirks Mode site, 318 search engine optimization, 283. See also SEO
quotes, 78–79, 146, 240 sections, 212, 222–223, 268–271, 297
selector declarations, 54
selectors, 60–75
R
readmore class, 246
adjacent, 78
child, 76
class, 62–67
RealPlayer, 23 defined, 52
relative position type, 160, 161 descendent, 72–75
relative URLs, 309 HTML, 60–61
rendering engines, 23 sibling, 76, 78
repeat property, 136, 137 semantics, 89–121. See also CSS vocabulary
adding notes to CSS, 104–105
333
cascade, 120–121 style attribute, 90
determining CSS rule’s weight, 114–115 style guides, 194–195
embedding styles in Web page, 94–95 style rules, 50–59
external styles in Web site, 96–103 basic, 54–55
importance, 116–117 combining, 58–59
inheritance, 106–109 determining weight of, 114–115
inline styles for HTML tag, 92–93 how they work, 50
media types, 118–119 parts of, 52–53
order of style rules, 110–111 specificity in, 112–113
specificity in style rules, 112–113 where to put, 90–103
where to put style rules, 90–103 style sheet languages, 36
semicolon, in selector declarations, 56, 92, style sheets. See also CSS
285 combining, 202–203
SEO, 283, 284 creating, 98–99
server-side technologies, 2 external. See external style sheets
shadows, 172–173, 190 genesis of, 8
Shiira, 23 importing, 102–103
shorthand properties, 200, 286 linking to, 100–101
sibling selectors, 76, 78 for mobile devices, 280
sidebars, 70, 146 tailoring for specific media types, 118–119
site navigation, 243–255 <style> tag, 90, 94
and anchor tags, 244 styles
buttons, 252–254 applying to entire Web site, 96
and CSS sprites, 244, 284 based on where something is, 72–73
hiding in printed Web page, 281 browser-default, 106, 110, 120, 216–217,
links, 246–247 296
menus, 248–251 browser-inherent, 6
site-planning process, 182–191 for children, 76–77
mood boards, 188–189 conditional, 320, 323
page flow, 184–185 in context, 70–79
sketches, 182–183 declaring, 56–57
visual comps, 190–191 default, 106, 110, 120, 194, 216–217
wire frames, 186–187 dynamic, 80, 84–85
site plans, 180. See also site-planning process embedded, 90–91, 94–95, 283
sketches, 182–183 external, 90–91, 96–103
soft launches, 204 forcing application of, 116
Sony PlayStation, 21 framework, 279
Speaking In Styles Web site, 2, 172, 228, 291 inherited, 106
specificity, 112–113, 120 inline, 90, 91, 92–93, 120, 283
sprites, CSS, 168, 192, 244–245, 284 for link actions, 82–83
stacking order, 164 order of priority for, 120–121
stair-stepped elements, 322 organizing, 200–201
states, link, 80–83, 244–245, 246 overriding, 108, 110, 116
static position type, 160, 161 parent-inherited, 106, 120
strike-through effect, 130 for parts of paragraph, 86–87
334
reusing, 270 Times font, 226
for siblings, 78–79 Times New Roman font, 226, 227
for special cases, 80–87 top-level navigation menus, 248, 280
text, 130–133 top position property, 138, 162, 163, 220
SUMO Paint, 32 TopStyle, 28
syntax, 49. See also CSS syntax transparent images, 192, 258–261
transparent keyword, 124
Trebuchet MS font, 226, 227
T
T-shirt company, 88, 90
Trident, 23
True Type fonts, 230
tutorials, Web design, 34
table-based layouts, 40 Twistori, 251
table tags, 6 typefaces, 228, 234–235. See also fonts;
tables, 166–167 typography
tags TypeTester, 32, 33
adding multiple classes to, 66–67 Typographic Desk Reference, The, 224
binding styles to, 50 typography, 225–241
creating basic style for, 50 as component of style guide, 194
how CSS acts on, 50 core Web fonts, 226–227
inline styles for, 92–93 downloadable fonts, 230–231
purpose of, 6, 50 fluid, 232–237
styling, 60–61 improvements in Web, 32
weight of, 114 previewing, 32
text styling text, 238–241
aligning, 130, 132, 133 Web-safe fonts, 32, 228–229, 234, 306–
capitalizing, 130 308
editing, 98 Typogridphy, 278
replacement, 266
U
sizing, 236
styling, 130–133, 238–241
underlining, 8, 130, 133, 216, 246
using placeholder, 196 UGSMAG, 50, 71
text-align property, 132, 133 underlining, 8, 130, 133, 216, 246
text-decoration property, 132, 133 underscore hack, 158, 260, 276, 321, 323
text editors, 98 Uniform Resource Locators, 309. See also
text-indent property, 132, 133 URLs
text replacement, 266 Unix, 20, 21
text-shadow property, 172, 173 unordered lists, 168
text-spacing properties, 130 Urban Dictionary, 122, 124
text styles, 130–133, 238–241 <url> variable, 125
text-transform property, 132, 133 URLs, 125, 281, 309. See also links
TextEdit, 98 usability reviews, 250
thegridsystem.org, 210 user feedback
Threadless, 88, 90 and beta launches, 204
tiling, image, 136–137, 190 and dynamic pseudo-classes, 84, 170
335
and link pseudo-classes, 80 jargon, 255
making changes based on, 180 meaning of acronym, 44
and mood boards, 188 Web applications, 30–33
user interface, 192 Web browsers, 18–23. See also specific
UXBooth, 250 browsers
alternatives to leading, 22, 23
and CSS, 18, 20–21, 44, 317
V
Validation Service, W3C CSS, 274, 276, 277,
and design enhancements, 172, 254
and downloadable fonts, 230
and font sizes, 236
321 graphics-based, 8
validator.w3.org, 275 layout engines for, 23
values legacy, 18
as component of style rules, 52 Macintosh, 18, 20–21
types of, 124–125 most commonly used, 18
variables, 125 and outlines, 174
Verdana font, 226, 227 and rounded corners, 174
vertical-align property, 132, 133 and shadows, 172
vertical menus, 248, 251 viewing Web page on different, 19
video, 14 Windows, 20–21
visibility, 144–145 Web design, 179–207
visibility value, 144, 145 adapting for print, 281
visited state, 80, 81, 82, 244, 298 best practices, 284
visual comps and browser viewport, 150
adjusting margins/padding in, 186 building site, 192–203
comparing with actual Web site, 26 choosing tools for, 17
cutting chrome from, 192 deploying site, 204–205
and fluid typography, 232 vs. designing for other media, 150, 180
purpose of, 190 dynamic nature of, 180
and site-planning process, 180 as iterative process, 180, 206–207
static vs. dynamic, 82 making CSS central part of, 179
tips for creating, 190 overview of process, 180–181
voxLibris page-flow considerations, 184–185
code for, 291–301 planning phase, 182–191
inspiration for, 292 source of news and updates on, 2
as model for design process, 180 standards, 275
testing, 196
tools. See Web designer’s toolbox
W
W3C
Web Designer Wall, 34, 36
Web designer’s toolbox, 17–34
code editors, 28–29
design ideas, 34
and CSS, 44 Firefox add-ons, 24–27
CSS Validation Service, 274, 276, 277, 321 online tools, 30–33
CSS Work Group, 158 tutorials, 34
336
Web browsers, 18–23 -webkit-box-shadow property, 172, 173
Web pages. See also Web sites weight, rule, 112, 114–115
adding structure to, 50 white-space property, 130, 131
core components of, 1–3 width, fluid vs. fixed, 184–185, 186, 218
creating printer-friendly version of, 118 width property, 148–151
embedding styles in, 94–95 Wii, 23
fluid vs. fixed, 184–185, 218 Windows
meta information for, 210 code editors, 28, 29
planning structure of, 186 core Web fonts, 226
setting default styles for, 210, 216–217 operating system fonts, 228
“skin” of, 257. See also chrome text editor, 98
structural elements, 210 Web browsers, 20–21
tailoring for specific media, 118–119 Web-safe fonts, 306
viewing on different browsers, 19 wire frames, 182, 186–187
viewing on mobile devices, 280 Word, Microsoft, 98
viewing printed, 281 word processors, 98
Web-safe fonts, 32, 228–229, 234, 306–308 word-spacing property, 130, 131
Web sites. See also Web pages WordPress, 39
analyzing CSS for, 29 World Wide Web Consortium, 44. See also W3C
applying styles to entire, 96
choosing color palette for, 30
choosing fonts for, 225, 234–235. See also
fonts
deploying, 180
X
XML, 12, 14
designing. See Web design
getting user feedback on. See feedback
navigation for. See navigation
planning, 180, 182–191
testing, 180, 196
Y
YAML, 278
vs. Web applications, 30
Web standards, 275 YUI Grids, 278
Web technologies, 2, 4
Web typography, 225–241
as component of style guide, 194
core Web fonts, 226–227
Z
z-index property, 164–165
downloadable fonts, 230–231
fluid, 232–237 Zen Garden, CSS, 40, 42–43
improvements in, 32
previewing, 32
styling text, 238–241
Web-safe fonts, 32, 228–229, 234, 306–
308
Webdings font, 226, 227
WebKit, 23
-webkit-border-radius property, 174, 175
337
Get free online access
to this book for 45 days!
And get access to thousands more by signing
up for a free trial to Safari Books Online!
With the purchase of this book you have instant online,
searchable access to it for 45 days on Safari Books Online!
And while you’re there, be sure to check out Safari Books
Online’s on-demand digital library and their free trial offer
(a separate sign-up process). Safari Books Online subscribers
have access to thousands of technical, creative and business
books, instructional videos, and articles from the world’s
leading publishers.