This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
In the beginning, Tim created the HyperText Markup Language. The Internet was without form and void, and text was upon the face of the monitor and the Hands of Tim were moving over the face of the keyboard. And Tim said, Let there be links; and there were links. And Tim saw that the links were good; and Tim separated the links from the text. Tim called the links Anchors, and the text He called Other Stuff. And the whole thing together was the first Web Page.
tag used in Listing 3.1 encloses a paragraph of text. You should enclose your chunks of text in the appropriate container tags whenever possible.
33
NOTE You no doubt noticed in Listing 3.1 that there is some extra code associated with the tag. This code consists of two attributes (xmlns and xml:lang), which are used to specify additional information related to the tag. These two attributes are standard requirements of all XHTML web pages; the former defines the XML namespace, while the latter defines the language of the content. Throughout this book a standard namespace is defined, and the English language is used. If you are writing in a different language, replace the “en” (for English) with the language identifier relevant to you.
TIP You might find it convenient to create and save a bare-bones page (also known as a skeleton page) with just the opening and closing ,
When your client’s hopping mad, put his picture in the ad. If he still should prove refractory, add a picture of his factory.
When your client’s hopping mad,
put his picture in the ad.
If he still should prove refractory,
add a picture of his factory.
tags.
You must use HTML tags if you want to control where line and paragraph breaks actually appear. When text is enclosed within the
tags being used to separate the lines and verses of an advertising agency song. You might have also noticed the
tag at the beginning of each paragraph and a
tag at the end of each paragraph. 4. UseMy widgets are the best in the land. Continue reading to learn more about my widgets.
If I had any features to discuss, it here.
Here, I would talk about my widget pricing.
Here, I would talk about how my widgets compare to my competitor’s widgets.
…
Come on Down!
This text is blue.
This text is still green.
tags are children of the
tag overrides the color style and changes it to blue. The end result is that the first line (not surrounded by a paragraph tag) is green, the first official paragraph is blue and the second official paragraph retains the cascaded green color.
A Basic Style Sheet
49
Like many web technologies, CSS has evolved over the years. The original version of CSS, known as Cascading Style Sheets Level 1 (CSS1) was created in 1996. The later CSS 2 standard was created in 1998 and CSS 2 is still in use today. All modern web browsers support CSS 2, and you can safely use CSS 2 style sheets without too much concern. So when I talk about CSS throughout the book, I’m referring to CSS 2. You’ll find a complete reference guide to CSS at http://www.w3.org/Style/CSS/. The rest of this hour explains how to put CSS to good use.
A Basic Style Sheet Despite their intimidating power, style sheets can be simple to create. Consider the web pages shown in Figure 4.1 and Figure 4.2. These pages share several visual properties that could be put into a common style sheet: . They use a large, bold Verdana font for the headings and a normal size and weight Verdana font for the body text. . They use an image named logo.gif floating within the content and on the right side of the page. . All text is black except for subheadings, which are purple. . They have margins on the left side and at the top. . There is vertical space between lines of text. . The footnotes are centered and in small print. FIGURE 4.1 This page uses a style sheet to fine-tune the appearance and spacing of the text and images.
50
HOUR 4: Understanding Cascading Style Sheets
FIGURE 4.2 This page uses the same style sheet as the one shown in Figure 4.1, thus maintaining a consistent look and feel.
Listing 4.1 shows the code for style sheet specifying these properties.
Listing 4.1
A Single External Style Sheet
body { font-size: 10pt; font-family: Verdana, Geneva, Arial, Helvetica,sans-serif; color: black; line-height: 14pt; padding-left: 5pt; padding-right: 5pt; padding-top: 5pt; } h1 { font: 14pt Verdana, Geneva, Arial, Helvetica,sans-serif; font-weight: bold; line-height: 20pt; } p.subheader { font-weight: bold; color: #593d87; } img { padding: 3pt; float: right; }
A Basic Style Sheet
Listing 4.1
A Single External Style Sheet
a { text-decoration: none; } a:link, a:visited { color: #8094d6; } a:hover, a:active { color: #FF9933; } div.footer { font-size: 9pt; font-style: italic; line-height: 12pt; text-align: center; padding-top: 30pt; }
This might initially appear to be a lot of code, but if you look closely, you’ll see that there isn’t a lot of information on each line of code. It’s fairly standard to place individual style rules on their own line to help make style sheets more readable. Speaking of code readability, perhaps the first thing you noticed about this style sheet code is that it doesn’t look anything like normal HTML code. CSS uses a language all its own to specify style sheets. Of course, the listing includes some familiar HTML tags. As you might guess, body, h1, p, img, a, and div in the style sheet refer to the corresponding tags in the HTML documents to which the style sheet will be applied. The curly braces after each tag name contain the specifications for how all content within that tag should appear. In this case, all body text should be rendered at a size of 10 points, in the Verdana font (if possible), and with the color black and 14 points between lines. If the user does not have the Verdana font installed, the list of fonts in the style sheet represents the order in which the browser should search for fonts to use: Geneva, then Arial, then Helvetica. If the user has none of those fonts, the browser will use whatever default sans-serif font is available. Additionally, the page should have left, right, and top margins of 5 points each. Any text within an
tag will
51
52
HOUR 4: Understanding Cascading Style Sheets
inherit all the styles indicated by the body element. However, if the
tag uses a special class named subheader, the text will appear bold and in the color #593d87 (a purple color). The pt after each measurement in Listing 4.1 means points (there are 72 points in an inch). If you prefer, you can specify any style sheet measurement in inches (in), centimeters (cm), pixels (px), or widths-of-a-letter-m, which are called ems (em).
NOTE You can specify font sizes as large as you like with style sheets, although some display devices and printers will not correctly handle fonts larger than 200 points.
You might have noticed that each style rule in the listing ends with a semicolon (;). Semicolons are used to separate style rules from each other. It is therefore customary to end each style rule with a semicolon so you can easily add another style rule after it. To link this style sheet to HTML documents, include a tag in the
The Bay Area Women’s Sports Initiative (BAWSI) is a public benefit, nonprofit corporation with a mission to create programs and partnerships through which women athletes bring health, hope and wholeness to our community. Founded in 2005 by Olympic and World Cup soccer
A Basic Style Sheet
Listing 4.2
HTML Code for the Page Shown in Figure 4.1
stars Brandi Chastain and Julie Foudy and Marlene Bjornsrud, former general manager of the San Jose CyberRays women’s professional soccer team, BAWSI provides a meaningful path for women athletes to become a more visible and valued part of the Bay Area sports culture.
BAWSI’s History
The concept of BAWSI was inspired by one of the most spectacular achievements in women’s sports history and born out of one its biggest disappointments...
,
Text about Marvin’s Munchies goes here.
Text for business investors goes here.
class and the footer
tags to get the feel for things.
Using Style IDs When you create custom style classes, you can use those classes as many times as you would like—they are not unique. However, there will be some instances when you want to have precise control over unique elements for layout or formatting purposes (or both). In such instances, look to IDs instead of classes. A style ID is a custom set of formatting specifications that can be applied only to one element in a web page. You can use IDs across a set of pages but only once per time within each page. For example, suppose you have a title within the body of all your pages. Each page has only one title, but all of the pages themselves include one instance of that title. Following is an example of a selector with an ID indicated, plus a property and a value: p#title {font: 24pt Verdana, Geneva, Arial, sans-serif}
Notice that this selector includes a hash mark, or pound sign (#), after p, followed by a descriptive ID name. When referencing a style ID in HTML code, simply specify the ID name in the id attribute of an element, like so:
Some Title Goes Here
tags will appear in 24point Verdana text—but only once on any given page. You will often see style IDs used to define specific parts of a page for layout purposes, such as a header area, footer area, main body area, and so on. These types of areas in a page will appear only once per page, so using an ID rather than a class is the appropriate choice.
61
TRY IT YOURSELF ▼ Add Classes to Your Style Sheet
62
HOUR 4: Understanding Cascading Style Sheets
Internal Style Sheets and Inline Styles In some situations, you might want to specify styles that will be used in only one web page, in which case you can enclose a style sheet between <style> and tags and include it directly in an HTML document. Style sheets used in this manner must appear in the
,
This text is green, but <span style=”color:red”>this text is red. Back to green again, but...
...now the green is over, and we’re back to the default color for this page.
tag and the <span> tag in this example use the color property as an inline style. What’s important to understand is that the color:red style property overrides the color:green style property for the text appearing between the <span> and tags. Then in the second paragraph, neither of the color styles applies because it is a completely new paragraph that adheres to the default color of the entire page.
63
NOTE and are dummy tags that do nothing in and of themselves except specify a range of content to apply any style attributes that you add. The only difference between
tag, you can specify whether the text in that particular paragraph should be aligned to the left margin, the right margin, or to the center of the page by setting the style attribute. If you want to associate that particular paragraph with an existing class or ID, you set the class or id attribute. In the following example, each paragraph could be left-aligned:
Text goes here.
Text goes here.
Text goes here.
However, this code does not conform to XHTML standards because the tag is uppercased, the style attribute and its value (text-align:center) is uppercased, and the value isn’t in quotation marks. If you want to stay compatible with the latest standards and software, you should always use the following instead:
Aligning Block-Level Elements To align a block-level element such as
to the right margin without creating a separate class or ID in a style sheet, simply place style=”textalign:right” inside the
tag at the beginning of the paragraph. Similarly, to center the element, use
. To align a paragraph to the left, use
. The text-align part of the style attribute is referred to as a style rule, which means that it is setting a particular style aspect of an HTML element. There are many style rules you can use to carefully control the formatting of web content. The text-align style rule is not reserved for just the
tag. In fact, you can use the text-align style rule with any block-level element, which includes
and the
tag, the default value is left, so using the barebones
tag has the same effect as using
. Learning the default values for common style rules is an important part of becoming a good web page developer.
70
HOUR 5: Working with Text Blocks and Lists
Listing 5.1
The text-align Style Rule Used with the style Attribute
Authors and actors and artists and such
Never know nothing, and never know much.
Sculptors and singers and those of their kidney
Tell their affairs from Seattle to Sydney.
Playwrights and poets and such horses’ necks
Start off from anywhere, end up at sex.
Diarists, critics, and similar roe
Never say nothing, and never say no.
People Who Do Things exceed my endurance;
God, for a man that solicits insurance!
,
and
This paragraph is bold and italic!
tag. The key to using multiple style rules is that they must be separated by a semicolon (;). You aren’t limited to using font styles in paragraphs, however. The following code shows how to italicize text in a bulleted list:
New <sup>Super<strong>Strength H<sub>2O <em>plus will knock out any stain, big or <small>small.
Look for new <sup>SuperStrength H<sub>2O plus in a stream near you.
NUTRITION INFORMATION (void where prohibited)
<pre> Calories Grams USRDA /Serving of Fat Moisture Regular 3 4 100% Unleaded 3 2 100%
There are several interesting things about this example. First, arial is specified as the primary font. Capitalization does not affect the font family, so arial is no different from Arial or ARIAL. Another interesting thing about this code is how single quotes are used around the times roman font name because it has a space in it. However, since ‘times roman’ appears after the generic specification of sans-serif, it is unlikely that ‘times roman’ would be used. Because sans-serif is in the second position, it says to the browser “if Arial is not on this machine, use the default sans-serif font.”
NOTE You’ll learn about hexadecimal colors in Hour 9. For now, just understand that the color style rule allows you to specify exact colors beyond just using green, blue, orange, and so forth.
The font-size and color style rules are also commonly used to control the size and color of fonts. The font-size style can be set to a predefined size (such as small, medium, or large) or you can set it to a specific point size (such as 12pt or 14pt). The color style can be set to a predefined color (such as white, black, blue, red, or green) or you can set it to a specific hexadecimal color (such as #FFB499.) Following is the previous paragraph example with the font size and color specified:
The example web content in Listing 6.2 and shown in Figure 6.2 uses some font style rules to create the beginning of a basic online résumé.
Listing 6.2
Using Font Style Rules to Create a Basic Résumé
1234 Main Street, Sometown, CA 93829
tel: 555-555-1212, e-mail: [email protected]
Summary of Qualifications
Professional Experience
<span style=”font-weight:bold;”>Operations Manager, Super Awesome Company, Some City, CA [Sept 2002 – present]
<span style=”font-weight:bold;”>Project Manager, Less Awesome Company, Some City, CA [May 2000 - Sept
87
88
HOUR 6: Working with Fonts
Listing 6.2
Using Font Style Rules to Create a Basic Résumé 2002]
Education
References
Q: What should you do when a British banker picks a fight with you?
A: £ some ¢¢ into him.
,
<span style=”font-weight: bold”>First three words are bold.
<span style=”font-weight: bold”>First three words are
bold.
,