Home  >  Article  >  Web Front-end  >  What is the difference between link and import in css

What is the difference between link and import in css

青灯夜游
青灯夜游Original
2021-03-31 11:26:276222browse

Difference: 1. Link is an HTML tag. In addition to loading CSS, it can also define other transactions such as RSS; @import belongs to the CSS category and can only load CSS. 2. When link refers to CSS, it is loaded at the same time when the page is loaded; @import requires the page to be loaded after the page is completely loaded. 3. The link has no compatibility issues.

What is the difference between link and import in css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

There are three main ways to use CSS in the page: adding and defining style attribute values ​​​​inline, inline calls in the page header and external link calls. There are two types of external references: link and @import. The two ways of externally referencing CSS, link and @import, are:

link code

<link rel="stylesheet" rev="stylesheet" href="CSS文件" type="text/css" media="all" />

@import code

<style type="text/css" media="screen">  
@import url("CSS文件");   
</style>

Both are ways of externally referencing CSS. But there are certain differences:

  • Difference 1: link is an HTML tag. In addition to loading CSS, it can also define other transactions such as RSS; @import belongs to the CSS category and can only load CSS.

  • Difference 2: When the link references CSS, it is loaded at the same time when the page is loaded; @import requires the page to be fully loaded before loading.

  • Difference 3: link is an HTML tag and has no compatibility issues; @import was proposed in CSS2.1 and is not supported by lower version browsers.

  • Difference 4: link supports using Javascript to control the DOM to change the style; while @import does not support it.

Recommended tutorial: CSS video tutorial

The above is the detailed content of What is the difference between link and import in css. For more information, please follow other related articles on the PHP Chinese website!

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