Difference between css link and @ import, csslink @ import

Source: Internet
Author: User

Difference between css link and @ import, csslink @ import

There are three main methods to use CSS in the page: 1. Add the defined style attribute value in the row. 2. embedded call in the page header. 3. Call the external link.

There are two types of external references: link and @ import.

XML/HTML code

<Link href = "stylesheet" href = "CSS file" type = "text/css"/>

XML/HTML code

<Style type = "text/css"> @ import url ("CSS file") </style>

Both are external reference CSS methods, but there are some differences:

Difference 1: link is an XHTML tag. In addition to loading CSS, it can also define RSS and other transactions. @ import is within the CSS category and can only load CSS.

Difference 2: When link References CSS, it is loaded at the same time when the page is loaded; @ import requires that the page be loaded after the page is fully loaded.

Difference 3: link is an XHTML tag with no compatibility issues. @ import was proposed in CSS2.1, and earlier versions of browsers are not supported.

Difference 4: link supports using Javascript to control DOM to change styles, while @ import does not.

Difference 5: The link style has a higher weight than @ import.

 

Supplement: @ import optimal syntax
@ Import is generally written in the following ways:

@ Import 'style.css '// Windows IE4/NS4, Mac OS X IE5, Macintosh IE4/IE5/NS4 not recognized
@ Import "style.css" // Windows IE4/NS4, which is not recognized by Macintosh IE4/NS4
@ Import url(style.css) // Windows NS4, which is not recognized by Macintosh NS4
@ Import url('style.css ') // Windows NS4, Mac OS X IE5, Macintosh IE4/IE5/NS4 not recognized
@ Import url ("style.css") // Windows NS4, which is not recognized by Macintosh NS4
According to the analysis above, @ import url(style.css) and @ import url ("style.css") are the best choices, with the most compatible browsers. From the perspective of byte optimization, @ import url(style.css) is the most recommended.

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.