CSS Essentials(2)-How to use CSS,
2006-04-13 13:17
295 查看
1.How to Insert a Style Sheet
(1).External Style Sheet
An external style sheet can be written in any text editor. The file should not contain any html tags. Your style sheet should be saved with a .css extension. An example of a style sheet file is shown below:
hr {color: sienna}
p {margin-left: 20px}
body {background-image: url("images/back40.gif")}
**NOTE:Do NOT leave spaces between the property value and the units! If you use "margin-left: 20 px" instead of "margin-left: 20px" it will only work properly in IE6 but it will not work in Mozilla/Firefox or Netscape.
(2).Internal Style Sheet
hr {color: sienna}
p {margin-left: 20px}
body {background-image: url("images/back40.gif")}
**Note: A browser normally ignores unknown tags. This means that an old browser that does not support styles, will ignore the tag, but the content of the tag will be displayed on the page. It is possible to prevent an old browser from displaying the content by hiding it in the HTML comment element:
(3)Inline Styles
An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly, such as when a style is to be applied to a single occurrence of an element.
To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph:
This is a paragraph
(4)Multiple Style Sheets
If some properties have been set for the same selector in different style sheets, the values will be inherited from the more specific style sheet.
For example, an external style sheet has these properties for the h3 selector:
h3
{
color: red;
text-align: left;
font-size: 8pt
}
And an internal style sheet has these properties for the h3 selector:
h3
{
text-align: right;
font-size: 20pt
}
If the page with the internal style sheet also links to the external style sheet the properties for h3 will be:
color: red;
text-align: right;
font-size: 20pt
The color is inherited from the external style sheet and the text-alignment and the font-size is replaced by the internal style sheet.
(1).External Style Sheet
An external style sheet can be written in any text editor. The file should not contain any html tags. Your style sheet should be saved with a .css extension. An example of a style sheet file is shown below:
hr {color: sienna}
p {margin-left: 20px}
body {background-image: url("images/back40.gif")}
**NOTE:Do NOT leave spaces between the property value and the units! If you use "margin-left: 20 px" instead of "margin-left: 20px" it will only work properly in IE6 but it will not work in Mozilla/Firefox or Netscape.
(2).Internal Style Sheet
hr {color: sienna}
p {margin-left: 20px}
body {background-image: url("images/back40.gif")}
**Note: A browser normally ignores unknown tags. This means that an old browser that does not support styles, will ignore the tag, but the content of the tag will be displayed on the page. It is possible to prevent an old browser from displaying the content by hiding it in the HTML comment element:
(3)Inline Styles
An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly, such as when a style is to be applied to a single occurrence of an element.
To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph:
This is a paragraph
(4)Multiple Style Sheets
If some properties have been set for the same selector in different style sheets, the values will be inherited from the more specific style sheet.
For example, an external style sheet has these properties for the h3 selector:
h3
{
color: red;
text-align: left;
font-size: 8pt
}
And an internal style sheet has these properties for the h3 selector:
h3
{
text-align: right;
font-size: 20pt
}
If the page with the internal style sheet also links to the external style sheet the properties for h3 will be:
color: red;
text-align: right;
font-size: 20pt
The color is inherited from the external style sheet and the text-alignment and the font-size is replaced by the internal style sheet.
相关文章推荐
- How to use the new CSS syntax in Flex 4
- how to use perf
- IIS->Error Pages:How to Use Detailed Errors in IIS 7.0
- a demo for how to use QThread
- Learn How To Use Oracle Audit
- How to use JabRef (BibTeX) with Microsoft Word
- how to use cgroup
- How to use IMGDECMP.DLL in WindowsCE
- How to use Struts Framework
- How to use composition and inheritance in visual c# ?
- How to Use Cocoa Bindings and Core Data in a Mac App
- How to use WinSCP with public key authentication
- How to Use Custom TTF Font on iOS
- Responsive Web Design: What It Is and How To Use It
- How to use pop-up TextBox in Java ME
- How to Use MMC/SDC——翻译
- Kernel Korner - Why and How to Use Netlink Socket
- How to use user’s location in your app?
- How to include cascading style sheets (CSS) in JSF
- How to use isInEditMode() to see layout with custom View in the editor