Web Design Manual
Style Sheets
<HTML>
<HEAD>
<TITLE>Style Sheet Fun</TITLE>
</HEAD>
<BODY>
<H1>Big Display Type</H1>
<H2>Smaller Display Type</H2>
<P>Wow. Style sheets equal power! My life is never
going to be the same!</P>
</BODY>
</HTML>
The <STYLE> tag (the building block of embedded
style sheets) goes anywhere in the HEAD section:
<STYLE TYPE="text/css">
<!--
H1 { font-size: 20pt; background: red; font-family:
helvetica, arial,
sans-serif }
H2 { font-size: 15pt; font-family: helvetica, arial,
sans-serif; }
P { background: blue; text-align: right; font-family:
courier, fixed,
monospace }
-->
</STYLE>
Admittedly, that may look terrible, but it works! So
whats happening, exactly? Well, the TYPE="text/css" and the information
within the comment tags ("<!--" and "-->" ) inform the browser
of the specified preferences. This way, older browsers wont mistakenly display the
code, which your readers would no doubt find either highly amusing or seriously baffling.
(But fear not; if the browser viewing the page doesnt understand CSS, it will just
display the page normally.) The rest of the code instructs the browser how to display
certain kinds of text. The H1 line, for example, specifies that any text on the page
within <H1> tags should appear in a font from the Helvetica family (more about font
families in a bit), should be 20 points high, and have a red background. The P line makes
any text between <P> tags appear right-aligned in Courier, with a blue background.
Using this simple format, you can control nearly
everything about your pages appearance from one centralized seat of power! Specify
rules to apply to any tag, such as: <B>, <UL>, <STRONG>, or any other.
You might make text within <B> tags italic and huge, or you might choose to tag all
text within <I> tags superscript and bold. Heres an overview of the style
rules at your disposal.
Font-family
In an ideal world, all of your sites visitors would
have the same fonts loaded on their computers, and you could specify fonts with
confidence, knowing every user would have exactly the same experience. In reality, you
have to make do with your best educated guess. Provide a list of desired fonts, and the
users browser will try each one in order until it finds a match. Systems running
Windows typically have a font called arial, which looks a lot like what Macs call
Helvetica. Just to be safe, at the end of your list you should name the type of font you
want, so that if no specific matches were made, youll at least get the general idea
across, as in this example: "P { font-family: arial, helvetica, sans-serif }".
The generic font types to choose from are serif, sans-serif, monospace, fantasy, and
cursive.
Font-size
You can specify font size in points (pt), pixels (px), or
in a variety of other ways. (For these and many other details, see Mulders tutorial,
linked below.) Specify "font-style: italic" to call for italics, and
"font-weight: bold" for bold. Specific numeric weights can also be selected;
experiment to see how weights look with various fonts on different browsers.
Text-transform
Use this to capitalize or lowercase text
globallythe allowed values are uppercase, lowercase, capitalize (title style), and
none.
Text-decoration
This property allows you to either impress or confound
your users (depending on their Web experience) with those neat, albeit confusing,
nonunderlined links. Just include the rule "a:link { text-decoration: none }"
and theyll have to drag their mouse all over creation in search of your hidden
hyperlinks. Other values for text-decoration include underline, blink, and line-through.
Color
Add color to your text or element backgrounds with the
color and background-color properties. Coding your color as such: "B { color:
#000000; background-color: #FF0000 }" will make all text appearing between <B>
tags appear black on a red background. You can also add a background image to just one
paragraph or element, using a rule along the lines of: "P {background-image:
url(pics/plaid.gif) }".
Aligning text
As seen in the initial CSS example, use the text-align
property to set your preferences. This works only on header, list, and paragraph text, for
obvious reasons. But despite the name, you can also text-align images, as such: "IMG
{ text-align: center }". Paragraphs can also be indented, using the text-indent
property. This property regards points, pixels, and other measurement units as values, and
indents the first line of a paragraph by the specified width. A negative value results in
a negative indent, with the first line hanging over to the left while the rest of the
paragraph is indented.
Margins
That much-missed feature of printed text is now, through
the miracle of style sheets, available on the Web, without requiring you to put everything
in yet another layout table. A margin rule looks like this:
BODY { margin-left: 10pt; margin-right: 15pt}
In this example, the page has a left margin of 10 points
and a right margin of 15 points. Other commands available include margin-top and
margin-bottom.
Borders
Each element can also have a border, which can be
manipulated with the border-width, border-color, and border-style properties. Widths are
expressed numerically, and styles can be selected from among the following: dashed,
dotted, double, inset, outset, ridge, or solid. You may choose to specify each side of the
border separately. For varying widths, the different property names are: border-top-width,
border-right-width, border-bottom-width, and border-left-width. For border color and
style, you just list the values, in top-right-bottom-left order. To illustrate:
BLOCKQUOTE {border-top-width: 5pt; border-right-width:
10pt;
border-bottom-width: 8pt; border-left-width: 17pt;
border-color: red red
green red; border-style: double double double solid }
Some of you may be wondering what to include if you want
different paragraphs to have different styles. Not to worry; you simply call styles
in-line. To do this, specify the style in the <P> tag: <P
STYLE="text-indent:
20pt; color: #660066">blah blah blah</P>.
Yet including this same style code on every page would normally require considerable
typing. Instead, use classes to accomplish this task more efficiently. Define and name a
style within the CLASS attribute. Just write a rule similar to the following:
.slick {color: black; font-family: "gill sans",
impact sans-serif }
Be sure to include a "." at the beginning of
your style name. This allows you, whenever you want to use that style, to call it as an
attribute from any tag: "<P CLASS="slick">blah blah
blah</P>". You can make as many of these styles as you want.
To make your life even more interesting, create and save
a separate document with all of the styles youll be using on your pages. Then simply
call that document from each page! This way, when its time to ditch that tired, old,
20th-century look in the year 2001, you only have to change one file, and your
entire 300-page site is instantly renovated. How is this possible? Easy! Just put all of
your rules in a text document (no headers or anything needed), save it with a .css
extension (stylee.css, for example), and upload it. In every page in which you want to use
that style, include a line like the following in the head section:
<LINK REL=stylesheet HREF="stylee.css"
TYPE="text/css">
All of the style rules in stylee.css will be applied to
the page. They will, however, be overridden by any style rules you specify on that
particular page. In addition, style rules you specify in-line will in turn override those
specified in a STYLE tag in the head.
Web Design Manual
|