CSS Application Basics Tutorial (2) How to apply

Source: Internet
Author: User
Tags advantage
css| Basic Tutorials
The way C S is declared
This chapter will begin to introduce you to the application of CSS. Of course, the first thing to introduce is how to build a stylesheet (style Sheets), including the way you declare it and how you apply it on a Web page, and then give you an overview of some of the CSS features. In summary, there are three ways to declare a CSS:

One, a basic declaration: the most typical form of CSS declaration. element {Property:value} is expressed in Chinese, that is, the
symbol (label) {Property (property) Name: Set Value}
For example: H3 {Color:blue} is a set of declarations.
Second, collective declaration: A group or array style rule (the nature) that declares one or more components (labels) (tags) separated by commas (separated by semicolons). Symbol (label) {
Property (property) Name 1: Set value 1;
Property (attribute) Name 2: Set value 2;
...}
or
Symbol a (label a), component B (label B), component C (label C), ... {
Property (attribute) Name 1: Set value 1;
Property (property) Name 2: Set value 2;
...}
For example: TD {
Color:blue;
font-size:9pt;
}
or
Td,p,div {
Color:blue;
font-size:9pt;
}
Three-item declaration: Group many style rules and declare them separately. Component A (label a) {property (attribute) Name 1: Set value 1; property (attribute) Name 2: Set value 2;}
Symbol A (label a) {Property (property) Name 3: Set value 3; Property (property) Name 4: Set value 4;}
For example: td {Color:blue FONT-SIZE:9PT}
td {Font-family: "superscript italics"; line-height:150%} Such declarations do not contradict each other because the nature of the declaration is different. If you accidentally make a duplicate declaration of the same nature, only the set value that is later declared will work.
to be incidentally, in your statement, as long as your format is correct, you will be accepted, regardless of whether the case, blank or line wrap will not affect the results of the display, you can write in your own custom.
The application method of C s S

Next, we'll introduce you to the four basic methods of applying the style sheet you created to your Web page.

First, use the style attribute: Add the style attribute directly to the individual component labels. < component (label) style= "Property (property) 1: Set value 1; Property (Attribute) 2: Set value 2; ...}
For example: <td style= "Color:blue; font-size:9pt; font-family: "Superscript italics"; Line-height:150%> The advantage of this usage is that it can be used neatly in each label, but the disadvantage is that there is no "uniformity" of the entire document.
Second, use style tags: write style rules in <STYLE>...</STYLE> tags. <style type= "Text/css" >
<!--
Style Rule table
-->
</STYLE>
For example: <style type= "Text/css" >
<!--
Body {
Color:blue;
Background: #FFFFCC;
FONT-SIZE:9PT}
TD, P {
Color:green;
FONT-SIZE:9PT}
-->
</STYLE> usually writes the entire <STYLE>...</STYLE> structure in the <HEAD> </HEAD> part of the Web page. The advantage of this usage is the uniformity of the entire document, as long as the declared component will apply the style rule. The disadvantage is that the flexibility of individual components is insufficient.
Use the LINK tag: Write style rules in the. CSS style file, then introduce the <LINK> tag. Let's say we put the style rules into a example.css file and we just add them to the page.
The <link rel=stylesheet type= "text/css" href= "Example.css" > can be applied to the style file as set out in the good style. The link tag is usually written in the <HEAD> </HEAD> section of the Web page. The advantage of this usage is that you can assign several files of the same style rule to the same style file. Disadvantages are also insufficient flexibility in individual files or components.
Use @import Introduction: Similar to link usage, but must be placed in <STYLE>...</STYLE>. <style type= "Text/css" >
<!--
@import URL (the address, path, and filename of the introduced style sheet);
-->
</STYLE>
For example: <style type= "Text/css" >
<!--
@import URL (http://yourweb/example.css);
-->
</STYLE> Note that the semicolon at the end of the line is absolutely indispensable! Remember, remember!
Obviously, both link and @import may be able to apply directly to other people's existing style sheets. However, based on the Internet etiquette, this kind of thing do not do well, at least should also know each other's voice, must first obtain the consent of others!

And the four application methods have their own advantages and disadvantages, you can use synthetically, and will not contradict each other. However, if the same nature of the property in the case of repeated statements, it is necessary to consider the problem of applying precedence! Generally speaking, the order of priority has the following principles: Web Designer's style setting > user's style setting > browser style setting
Style property's styling > Style label Style Set > link in the style set
The styling of the rear declaration style is set in front of the style

The so-called "link in the style set" refers to the above mentioned link tag and @import introduced in the two application methods linked to the style of the set.

The above is the most basic CSS declaration and application of the method introduction, with these basic knowledge and methods, you can start to build your style sheet! In addition to the basic declarations and application methods mentioned above, there are other methods of declaration and application that will be introduced in the next chapter.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.