In this section you will look at styling and adding structured content to the center column—your content div. Using the correct elements for your markup is of paramount importance. Good semantic markup enables your XHTML document to have a meaningful structure that is not only structured in the visual sense but is also machine-readable by screen readers and other assistive technologies.
First, remove the height and background-color properties and values from the #content selector:
#content h1 {
color: #577f1c;
font-family: Georgia, "Times New Roman", Times, serif;
}
The selector for the content div is a descendant selector. By mapping the selector in this way, you are free to use h1 elements in other areas of your design without one area affecting another. For example, if you wanted to add h1 elements to the #rightcol div, you could write a selector like this:
#rightcol h1 {
Properties: values;
}
When you write rules as descendant selectors, you isolate one selector from another. In other words, despite both elements being h1 elements, none of the properties and values set in one would affect the other. This is the beauty of mapping your selectors in this manner—it provides structured organization.
To create your #content h1 selector, complete the following steps:
#content selector.Create a blank line below the closing } and then enter the following (pressing Enter after each line):
#content div tag.Type <h1>Welcome to Health & Spa</h1>
Your content div should now look like the following code:
<div id="content"> <h1>Welcome to Health & Spa</h1> <!-- Close content --> </div>
Tip: Be sure to use & as the code for the ampersand instead of just &.
You now need to add some content to the page. However, first you must define how that content will appear in the browser. You'll do this by defining the #content p selector. You need to set margin values on your p elements.
You might recall that the first thing you did in your style sheet was to remove the default values. If you do not specifically set margins on the p elements, then your paragraphs will not have any spacing between them. Follow these steps:
#content h1 selector.Enter a blank line below the closing } and type the following (pressing Enter after each line):
h1 element and press Enter.Place your cursor close to the center of the generated text and press Enter. You now have two paragraphs. Note that you have no space between them (see Figure 1). This is due to your zeroing selector.
Figure 1. Paragraphs with no padding or margins
#content p selector.
Figure 2. Paragraphs with the added margin setting
Now repeat the steps above with the following changes:
h2 selector for the content div, make the font size 130%, and keep the same font and color that you set for the h1 elementh2 element to your health.html document immediately below the second paragraphh2 elementTip: You do not need to create a second p selector. The styles for your element will be picked up automatically from the existing selector you created in the previous section.
After you complete those changes, preview your page in Firefox. It should resemble Figure 3.
Figure 3. Did you get it right?
Next, you'll add a blockquote element to our document and set up a default link that you can use throughout the design.
blockquote ElementFollow these steps to add a blockquote element to your text:
h2 element.Type the following:
<blockquote>This is some quoted text. We are going to style this blockqoute and then we will apply a hover effect to it.</blockquote>
Open your health.css file and type the following below your existing style rules (pressing Enter after each line):
blockquote {Your page should now look like Figure 4.
Figure 4. Blockquote now in place
The second selector you created enables the blockquote's border to change color when a user places the mouse cursor over the blockquote element (see Figure 5).
Figure 5. Border color changes on hover
#rightcol DivWith the main content area complete, you can now look at styling the content that resides in the #rightcol div.
The #rightcol div contains three basic elements: the h4 element for each sections title, the p element for holding the text information, and an a element to provide links to other pages where the information can be read in detail.
Using the knowledge you have gained in this tutorial, complete the following task:
#rightcol selector and add a blank line below it.Using a descendant selector, create an h4 selector that applies only to the #rightcol div and give it the following properties:
Using a descendant selector, create a p selector that applies only to the #rightcol div and give it the following properties:
#rightcol selector.height property and value.background-color property and value.Next, add the elements to your page and create the default link styles. Follow these steps:
#rightcol div and then insert, with dummy content, the following elements: h4, p, h4, p.Open the health.css file in Code view and add the following to the end of your CSS file:
a {Insert a blank line and then type the following:
a:hover, a:focus {p elements below the h4 elements.That completes the styling of the #rightcol div content.
#footer DivPlace a copyright notice in the #footer div. For this task, you will create a selector for the p element within the footer. Follow these steps:
Open your health.css file and type the following:
#footer p {#footer div tag and place your cursor at the end ot the tag.Press Enter and type the following:
<p>This site is copyrightSelect the copyright icon and then type the following:
of me!</p>You have now completed Part 4 of this tutorial.
In this part you have learned how to use descendant selectors to map CSS rules to specific areas of your document. You have seen how hover and focus techniques can be applied to elements and learned how to make CSS buttons and make them clickable.
In Part 5 of this series, you look at the CSS rules you have written so far and what you need to do to make it cross-browser compatible. You will look at conditional comments and learn how to use filters within your style sheets.
Applying CSS from Screen to Print to Handheld – Part 5: Cross-Browser Compatibility
Incidentally, in case you're wondering why you don't have style content within your XHTML document, the aim of CSS and XHTML is to separate content from style—and you have done just that.