Cover | Table of Contents | Colophon
font tags to set the color, size, and style of
text on different parts of a web page:<font face="Verdana, Arial" size="+1" color="blue">Hello, World!</font>
font tags results in time-consuming updates, adds
to the overall file size of the web document, and increases the
likelihood that errors will occur in the markup.p element:<p>Hello, World!</p>
<style type="text/css" media="all">
p {
color: blue;
font-size: small;
font-family: Verdana, Arial, sans-serif;
}
</style>
font-family
property:p {
font-family: Georgia, Times, "Times New Roman", serif;
}
font tags to set the color, size, and style of
text on different parts of a web page:<font face="Verdana, Arial" size="+1" color="blue">Hello, World!</font>
font tags results in time-consuming updates, adds
to the overall file size of the web document, and increases the
likelihood that errors will occur in the markup.p element:<p>Hello, World!</p>
<style type="text/css" media="all">
p {
color: blue;
font-size: small;
font-family: Verdana, Arial, sans-serif;
}
</style>
font-family
property:p {
font-family: Georgia, Times, "Times New Roman", serif;
}
font-family property. If the browser
can't find the first font on the list, it tries to
find the next font, and so on, until it finds a font.|
Generic font family values
|
Font examples
|
|---|---|
serif |
Georgia, Times, Times New Roman, Garamond, and Century Schoolbook
|
sans-serif |
Verdana, Arial, Helvetica, Trebuchet, and Tahoma
|
monospace |
Courier, MS Courier New, and Prestige
|
font-size property:P {
font-size: 0.9em;
}
font-size
property is set to a value of zero. Therefore different browsers
interpret the value unpredictably. For example, such text
isn't visible in the Mozilla browser. In Internet
Explorer for Macintosh and Safari, the text isn't
hidden, but, rather, is displayed at the default value of the font
size. The Opera browser displays the text at a smaller, but still
legible, size. And Internet Explorer for Windows sets the type size
to a small, illegible, but still visible line of text that appears to
be equal to the size of 0.1em, as shown in Figure 1-4. If you want to make text invisible, use the
CSS properties !important rule to override a
user's style sheet rules:P {
font-size: 12px !important;
}
!important rule consists
of an exclamation mark (!) followed immediately by the word
important.!important rule gives you a little insurance that
your designs remain intact. (However, the nature of the medium means
that designs are never precise or
"pixel-perfect" from one display to
another.)!important
CSS rules, the user also can write these rules in his own style
sheet. And in the CSS 2 specification, !important
rules the user writes override any !important
rules the designer writes.!important rules at
http://www.w3.org/TR/CSS21/cascade.html#important-rules.p element:<p>Online, activity of exchanging ideas is sped up. The distribution of messages from the sellin of propaganda to the giving away of disinformation takes place at a blindingly fast pace thanks to the state of technology...</p>
:first-letter
to stylize the first letter of
the paragraph, as shown in Figure 1-7:p:first-letter {
font-size: 1.2em;
background-color: black;
color: white;
}
:first-letter pseudo-element
(:first-letter isn't supported in
most browsers, including Internet Explorer 4 and 5 for Windows,
Netscape Navigator 4, and Internet Explorer 4.5 for Macintosh).span element with a
class attribute around the first letter of the
first sentence of the first paragraph:<p><span class="initcap">O</span>nline, activity of exchanging ideas is sped up. The distribution of messages from the selling of propaganda to the giving away of disinformation takes place at a blindingly fast pace thanks to the state of technology...</p>
p .initcap {
font-size: 1.2em;
background-color: black;
color: white;
}
:first-letter
pseudo-element at http://www.w3.org/TR/CSS21/selector.html#x52;
for more information on initial caps in general, see span element with a
class attribute around the first letter of the
first sentence of the first paragraph:<p><span class="initcap">O</span>nline, activity of exchanging ideas is sped up. The distribution of messages from the selling of propaganda to the giving away of disinformation takes place at a blindingly fast pace thanks to the state of technology...</p>
span tag with a class selector, create the
decoration that sets the text indent for the paragraph (see Figure 1-8):p {
text-indent: 37%;
line-height: 1em;
}
p .initcap {
font-size: 6em;
line-height: 0.6em;
font-weight: bold;
}
text-indent property,
which moves the first line toward the middle of the paragraph. The
value is set to 37%, which is a little bit more than one-third the
distance from the left side of the paragraph, as shown in Figure 1-9, but not enough to
"center" the initial cap.
font-size property.
Setting the size to 6em makes the font six times (or 600%) larger
than the default size set for fonts in the browser, as shown in Figure 1-10.
span element around the first letter of the
first sentence of the first paragraph:<p><span class="initcap">O</span>nline, activity of exchanging ideas is sped up. The distribution of messages from the selling of propaganda to the giving away of disinformation takes place at a blindingly fast pace thanks to the state of technology...</p>
span to be hidden:p.initcap {
display: none;
}
p {
line-height: 1em;
background-image: url(initcap-o.gif);
background-repeat: no-repeat;
text-indent: 35px;
padding-top: 45px;
}
display property to
none. Then put the image in the background of the
paragraph, making sure that the image doesn't repeat
by setting the value of background-repeat to
no-repeat:background-image: url(initcap-o.gif); background-repeat: no-repeat;
text-indent and the height of the
image as the padding for the top of the paragraph (see Figure 1-13):
<h2>Designing Instant Gratification</h2> <p>Online, activity of exchanging ideas is sped up. The distribution of messages from the selling of propaganda to the giving away of disinformation takes place at a blindingly fast pace thanks to the state of technology...</p>
font
shorthand property to easily change
the style of the heading:h2 {
font: bold italic 2em Georgia, Times, "Times New Roman", serif;
margin: 0;
padding: 0;
}
p {
margin: 0;
padding: 0;
}
font property is just one of these
timesavers. One font property can represent the
following values:font-style
font-variant
font-weight
font-size/line-height
font-family
border-top and
border-bottom properties when setting the style
for the heading:h2 {
font: bold italic 2em Georgia, Times, "Times New Roman", serif;
border-bottom: 2px dashed black;
border-top: 10px solid black;
margin: 0;
padding: 0.5em 0 0.5em 0;
font-size: 1em;
}
p {
margin: 0;
padding: 10px 0 0 0;
}
border-left
and border-right
properties, respectively. The border-top,
border-bottom, border-left,
and
border-right properties are shorthand properties
that enable developers to set the width, style, and color of each
side of a border.h2 {
font: bold italic 2em Georgia, Times, "Times New Roman", serif;
border-bottom-width: 2px ;
border-bottom-style: dashed;
border-bottom-color: black;
border-top-width: 10px;
border-top-style: solid;
border-top-color: black;
margin: 0;
padding: 0.5em 0 0.5em 0;
font-size: 1em;
}
border. The
border property sets
the same style for the width, style, and color of the border on each
side of an element:h2 {
border: 3px dotted #33333;
}
background-image,
background-repeat, and
background-position properties:h2 {
font: bold italic 2em Georgia, Times, "Times New Roman", serif;
background-image: url(tall_grass.jpg);
background-repeat: repeat-x;
background-position: bottom;
border-bottom: 10px solid #666;
margin: 10px 0 0 0;
padding: 0.5em 0 60px 0;
}
background-repeat
property to a value of repeat-x, which will cause
the image to repeat horizontally:background-image: url(tall_grass.jpg); background-repeat: repeat-x;
background-position
property to bottom:background-position: bottom;
background-position can take up to two values
corresponding to the horizontal and vertical axes. Values for
background-position can be a length unit (such as
pixels), a percentage, or a keyword. To position an element on the x
axis, use the keyword values left,
center, or right. For the y
axis, use the keyword values top,
center, or bottom.background-position: bottom;
blockquote
element to indicate the pull quote
semantically in the markup:<blockquote> <p>Ma quande lingues coalesce, li grammatica del resultant lingue es plu simplic e regulari quam ti del coalescent lingues.</p> <div class="source">John Smith at the movies</div> </blockquote>
blockquote element:blockquote {
margin: 0;
padding: 0;
color: #555;
}
p and
div elements nested in the
blockquote element:blockquote p {
font: italic 1em Georgia, Times, "Times New Roman", serif;
font-size: 1em;
margin: 1.5em 2em 0 1.5em;
padding: 0;
}
blockquote .source {
text-align: right;
font-style: normal;
margin-right: 2em;
}
border-left and
border-right properties:border-left: 1em solid #999; border-right: 1em solid #999;
blockquote element to mark up the pull
quote content:<blockquote> <p>«Ma quande lingues coalesce, li grammatica del.»</p> </blockquote>
blockquote {
float: left;
width: 200px;
margin: 0 0.7em 0 0;
padding: 0.7em;
color: #666;
background-color: black;
font-family: Georgia, Times, "Times New Roman", serif;
font-size: 1.5em;
font-style: italic;
border-top: 1em solid #999;
border-bottom: 1em solid #999;
}
blockquote p {
margin: 0;
padding: 0;
text-align: left;
line-height: 1.3em;
}
float
property as well as the
width
property for the
blockquote element. These two CSS properties allow
the main content to wrap around the pull quote:float: left; width: 200px;
color: #666; background-color: black;
border-top and
border-bottom properties to match the color of the
text in the pull quote:border-top: 1em solid #999; border-bottom: 1em solid #999;
float property; Recipe
Recipe 1.8 for styling headings with borders;
Recipe 10.3 and Recipe 10.4
for
more
on
designing with contrast.
blockquote element to mark up the pull
quote content:<blockquote> <p>Ma quande lingues coalesce, li grammatica del resultant lingue es plu simplic e regulari quam ti.</p> </blockquote>
blockquote element and another
in the background of the p:blockquote {
background-image: url(bracket_left.gif);
background-repeat: no-repeat;
float: left;
width: 175px;
margin: 0 0.7em 0 0;
padding: 10px 0 0 27px;
font-family: Georgia, Times, "Times New Roman", serif;
font-size: 1.2em;
font-style: italic;
color: black;
}
blockquote p {
margin: 0;
padding: 0 22px 10px 0;
width:150px;
text-align: justify;
line-height: 1.3em;
background-image: url(bracket_right.gif);
background-repeat: no-repeat;
background-position: bottom right;
}
blockquote element
and the other in the p element that is a child of
the blockquote element:blockquote {
background-image: url(bracket_left.gif);
background-repeat: no-repeat;
float: left;
width: 175px;
}
blockquote p {
background-image: url(bracket_right.gif);
background-repeat: no-repeat;
background-position: bottom right;
}
blockquote and p elements so
that you have an unobstructed view of the images:
text-indent
property to create the indent:p {
text-indent: 2.5em;
margin: 0 0 0.5em 0;
padding: 0;
}
text-indent property can take absolute and
relative length units as well as percentages. If you use percentages,
the percentage refers to the element's width and not
the total width of the page. In other words, if the indent is set to
35% of a paragraph that is set to a width of 200 pixels, the width of
the indent is 70 pixels.text-indent property at http://www.w3.org/TR/CSS21/text.html#propdef-text-indent.
p.normal {
padding: 0;
margin-left: 0;
margin-right: 0;
}
p.large {
margin-left: 33%;
margin-right: 5%;
}
p.medium {
margin-left: 15%;
margin-right: 33%;
}
<p class="normal">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna al iquam erat volutpat.</p> <p class="large">Epsum factorial non deposit quid pro quo hic escorol. Olypian quarrels et gorilla congolium sic ad nauseum. Souvlaki ignitus carborundum e pluribus unum.</p> <p class="medium ">Li Europan lingues es membres del sam familie. Lor separat existentie es un myth. Por scientie, musica, sport etc., li tot Europa usa li sam vocabularium</p>
class attribute. The difference between class and
type selectors is that selectors pick out
every instance of the HTML element. In the following two CSS rules,
the first selector is a type selector that signifies all content
marked as h2 be displayed as red while the following CSS rule, a
class selector, sets the padding of an element to 33%:h2 {
color: red;
}
.largeIndent {
padding-left: 33%;
}
text-align
property:P {
width: 600px;
text-align: justify;
}
text-align
property at http://www.w3.org/TR/REC-CSS2/text.html#alignment-prop.
:first-line pseudo-element to set the
style of the first line:p:first-line {
font-weight: bold;
}
:first-line
pseudo-element at http://www.w3.org/TR/CSS21/selector.html#first-line-pseudo.
background-image
property within the
:first-line
pseudo-element:p:first-line {
font-size: 2em;
background-image: url(background.gif);
}
:first-line selectors styles can only
be applied to the first line of text of an element and not the width
of the element itself.background-image property, the
:first-line pseudo-element also supports the
following properties allowing for greater design
control:font
color
background
word-spacing
letter-spacing
text-decoration
vertical-align
text-transform
text-shadow
line-height
clear
:first-line
pseudo-element at http://www.w3.org/TR/CSS21/selector.html#first-line-pseudo.
strong element to mark up the portions of
text you want to highlight:<p>The distribution of messages from the selling of propaganda to the giving away of disinformation takes place at a blindingly fast pace thanks to the state of technology... <strong>This change in how fast information flows revolutionizes the culture.</strong></p>
strong {
font-weight: normal;
background-color: yellow;
}
strong element is used
in this Solution, you also can use the em element
instead of the strong element to mark highlighted
text. The HTML 4.01 specification states that em
should be used for marking
emphasized text, while
strong "indicates stronger
emphasis."background-color
property. Because some browsers apply a
bold weight to text marked as strong, set the
font-weight to normal. When
using the em element, be sure to set the
font-style to normal as this
keeps browsers from setting the type in italic, as shown in the next
code listing.em {
font-style: normal;
background-color: #ff00ff;
}
strong and
em at http://www.w3.org/TR/html401/struct/text.html#edef-STRONG.
line-height:P {
line-height: 1.5em;
}
line-height value increases, the distance
between the lines of text grows. As the value decreases, the distance
between the lines of text shrinks and eventually the lines overlap
each other. Designers refer to the line height as the
leading
.line-height value can be a number and a unit
such as points, just a number, or a number and a percentage symbol.
If the line-height value is just a number, that
value is used as percentage or a scale unit for the element itself as
well as for child elements. Negative values aren't
allowed for line-height.font-size to 12px and the
line-height to 14.4px ((10px * 1.2) * 1.2px =
14.4px):body {
font-size: 10px;
}
p {
font-size: 1.2em;
line-height: 1.2;
}
line-height
property with the shorthand
font property when paired with a
font-size value. The following line transforms any
text in a p element to have a font size of 1em, to
have a line-height of 1.5em, and to display in a
sans-serif typeface:p {
font: 1em/1.5em sans-serif;
}
line-height
property at http://www.w3.org/TR/CSS21/visudet.html#propdef-line-height;
Recipe 1.6 for more information
on the
margin and
padding properties for the html
and body elements to 0:html, body {
margin: 0;
padding: 0;
position: absolute;
top: 0;
left: 0;
}
margin and padding
properties of the body element to
0 helps create a full-bleed effect—in
other words, it eliminates the whitespace around a web page (the
units in this case don't matter). And setting the
position to absolute and the
values for top and left to
0 helps remove the body margins in Netscape
Navigator 4.margin and padding
margin and
padding properties for the html
and body elements to 0:html, body {
margin: 0;
padding: 0;
position: absolute;
top: 0;
left: 0;
}
margin and padding
properties of the body element to
0 helps create a full-bleed effect—in
other words, it eliminates the whitespace around a web page (the
units in this case don't matter). And setting the
position to absolute and the
values for top and left to
0 helps remove the body margins in Netscape
Navigator 4.margin and padding properties
might not be all you need to change to get a full-bleed effect.
Default properties on other elements can have unexpected side effects
when attempting to change the page margin For example, if
h1 is the body
element's first child element, some
unintended whitespace will appear above the headline and below the
top of the browser's viewport. Figure 2-2 shows this undesired effect; the background
color of the headings and paragraphs is gray so that you can more
clearly see the effect.
h1, h2, h3)
to 0 as well as the body. This
sets all the sides of the element's padding to
0. If that setup isn't possible
(for example, you need to have a value at the bottom padding or
margin), set the
body,html {
scrollbar-face-color: #99ccff;
scrollbar-shadow-color: #ccccff;
scrollbar-highlight-color: #ccccff;
scrollbar-3dlight-color: #99ccff;
scrollbar-darkshadow-color: #ccccff;
scrollbar-track-color: #ccccff;
scrollbar-arrow-color: #000033;
}
http://jigsaw.w3.org/css-validator/validator-uri.html.
textarea for a web form,
framesets, iframes, and
generally anything with a scrollbar:.highlight {
scrollbar-face-color: #99ccff;
scrollbar-shadow-color: #ccccff;
scrollbar-highlight-color: #ccccff;
scrollbar-3dlight-color: #99ccff;
scrollbar-darkshadow-color: #ccccff;
scrollbar-track-color: #ccccff;
scrollbar-arrow-color: #000033;
}
<form>
<textarea class="highlight"></textarea>
</form>
text-align property:h1, h2, h3 {
text-align:center;
}
text-align, you can center text inside
block-level elements. However, in this example, the heading takes up
the entire width of the body element, and if you
don't apply a background color to the element, you
probably won't even notice this is happening. The
gray background color in Figure 2-6 shows the
actual width of the centered elements.
h1, h2, h3 {
margin-left: auto;
margin-right: auto;
}
margin-left and
margin-right
properties to auto, you center the element inside
its parent element. However, older but still popular browsers
won't render the presentation correctly. So,
workarounds are needed for individual situations.div element:<div class="center"> <table width="50%" border="1" cellpadding="30"> <tr> <td>This is the first cell</td> <td>This is the second cell</td> </tr> <tr> <td>This is the third cell, it's under the first cell</td> <td>This is the fourth cell, it's under the second cell.</td> </tr> </table> </div>
.center {
text-align: center;
}
.center table {
width: 50%;
margin-left: auto;
margin-right: auto;
text-align: left;
}