Merging CSS and HTML

There are three ways to add CSS to your Web pages:

Inline styles: With this method, the effect is totally localized. That is to say, the style you create with this method applies only to the element that contains it and to nothing else on the Web page. An inline style is the simplest kind of CSS, but lacks much flexibility. It uses the style attribute to add CSS. An inline style that sets the color only for the H1 element in which it is declared looks like this:
<H1 style="color: blue">This is a major heading in    
												   blue.</H1>                                         
Style declaration: This permits you to use the full range of CSS, applying it throughout a single Web page, but it’s of limited utility when dealing with a large number of pages on a significant Web site. Such a declaration must occur within the HEAD element of the HTML document. A style declaration takes the form of:
<HEAD>                                               
												<STYLE>                                              
												H1                                                   
												{color:blue}                                         
												</STYLE>                                             
												</HEAD>                                              
After such a declaration, the text in all H1 elements on this Web page will be blue in color.
Separate .css file: This file is linked to the .html files on your Web site. With this approach, all the creative elements (color, font size, and the like) are specified in a different file (.css) from the ones that define the content of the Web pages on your site (.html). This has a tremendous advantage over either of the other two approaches: One .css file can control the appearance of multiple Web pages. Let’s say, for example, that you have a Web site with 87 pages. You ...

Get Building a Web Site For Dummies®, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.