Difference in the usage of css file introduced by link and @ import in css

Source: Internet
Author: User
Tags website server

1. Two methods for referencing external CSS in a webpage

There are two ways to reference external CSS files on a webpage: link and @ import. The two methods are the same on the page.
Link reference is as follows:
<Link href = "styles.css" type = "text/css"/> The @ import reference method is as follows:
<Style type = "text/css"> @ import url ("styles.css"); </style>
2 Difference

2.1 different applicability
@ Import can be used on webpages or css files to introduce multiple css files to one css file; link can only introduce css files to webpages.
   
2.2 Different functions
Link is an XHTML label, while @ import is a method provided by CSS. In addition to loading CSS, link labels can also define RSS and rel connection attributes, @ import can only load CSS.

2.3 different loading sequence
When a page is loaded, the CSS referenced by link is loaded at the same time, and the CSS referenced by @ import is loaded after the page is downloaded. So sometimes when you browse the page where @ import loads CSS, there will be no style (that is, flashing) at the beginning, and the speed is quite slow.

2.4 Compatibility
Because @ import is proposed by css2.1, it is not supported by the old browser. @ import can be identified only when it is later than IE5, but the link label does not have this problem.

2.5 Differences in style control
The link method allows users to switch CSS styles. modern browsers such as Firefox, Opera, and Safari support the rel = "alternate stylesheet" attribute (you can select different styles on the browser ), of course, you can also use Javascript to enable IE to change the style.

Of course, if you write styles directly on a webpage, the HTTP requests generated by the website server will be reduced to avoid loading slow problems, but the maintenance volume will increase.

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.