简体   繁体   English

为什么我们必须为 css 文件使用“link”标签

[英]why do we have to use “link” tag for css files

Why this is not allowed:为什么不允许这样做:

<style src="someCssFile.css"></style>

whereas this is allowed:而这是允许的:

<script src="someJsFile.js"></script>

I don't understand why i have to use link tag for css files.我不明白为什么我必须为 css 文件使用链接标签。 I think it would make more sense to use style tag.我认为使用样式标签更有意义。

Do you know when all these tags introduced in HTML?你知道所有这些标签是什么时候在 HTML 中引入的吗? There is a reason why the <LINK> tag is used instead of the <style> tag.使用<LINK>标签而不是<style>标签是有原因的。

It makes the most sense for individuals using HTML who want to see where HTML has been and where it is going.对于希望查看 HTML 已经到过的地方以及它的去向的使用 HTML 的个人来说,这是最有意义的。


HTML1.0 HTML1.0

  • HTML1.0 was the earliest version of HTML, used from 1989 to 1994. It was a very limited version and only contained 20 elements. HTML1.0 是最早的 HTML 版本,从 1989 年到 1994 年使用。这是一个非常有限的版本,只包含 20 个元素。 But there was no link or style tag in the 20 elements.但是这 20 个元素中没有链接或样式标签。

HTML2.0 HTML2.0

  • This version was created in 1995, with significant improvements to HTML1.0.该版本创建于 1995 年,对 HTML1.0 进行了重大改进。 A <link> tag was added to this version.一个<link>标签被添加到这个版本。 The <LINK> tag is presented as a general purpose link to other documents. <LINK>标签作为指向其他文档的通用链接呈现。 Styling sheets are indicated as a possibility.样式表被指示为一种可能性。
<link rel="stylesheet" href="styles.css">

HTML3.2 HTML3.2

  • The HTML3.2 version was endorsed by the W3 consortium in January 1997 and was approved by many, including notable browsers such as Netscape and Microsoft. HTML3.2 版本于 1997 年 1 月得到 W3 联盟的认可,并得到了许多人的认可,包括著名的浏览器,如 Netscape 和 Microsoft。 And this version included a style and script tag.这个版本包括一个样式和脚本标签。 <style> tag "Reserved for future use with internal style sheet." <style>标记“保留供将来与内部样式表一起使用。”
<style type="text/css"> </style>

So the <link> tag is already used to include the external style in the page.所以<link>标签已经用于在页面中包含外部样式。 The <style> tag was introduced after the <link> tag, but it is not used to include external style. <style>标签是在<link>标签之后引入的,但它不用于包含外部样式。

Because there was already a <link> tag to include the external style and HTML has never devalued a single tag.因为已经有一个<link>标签来包含外部样式,而 HTML 从来没有贬低过一个标签。 Sources used: Link使用的来源: 链接

The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web.万维网联盟 (W3C) 是万维网的主要国际标准组织。 This may help to understand why we use the tags we do.这可能有助于理解我们为什么使用我们所做的标签。

About Styles https://www.w3.org/Style/关于样式https://www.w3.org/Style/

About Scripts https://www.w3.org/TR/2011/WD-html5-author-20110705/the-script-element.html关于脚本https://www.w3.org/TR/2011/WD-html5-author-20110705/the-script-element.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM