4 ways to introduce and prioritize CSS

Source: Internet
Author: User

First: 4 ways to introduce CSS

There are 4 ways to introduce CSS: inline, inline, link, import style

1. Inline style

The most straightforward and straightforward one, use style= "" directly on HTML tags, for example:

<p style= "color: #F00; "></p>

Disadvantages: HTML page is not pure, file size, not conducive to spider crawling, late maintenance inconvenient.

2. Inline style

The inline style is to write the CSS code between

<style type= "Text/css" >

body,div,a,img,p{margin:0; padding:0;}

</style>

Advantages and Disadvantages: the page using public CSS code, but also each page to be defined, if a site has a lot of pages, each file will become larger, later maintenance difficulty is also large, if the file is very small, CSS code is not much, this style is still very good.

3. Link Style

Link style is the most frequently used, the most practical style, only need to add <link.../> between

<link type= "Text/css" rel= "stylesheet" href= "Style.css"/>

Advantages and Disadvantages: the implementation of the page framework code and performance of the CSS code completely separated, making pre-production and post-maintenance is very convenient

4. Import style (not recommended)

Import style and link style are similar, import CSS style sheet with @import style, when HTML is initialized, it will be imported into HTML or CSS file, become part of the file, similar to the second kind of inline style.

@import used in HTML, as follows:

<style type= "Text/css" >
@import URL (style.css);
</style>

@import used in CSS, as follows:

@import URL (style.css);

Second: Four ways to prioritize CSS introduction

1. Principle of proximity

2. Theoretically: inline > Inline > Link > Import

3. Actually: embed, link, import in the same file header, who is close to the corresponding code, who has high priority

4 ways to introduce and prioritize CSS

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.