Home  >  Article  >  Web Front-end  >  Summary of four methods to add CSS style sheets to web pages

Summary of four methods to add CSS style sheets to web pages

高洛峰
高洛峰Original
2017-03-10 10:10:583334browse

Summary of four methods for adding CSS style sheets to web pages. You can choose your favorite method according to your needs.

1. Use the STYLE attribute: Add the STYLE attribute directly to individual component tags.
5a7f8c23846edad51debc6cf4fde7168
The advantage of this usage is that the style can be flexibly applied to each label. But the disadvantage is that there is no "unity" in the entire document.

2. Use the STYLE tag: Write the style rules in the 812f7be0e9ba70c6f2a66273c3c04692...a2d87b9af1e305217ec9648d1e8a0a47 tag.

The code is as follows:

<STYLE TYPE="text/css"> 
<!-- 
样式规则表 
--> 
</STYLE> 
例如: 
<STYLE TYPE="text/css"> 
<!-- 
BODY { 
color: BLUE; 
background: #FFFFCC; 
font-size: 9pt} 
TD, P { 
COLOR: GREEN; 
font-size: 9pt} 
--> 
</STYLE>


Usually the entire 812f7be0e9ba70c6f2a66273c3c04692...a2d87b9af1e305217ec9648d1e8a0a47 structure is written in the e28b1a6b539b6aceb13ada9d9bcbd835 section. The advantage of this usage lies in the uniformity of the entire document. As long as there is a declared component, the style rule will be applied. The disadvantage is the lack of flexibility in individual components.

3. Use the LINK tag: Write the style rules in the .css style file, and then introduce it with the 3e76e57fc5dd9b761bdd2082385f4936 tag.
Suppose we save the style rules as an example.css file, we only need to add
83041f9ba485098ac35e9c4a11d887719c3bca370b5104690d9ef395f2c5f8d1 section of the web page. The advantage of this usage is that you can assign several documents to which the same style rules apply to the same style file. The disadvantage is also the lack of flexibility in individual files or components.


4. Use @import to introduce: It is very similar to LINK usage, but must be placed in 812f7be0e9ba70c6f2a66273c3c04692...a2d87b9af1e305217ec9648d1e8a0a47.

The code is as follows:

<STYLE TYPE="text/css"> 
<!-- 
@import url(引入的样式表的位址、路径与档名); 
--> 
</STYLE> 
例如: 
<STYLE TYPE="text/css"> 
<!-- 
@import url(http://yourweb/ example.css); 
--> 
</STYLE>


It should be noted that the semicolon at the end of the line is absolutely essential! In this way,
@import url(http://yourweb/ example.css);
can also be added to other styles to call.

The above is the detailed content of Summary of four methods to add CSS style sheets to web pages. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn