Internal Style Sheets
Internal style sheets are to be used when a single document has a unique style. The internal styles are defined in the head section with the <style> tag (the style tag is explained in the last part of this section).
Example: |
|
<head> |
<style type=”text/css”> |
body {background-color: red} |
p {font-family : "courier new", courier} |
</style> |
</head> |
| |
Inline Styles
An inline style is used when a unique style is to be applied to a single occurrence of an element. To use the inline tag the <style> tag is used in the relevant tag. The style tag can contain any style sheet property. The following example shows how to change the color and left margin of a paragraph.
Example: |
|
<p style=”color: red; margin-left: 20px” > |
This is my jokes site. |
</p> |
| |
Note:
In an HTML element, if all three style sheets are used then the order of preference is as follows: Firstly, inline style sheet will be used; secondly, internal style sheet; and lastly, external style sheet will be used. If style for an HTML tag has been defined in all the style sheets, then only the style of inline style sheet will be used. |
Some tags associated with style sheets:
Link Tag
The link tag defines the relationship between two linked documents. This tag lets a style sheet to be linked to an HTML document.
Attributes of Link Tag
Href
In this attribute, the target URL of the resource has to be given. It means that the URL of the document has to be given; which is to be linked with the HTML document.
Type
Type defines the content type of the link tag. It takes up the value text/css. These two values are given together and separated by a slash (/). It means that either of these two values could be used.
Example: |
|
<head> |
<link href=”mystyle.css” type=”text/css” /> |
</head> |
| |
Rel
Rel defines the relationship between the current document and the targeted document. In this the value of rel should be given as stylesheet.
Example: |
|
<head> |
<link rel=”stylesheet” href=”mystyle.css” type=”text/css” /> |
</head> |
| |
Style Tag
The style tag defines a style in a document. The style tag is placed in the head section of an HTML document for an internal style sheet. The style element is also used with the HTML tag and it is placed inside that tag for inline style sheets.
For internal style sheets it is used as:
Example: |
|
<head> |
<style type=”text/css”> |
body {background-color: red} |
p {font-family : "courier new", courier} |
</style> |
</head> |
| |
For inline style sheets it is used as:
Example: |
|
<p style=”color: red; margin-left: 20px” > |
This is my jokes site. |
</p> |
| |
Attributes of Style Tag
Type
Type defines the content type of the style tag. It takes up the value text/css. These two values are given together and separated by a slash (/). It means that either of these two values could be used.
Example: |
|
<head> |
<style type=”text/css”> |
body {background-color: red} |
p {font-family : "courier new", courier} |
</style> |
</head> |
| |
|