Home  >  Article  >  Web Front-end  >  The difference between CSS link and @import_html/css_WEB-ITnose

The difference between CSS link and @import_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:41:111134browse

The difference between CSS link and @import:

Both tags and @import can introduce external style sheets. The functions look similar, but there is a difference between them. There are still many differences. Since tags are used frequently, I won’t introduce them here. Click on the usage of @import in CSS to learn about the usage of @import. Below is a brief introduction to the differences between them.

1. @import can introduce other style sheets in a style sheet. There are three style sheets in the same directory: main.css, one.css and two.css. In the main style sheet, you can Introduce one.css and two.css. The method is as follows:

@charset "utf-8";/* CSS Document */@import url("one.css");@import url("two.css");

But there is no such usage.

2. The difference when using DOM to control styles. When using JavaScript to control the dom to change the style, you can only use the link tag, because @import is not controllable by the dom.

3. Since @import is a concept that appeared in CSS2.1, it is invalid for older versions of browsers, while tags do not have this problem.

4. Differences in loading order. When a page is loaded (that is, when viewed by a viewer), the CSS referenced by link will be loaded at the same time, while the CSS referenced by @import will wait until the page is completely downloaded before being loaded. So sometimes when browsing the page where @import loads CSS, there will be no style at first.

Summary: From the above differences, we can see that we should try to use tags instead of @import.

The original address is: http://www.51texiao.cn/div_cssjiaocheng/2015/0503/584.html

The most original address is: http://www.softwhy.com/

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn