5 kinds of CSS Writing comparison, this article lists the advantages and disadvantages of 5 methods, I hope to help.
First, use the Style property
Add the STYLE attribute directly to the individual component label,< component (label) style= "Property (property) 1: Set value 1; Property (Attribute) 2: Set value 2; ...}
For example:
The following is a code fragment: <TD style= "color: #c00; font-size:15px; Line-height:18px;> The 80 generation </td> |
The advantage of this method is that it can be used neatly in each label. Easy to use when writing code.
The disadvantage of this method: there is no "uniformity" of the whole document, it becomes more difficult to change a certain style.
Second, use the style label
Write style rules in <STYLE>...</STYLE> tags.
The following is a code fragment: <style type= "Text/css" > <!-- Style Rule table --> </STYLE> |
For example:
The following is a code fragment: <style type= "Text/css" > <!-- Body { Color: #666; Background: #f0f0f0; font-size:12px; } td,p { Color: #c00; font-size:12px; } --> </STYLE> |
Usually the entire <STYLE>...</STYLE> structure is written in the <HEAD> </HEAD> part of the Web page.
The advantage of this approach is that the entire article has a uniformity, as long as the declared component will apply the style rule.
The disadvantage of this method: the flexibility of individual components is insufficient, the function of the whole station is weak.
Third, use link tag
Write style rules in a. CSS style file and then introduce it in the <link> tab.
Suppose we save the style rule as a example.css file, we just add it to the page:
The following is a code fragment: <link rel=stylesheet type= "text/css" href= "Example.css" > |
After you introduce the CSS style sheet file, you can apply the styles that you have set in the style file directly. The link tag is usually written in the
The advantage of this method: You can apply the same style rules to the number of files are assigned to the same style file, you can make a unified change, but also easy to set the whole station has a unified style. This method is used for general CSS page layouts.
Disadvantages of this approach: insufficient flexibility in individual files or elements.
Iv. introduction of using @import
Similar to the link method, but must be placed in <STYLE>...</STYLE>:
The following is a code fragment: <style type= "Text/css" > <!-- @import URL (the address, path, and filename of the introduced style sheet); --> </STYLE> |
For example:
The following is a code fragment: <style type= "Text/css" > <!-- @import URL (css/example.css); --> </STYLE> |
Note that the semicolon at the end of the line is a must! Do not omit to write!
The advantage of this approach is that it is flexible to introduce CSS files to control XHTML elements. Sometimes it is also used to write some CSS hack.
Disadvantages of this approach: insufficient flexibility in individual files or elements.
V. Introduction of styles using <span></span> tags
For example:
The following is a code fragment: <span style= "font:12px/20px #000000;" > 80 </span> |
The advantage of this method is that it can be used neatly in each label. Easy to use when writing code.
The disadvantage of this method: there is no "uniformity" of the whole document, it becomes more difficult to change a certain style.