XML technologies / CSS / Advanced websites with CSS / Behind the scenes / CSS with HTML documents
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
In the first chapter, I introduced all three ways to apply stylesheets to an HTML document. Here is a brief recap:
Inline stylesheets
You can style almost any HTML element directly by writing the style in an attribute style in the HTML tag.
<h1 style="font-family: Helvetica, Arial, sans-serif; color: blue;">Willkommen</h1>This method is best used to test a style rule’s effect on a particular HTML element. I advise against using it as the final CSS solution for an entire website, because it eliminates almost all CSS advantages.
Embedded stylesheets
Apply a stylesheet to an entire HTML document by embedding all the page’s style rules in a tag <style> inside the document’s section head.
<style type="text/css">
h1, h2 {
color: green;
}
h3 {
color: blue;
}
</style>Embedded stylesheets offer many advantages over inline stylesheets. However, they are far less versatile and powerful than external stylesheets. I recommend embedded stylesheets only for rules applying to a single page. The advantages of separate code in external stylesheets are obvious, but embedded stylesheets are convenient for a quick solution on an individual page.
External stylesheets
Apply a stylesheet stored in a separate CSS file to an HTML document by creating a tag <link> in the section head with the CSS file’s path.
<link rel="stylesheet" type="text/css" href="meine_stile.css" />External stylesheets are the most recommended way to use CSS. They deliver all CSS benefits for speed and productivity.
Copyright © 2006 of the German translation, dpunkt.verlag GmbH
You may print the online version for your private use.
Otherwise, this chapter from “CSS − Anspruchsvolle Websites mit Cascading Stylesheets” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
dpunkt.verlag GmbH, Ringstraße 19, 69115 Heidelberg