Font style - A Smarter Way To Learn HTML & CSS (2015)

A Smarter Way To Learn HTML & CSS(2015)

10
Font style

You can specify italics for any text. Here’s a class that applies italics to a paragraph.

p.standout {
font-style: italic;
}

Here’s a class that applies italics to h4 headings of the class “special”.

h4.special {
font-style: italic;
}

Here’s a class that applies italics to any text, whether it’s a paragraph, heading, or some other text element.

.emphasized {
font-style: italic;
}

Remember, class names can be anything you like, within the bounds of the naming rules I covered in Chapter 7.

Instead of defining CSS classes to italicize text, you can use the <i> tag in your HTML.

In the following paragraph, the words “David Copperfield” are italicized.

<p>Leading style manuals say book titles, like <i>David Copperfield</i>, should be italicized.</p>

An alternative to the <i> tag is the <em> tag.

<p>You must be dressed <em>and</em> ready to go.</p>

By default, the <em> tag has the same visual effect as the <i> tag. They both italicize text. The main difference is that when a screen reader sees the <em> tag, it puts extra vocal emphasis on the text enclosed in the tag. It doesn’t do that with <i> text.

Instead of creating a class for bold text in CSS, you can use the <b> tag in HTML. In the following paragraph the text “Please note:” is bolded.

<p><b>Please note:</b> The flight schedule is subject to change without notice.</p>

An alternative to the <b> tag is the <strong> tag. By default, the <strong> tag has the same visual effect as the <b> tag. They both bold text in most browsers. The main difference is that when a screen reader sees the <strong> tag, the reader may say the text in a lower tone. It doesn’t do that with <b> text.

In your CSS file, add a class not tied to an element that italicizes text. In your HTML file code a heading of that class. Then write a one-sentence paragraph. In the paragraph, use the two HTML tags that italicize text and the two HTML tags that bold text. Save the files and display your HTML file.

Sample CSS code is at:
http://asmarterwaytolearn.com/htmlcss/practice-10-1.html.

Sample HTML code is at:
http://asmarterwaytolearn.com/htmlcss/practice-10-2.html.

Find the interactive coding exercises for this chapter at:
http://www.ASmarterWayToLearn.com/htmlcss/10.html