Several ways and differences of CSS introduced in HTML page

Source: Internet
Author: User

1. Use the Style property of the HTML tag

such as: <p style= "FONT-SIZE:12PX; Color:blue ">

The advantages of this approach: decentralized and flexible and convenient;

Shortcomings: lack of integrity and planning, not conducive to maintenance, high maintenance costs;

CSS rendering in this way has a higher priority than the other three types.

2. Write the style code in the <style></style> tab

Always place style tags in html files

such as:

Advantages of this approach: CSS code within a single page is unified and programmatic, and is easy to maintain.

Cons: CSS reuse between multiple pages is still not enough.

3. Use the <link> tag to introduce an external CSS file

<link rel= ' stylesheet ' type= ' text/css ' href = '/css/base.css ' >

External CSS file: base.css:

p {color: #000}

...

The advantages of this approach: a page can introduce multiple external CSS files, easy to reuse CSS code, easy to maintain;

The current application is long.

Cons: Centralized code, easy to confuse.


4. Using @import to introduce CSS files

This method can be used in both <style> tags and in external CSS files, such as:

@import url ('/css/list.css ')

Features: easy to introduce, but may be poor performance


Use link tags and @import differences:

1. Different categories: Link is an HTML tag, in addition to loading CSS, you can also define other such as RSS transactions, @import belong to the CSS category, can only load CSS;

2. Loading order is different: When link is introduced into CSS, it is loaded at the same time when the page is loaded, and @import needs the page to load completely.

3. Compatibility difference: Link is XHTML label, so there is no compatibility problem, and @import is CSS2.1 (IE5 above to recognize), so the low version of the browser is incompatible;

4. Support JS DOM change: Link supports using JavaScript to control DOM changes CSS style, @import not supported;

5. Different weights: Link style weights are higher than the weights of the @import style.





Several ways and differences of CSS introduced in HTML page

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.