Attaching Style Sheets


Here it gets a little tricky. The style tag doesn't have a src attribute, so you can't use the style tag to attach an external style sheet. Instead, use the link tag:

 <html>   <head>     <title>Page Title</title>     <link href="css/mystyles.css" rel="stylesheet" type="text/css">   </head>   <body>     <!-- The content of the page goes here. -->   </body> </html> 

TIP

Another alternative is to import the external style sheet. See Topic 42 for details.


You'll note a couple things about the link tag here. It doesn't have an src attribute, either, but it does have an href attribute, which works exactly the same way. The path from the current page to the external style sheet goes in there. The rel attribute describes the relation of the linked document, and the type attribute tells what kind of style sheet the linked document is. The last two attributes aren't mission critical, in that all you really need is the href attribute to attach the style sheet, but they can be useful to the software or hardware that reads the Web page, so you should try to include them.

TIP

The link tag must always appear in the head section of the HTML document. You can't put it anywhere else.


Another thing about the link tag is that it doesn't require a closing version of itself, </link>. The link tag is self-contained, while the script tag isn't. That means, when you open a script tag, always try to close it, even if you don't have any embedded JavaScript between the tags. But with a link tag, you don't have to go to the trouble.



Web Design Garage
Web Design Garage
ISBN: 0131481991
EAN: 2147483647
Year: 2006
Pages: 202
Authors: Marc Campbell

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