To understand the significance of CSS, let's consider the analogy of a book. A book has both structure and appearance. The structure of a book involves levels of information, such as chapters, pages, paragraphs, and the textual content of the book. The appearance of a book involves page size, margin, indentations, font size, color, and so forth. When an author writes a book, the author focuses on the structure and organizes the textual information into chapters, pages, and paragraphs. After the manuscript is accepted by a publisher, the publisher focuses on the appearance of the book. Notice that because the structure and appearance are separated, the author and the publisher focus on the aspect of the book that is of most concern to them. So it is with web pages. Web pages have structure and they have appearance. The XHTML markup language provides the structure, and CSS handles the appearance. The use of CSS can save the designer hours of time. The designer can change a rule in CSS to use a different font, for example, and every HTML page that uses that rule will automatically be updated to use the new font. In addition, CSS increases the accessibility of web sites by allowing visitors to control the appearance of the web pages (a boon to persons using PDAs to access web pages and to persons who might need special font sizes, colors, etc). Let's look at two methods of providing the rules to web pages. Linking to Style SheetsCSS rules can be grouped into files that are external to the web pages. Each file is a style sheet. Web pages can link to style sheets. The syntax of the link is the following, where pathtostylepage is the path and file name of the style sheet. The style sheet must have a .css extension. The link goes in the <head> of the program. Grouping the CSS rules into separate files has advantages.
This linking to style sheets is the method taught in this tutorial site. Embedded Style InformationCSS rules can also be embedded within the header of the XHTML code. The following syntax is used.
An example is
Notice the <style> tag and the rule information are enclosed in XHTML comments. This provides protection when the page is read via browsers that do not support CSS. Those browsers will think the embedded information is a comment and will ignore it. Browsers that support CSS will ignore the comment and will use the CSS information.
|