Difference between link and @import

Application scenarios:

<head>
    <!-- link是标签,引入外部样式表 -->
    <link rel="stylesheet" href="./a.css">
    <style>
        /* @import 在css环境中 导入外部css */
        @import url('./b.css');
        .box{
    
    
          width: 100px;
          height: 100px;
          background: green;
        }
    </style>
</head>

the difference:

  1. link belongs to html tag. @import is used in css to import external style sheets;
  2. When the page is loaded, the link will be loaded at the same time, and the CSS referenced by @import will wait until the page is loaded before loading;
  3. Import can only be recognized above IE5, and link is an HTML tag, so there is no compatibility problem;
  4. The weight of link style style is higher than that of @import;
  5. link supports the use of javascript to change the style ( document.styleSheets), the latter is not

Guess you like

Origin blog.csdn.net/weixin_43638968/article/details/109175553