XML technologies / CSS / CSS Cookbook / Design with CSS / Emphasizing quotations

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

Emphasize a quotation with large, bold quotation marks, as shown in the following figure.

A styled quotation

Figure: The styled quotation.

Solution

First mark up the quotation correctly (see the next figure):

<blockquote>
  <p>There is a tendency for things to right themselves.</p>
  <cite>Ralph Waldo Emerson</cite>
</blockquote>

The quotation’s default appearance

Figure: The quotation’s default appearance.

Then define the CSS rules required to display the quotation:

blockquote {
 padding: 0;
 margin: 0;
 text-align: center;
}
p {
 font-size: 1em;
 padding-bottom: 3em;
 text-transform: lowercase;
 font-family: Georgia, Times, "Times New Roman", serif;
 margin: 0;
 padding: 0;
}
cite {
 display: block;
 text-align: center;
}

Finally, use the pseudo-elements :before and :after to insert the quotation marks and an em dash before the quoted source’s name:

blockquote p:before {
 content: "\201C";
 font-size: 1.2em;
 font-weight: bold;
 font-family: Georgia, Times, "Times New Roman", serif;
}
blockquote p:after {
 content: "\201D";
 font-size: 1.2em;
 font-weight: bold;
 font-family: Georgia, Times, "Times New Roman", serif;
}
cite:before {
 content: "\2014 ";
}
cite {
 display: block;
 text-align: center;
}

Discussion

Using pseudo-elements, browsers can apply styles to parts of a page that standard HTML cannot reach. For example, pseudo-elements can target a paragraph’s first line or, as here, insert automatically generated content before and after a particular element.

This solution surrounds the quotation with typographic curly quotation marks. For example, the opening mark is declared as follows:

content: "\201C ";

Content inserted into a document through the property content must be enclosed in single or double quotation marks. To use single quotation marks for the quotation, we could also write:

content: " ' ";

For ordinary double quotation marks, the rule would look like this; spaces have been added before and after the inserted character for readability:

content: ' " ';

However, the curly quotation marks used here are not part of the standard ASCII character set, so we use their hexadecimal equivalents to avoid browser misunderstandings.

Because everything between the quotation marks is generated automatically, we must escape the hexadecimal value with a backslash.

Another way to insert quotation marks is to give the property content the keyword open-quote or close-quote as its value:

content: open-quote;

Note that the keywords open-quote and close-quote are currently supported only by Mozilla and Opera. Internet Explorer for Windows and Macintosh also does not support the pseudo-elements :before and :after.

See also

The recipe Displaying the URI after a link for adding URLs to printed web pages using pseudo-elements, and the CSS2 specification on quotation marks and generated content.

  

 

 

 

back to top