XML technologies / ePUB / ePub für (In)Designer / A short introduction to HTML and CSS / CSS
(Excerpt from “ePub für (In)Designer — Mit InDesign Schritt für Schritt zum E-Book” by Sascha Heck & Yves Apel)
HTML concerns descriptive text markup: it structures the document. How the browser or e-reader displays tags has not yet been specified. Unless a tag is further defined, readers use its default appearance. The appearance of headings and text is defined in CSS (Cascading Stylesheets). HTML is a separate file, found in OEBPS or Sigil’s Text subfolder; CSS is another text file, template.css in OEBPS or Sigil’s Styles subfolder. The HTML header references CSS so the reader knows to apply its properties. InDesign does this automatically; no action is needed.
<link href="../Styles/template.css" rel="stylesheet" type="text/css"/>CSS lists the tags used in HTML and their assigned properties. Suppose a heading should be red, Minion Pro, 24 points, bold, with 10 millimeters of space afterward. In InDesign, define this in a paragraph style. The exported CSS file then contains:
h1 {
font-family: "Minion Pro", serif;
font-weight: bold;
font-size: 2em;
color: #d90000;
margin: 0px 0px 28px 0px;
}If you understand some English, you will recognize the properties. Familiar print units such as points and millimeters become screen units: 24 points becomes 2 em (two em squares), and 10 millimeters becomes 28 pixels.
Classes
Classes are important in CSS. Consider an image caption: HTML has no caption tag, so convey this information another way. Mark it with the paragraph tag <p> and additionally define a freely named class. This class appears in CSS, where attributes control the caption’s appearance. Reference a class in HTML:
<p class="bildunterschrift">Ich bin eine Bildunterschrift</p>The class appears in CSS in this form:
p.bildunterschrift {
font-family: serif;
font-size: 1em;
font-weight: normal;
font-style: italic;
color: #000000;
}font-family, font-size and so on are possible attributes assigned to the class.
Character styles are declared in HTML using the tag span. To make a word red within a paragraph, for example, HTML looks like this:
<p>Ich bin ein Absatz und dieses <span class="rot">Wort</span> wird jetzt rot dargestellt werden.</p>The class rot now reappears in CSS and contains only the red color definition.
span.rot {
color: #d90000;
}InDesign automatically generates classes from your paragraph and character styles. Later chapters will sometimes edit HTML or CSS, adding or changing a line to achieve a particular reader display effect.
For ePub production, simple, logical tags and classes give the best results across readers. Everything belonging to body text, for instance, should receive the tag <p>. Assign variations in the respective class.
Some readers interpret only part of CSS. Almost all, however, recognize standard tags and display them accordingly. This ensures that, at worst, the reader still interprets and displays content with the correct structure, even without all the attractive styling.
This deliberately brief introduction helps explain relationships discussed throughout the book. We encourage deeper study: many textbooks and teaching videos are available, for example “Einführung in XHTML, CSS und Webdesign” by Michael Jendrischik.
Copyright © dpunkt.verlag GmbH 2012
You may print the online version for your private use.
Otherwise, this chapter from “ePub für (In)Designer” is subject to the same terms as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
dpunkt.verlag GmbH, Wieblinger Weg 17, 69123 Heidelberg, fon 06221-14830, fax 06221-148399, hallo(at)dpunkt.de