|
Search This Site
|
The Types of Stylesheets in CSS
The three ways are In-line, Internal and External. Whats the Difference ?In-line Style SheetsAn In-line style sheet is applied to tags. So long as the tag is open, the style specified is applied. As an example say we have an opened paragraph tag and want the text in that paragraph to be bold. As long as that paragraph tag is kept open
then the style will be apply. If the paragraph tag is closed and another paragraph is opened the style no longer applies. It is done like this:
<p style="font-weight: bold;"> This is an example of an in-line style sheet. </p>
As you can see the keyword style is used and the property to be styled ( font-weight ) is specified. The value given is bold and so the text between the tags will be bold.
<p style="font-weight: bold; color: purple;"> This is an example of an in-line style
sheet.</p>
Internal Style SheetsAn Internal style sheet is used when a style is to be applied to a specific ( only one ) page. Internal style sheets are most commonly associated with a web page which is to be styled differenly from other pages.
In creating an internal style sheet the selectors, their properties and values are applied within a style tag.
This tag must be placed between the opening and closing head tags of your html document. It is done like this:
<head> <--------- Opening head tag <style type="text/css"> <------- Opening style sheet tag p { color: blue; } <------- selector, property and value </style> <------- Closing style sheet tag </head> <--------- Closing head tag
External Style SheetsAn external style sheet is one where the formatting to be applied is specified external to the document itself. This is the most widely used style sheet format and will be the center of focus throughout the tutorials. All external style sheets must be saved with the extension .css for it to be recognised. After this is done, you have to provide a link in the head section of your html document. As an example, lets create an external
style sheet, style.css and then create a HTML web page to reference it. style.css
p
{
font-weight: bold;
}
h4
{
text-decoration: underline;
}
Now copy the code below into a next text document and save it as an HTML file as you were taught in the HTML tutorials. It is important
that you save both files ( css and html ) in the same folder. This will allow you to easily access and link to them. webpage.html
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title> My First CSS Example </title>
</head>
<body>
<h4> Paragraph </h4>
<p> This is my first paragraph of text. This text should be bold. </p>
</body>
</html>
Open your HTML document in your web browser. You should see that the level 4 heading is underlined and the paragraph of text is bold. Pretty cool right ?
Previous Lesson - Syntax of CSS
Next Lesson - ID & Class
|
|
© Copyright 2010 | All Rights Reserved
|