Five ways to introduce CSS styles into a Web page XHTML file

Source: Internet
Author: User
Tags advantage
css|xhtml| Web page

XHTML files are controlled by a CSS style display that combines XHTML and CSS to represent the content of the page. So what are the ways to introduce CSS styles into XHTML files?

  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:

<TD style= "color: #c00; font-size:15px; Line-height:18px;>
Web webjx.com-provides the latest and fastest web technology
</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.


<style type= "Text/css" >
<!--
Style Rule table
-->
</STYLE>

For example:

<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:

<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>:

<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 (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:

<span style= "font:12px/20px #000000;" > Web Teaching Network webjx.com-provides the latest and fastest web technology </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.



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.