Using External Style Sheets


The third method of applying styles to a document involves linking to external style sheets. External style sheets are the most appropriate method for styling documents. If styles need to be changed, the modifications can take place in one CSS file rather than all HTML pages.

To change the header style to an external style, move the rule set to a new CSS file as shown in Listing 4.4.

Next, link to this style sheet from your HTML file using the link element as shown in Listing 4.5.

Listing 4.4. CSS Code Containing an External Style Sheet with Styles for the <p> Element
p {      font-family: arial, helvetica, sans-serif;      margin: 1em;      padding: 1em;      background-color: gray;      width: 10em; } 

Listing 4.5. HTML Code Containing the link Element
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"          "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head>     <meta http-equiv="content-type" content="text/html;     charset=utf-8">     <title>Lesson 4</title>     <link rel="stylesheet" href="style.css" type="text/css"     media="screen"> </head> <body> <p>     Lorem ipsum dolor sit amet, consectetuer adipiscing     elit... </p> </body> </html> 




Sams Teach Yourself CSS in 10 Minutes
Sams Teach Yourself CSS in 10 Minutes
ISBN: 0672327457
EAN: 2147483647
Year: 2005
Pages: 234
Authors: Russ Weakley

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net