XML technologies / CSS / CSS Cookbook / Typography for the web / Headings with style

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

You want to design a heading that differs from the default appearance. For example, you may want to italicize the heading in the following figure, as shown in the figure after that.

Default heading appearance

Figure: Default heading appearance.

The heading with styles applied

Figure: The heading with styles applied.

Solution

First mark up the heading correctly as a heading:

<h2>Designing Instant Gratification</h2>
<p>Online, activity of exchanging ideas is sped up. 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;</p>

Then use the shorthand property font to customize its appearance easily:

h2 {
 font: bold italic 2em Georgia, Times, "Times New Roman", serif;
 margin: 0;
 padding: 0;
}
p {
 margin: 0;
 padding: 0;
}

Discussion

As described in the recipe Shorthand properties, a shorthand property combines several individual properties into one. The property font is one of these time-saving properties. It can represent values for the following properties:

  • font-style

  • font-variant

  • font-weight

  • font-size/line-height

  • font-family

The first three values may appear in any order, but the remaining values must follow the order shown here.

If you want to define a value for line-height, separate it from the value for font-size with a slash:

p {
 font: 1em/1.5em Verdana, Arial, sans-serif;
}

When styling headings, remember that browsers supply their own defaults for paragraph and heading margins and padding. These defaults generally have mathematical rather than aesthetic foundations.

See also

The CSS 2.1 specification on shorthand properties.

  

 

 

 

back to top