[html] 第1天 页面导入样式时,使用link和@import有什么区别? #1
Comments
|
没留意这个区别啊。.... 尴尬的很 |
|
1)从属关系的区别:link属于XHTML标签,而@import是CSS提供的语法规则,link除了加载CSS,还可以定义RSS,定义rel连接属性等,@import就只能加载CSS。 |
呵呵,查漏补缺的时候到了 |
|
发现之前也思考过这个问题,今天复习了一下。 先回答区别,再扩展一下。
在html设计制作中,css有四种引入方式。 方式一: 内联样式内联样式,也叫行内样式,指的是直接在 HTML 标签中的 style 属性中添加 CSS。 <div style="display: none;background:red"></div>这通常是个很糟糕的书写方式,它只能改变当前标签的样式,如果想要多个 方式二: 嵌入样式嵌入方式指的是在 HTML 头部中的 <head>
<style>
.content {
background: red;
}
</style>
</head>嵌入方式的 CSS 只对当前的网页有效。因为 CSS 代码是在 HTML 文件中,所以会使得代码比较集中,当我们写模板网页时这通常比较有利。因为查看模板代码的人可以一目了然地查看 HTML 结构和 CSS 样式。因为嵌入的 CSS 只对当前页面有效,所以当多个页面需要引入相同的 CSS 代码时,这样写会导致代码冗余,也不利于维护。 方式三:链接样式链接方式指的是使用 HTML 头部的 标签引入外部的 CSS 文件。 <head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>这是最常见的也是最推荐的引入 CSS 的方式。使用这种方式,所有的 CSS 代码只存在于单独的 CSS 文件中,所以具有良好的可维护性。并且所有的 CSS 代码只存在于 CSS 文件中,CSS 文件会在第一次加载时引入,以后切换页面时只需加载 HTML 文件即可。 方式四:导入样式导入方式指的是使用 CSS 规则引入外部 CSS 文件。 <style>
@import url(style.css);
</style>或者写在css样式中 @charset "utf-8";
@import url(style.css);
*{ margin:0; padding:0;}
.notice-link a{ color:#999;} |
|
看上面总结的就不多说了,就补充一点@import这个使用的方法,它必须得在<style></style>中使用 <style> @import url(css/style.css); </style> |
可以在css文件中引入使用的 |
|
link以外联形式引入css,同步有阻塞@import属于新特性,异步. |
|
html中link和@import的区别 link是一个html标签,import是css语法 查询相关资料补充即修改: 加载顺序: link加载文档会被加载,import是等文档加载完毕之后,执行css的时候才会执行import 借鉴了大家的思想 |
|
link当页面被加载后(尚未解析) 就开始加载link对应的资源 |
|
|
|
1.link是html标签,除了家在css文件外,还可以加载RSS其他事务,加载模版等常用的属性有rel和href |
|
|
|
这个还能有这么多区别,还真没注意到,尴尬 |
|
真的是学到了 大佬 |
|
作为一个后端 强达一波 link可以用js控制 而import不可以 |
|
A: Difference 1: link is XHTML tag, in addition to loading CSS, can also be used to define RSS, define rel connection attributes, etc. @import is provided by CSS and can only be used to load CSS. Difference 2: when link references CSS, the page is loaded at the same time; @import requires the page to be fully loaded and later loaded. Difference 3: link is XHTML tag, no compatibility problem; @import was introduced in CSS2.1 and is not supported by browsers with lower versions (IE5 and below). Difference 4: link supports using Javascript to control the DOM to change styles; @import is not supported. 2: Essentially, both of these are for loading CSS files, but there are subtle differences The difference between ancestors. Link belongs to the XHTML tag, and @import is entirely a way of providing CSS. Link tags can do a lot of other things besides loading CSS, such as defining RSS, defining rel connection properties, etc. @import can only load CSS.
3 compatibility differences. Since @import is proposed by CSS2.1, old browsers do not support it. Only those above IE5 can recognize @import, while the link tag does not have this problem. 4 use dom to control style differences. When using javascript to control the dom to change the style, you can only use the link tag, because @import is not something that the dom can control. |
这一条如何验证,或者有参考文章么。 |
|
(1)从属关系区别。 @import 是 CSS 提供的语法规则,只有导入样式表的作用;link 是 HTML 提供的标签,不仅可以加载 CSS 文件,还可以定义 RSS、rel 连接属性、引入网站图标等。 |
|
别的不说了: |
笔记/?p=753补充:一个 at-rule 是一个CSS 语句,以at符号开头, ‘@‘ (U+0040 COMMERCIAL AT), 后跟一个标识符,并包括直到下一个分号的所有内容, ‘;‘ (U+003B SEMICOLON), 或下一个CSS块,以先到者为准。 |
|
1 |
|
1,优先级不同,link高于@Important |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

[html] 第1天 页面导入样式时,使用link和@import有什么区别?
The text was updated successfully, but these errors were encountered: