CSS basics: What is the difference between @ import and link?

Source: Internet
Author: User
Author: webpage tutorial network source: Tianji net responsibility Editor: Sheng Xiaoying



There are two methods to reference external CSS in a webpage: @ import and link. It is often said that it is better to use link to introduce CSS. This article will briefly explain the differences.

  Link:Link is used to connect external CSS with webpages.

  @ Import:The difference between the import text and link text is that it can introduce several other CSS files into a CSS file.

  

Why use @ import?

Most people use the @ import method because the old browser does not support the @ import method. This means that we can use @ import to introduce CSS styles that are only parsed by modern browsers.

Another major reason is when several external CSS files need to be introduced to your webpage. you can use link to introduce a CSS file, and then use @ import to introduce several other CSS files. this seems easier to manage.

Why link?

One of the main reasons for using link is that you can allow users to switch CSS styles. modern browsers such as Firefox, opera, and Safari support
Rel = "Alternate
Stylesheet "attribute (you can select different styles in the browser). Of course, you can also use JavaScript to enable IE to support style change.

@ Import

If the head Tab Of Your webpage is very simple and only has the @ import attribute, when the user's network speed is slow, he will see a page with no style, after the CSS file is downloaded, you can see its style. to avoid this problem, make sure that there is at least one script or link tag in the head.

04-11 update: @ import will extend the overall loading time of CSS. in ie, the file download order will be changed. For example, the script file placed after @ import will be downloaded before CSS.

Which method should I use:

At present, it seems that it is more appropriate for small websites to use link (or more popular). Of course, if we need to modularize CSS management in the future, we must also use @ import.

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.