Recipe 2.22. Creating a Highlighted Text Effect


Problem

You want to highlight a portion of the text in a paragraph, as in Figure 2-37.

Figure 2-37. Highlighted text


Solution

Use the 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&hellip; <strong>This  change in how fast information flows revolutionizes the  culture.</strong></p>

Then set the CSS rule to set the highlighted:

strong {  font-weight: normal;  background-color: yellow; }

Discussion

Although the 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."

Once the text has been marked, set the highlighter color with the 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; }

See Also

The HTML specification for strong and em at http://www.w3.org/TR/html401/struct/text.html#edef-STRONG.




CSS Cookbook
CSS Cookbook, 2nd Edition
ISBN: 0596527411
EAN: 2147483647
Year: 2006
Pages: 235

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net