是否可以将id/类添加到标签?

时间:2022-11-25 20:14:52

Is it okay to do this?

这样可以吗?

<link rel="stylesheet" href="css/mobile/load.css" id="stylesheet_mobile" />

so I can use JavaScript to dynamically disable stylesheets?

所以我可以使用JavaScript动态禁用样式表?

4 个解决方案

#1


27  

According to HTML 4.01 Transitional, id, class are document-wide selectors, and thus it is ok to have them in the link element.

根据HTML 4.01 Transitional、id、类都是文档范围的选择器,因此可以将它们放在link元素中。

#2


5  

Yes, you can. The core attributes are allowed on the <link> element, which includes style, class, id, and title. Although, since it's not a rendered element, classes and styles won't have any effect.

是的,你可以。在 元素上允许使用核心属性,包括样式、类、id和标题。虽然,因为它不是呈现的元素,类和样式不会有任何影响。

<!ENTITY % coreattrs
 "id          ID             #IMPLIED  -- document-wide unique id --
  class       CDATA          #IMPLIED  -- space-separated list of classes --
  style       %StyleSheet;   #IMPLIED  -- associated style info --
  title       %Text;         #IMPLIED  -- advisory title --"
  >

#3


2  

Yes. There are certain attributes that may be specified on every html element. id and class are among them.

是的。在每个html元素上都可以指定某些属性。id和class是其中之一。

For a complete list in the html5 spec: http://developers.whatwg.org/elements.html#global-attributes

html5规范中的完整列表:http://developers.whatwg.org/elements.html#global-attributes

The spec for the link element: http://developers.whatwg.org/semantics.html#the-link-element

链接元素的规范:http://developers.whatwg.org/semantics.html# The -link元素

And in html4.1: http://www.w3.org/TR/html401/struct/links.html#h-12.3

在html4.1:http://www.w3.org/TR/html401/struct/links.html h - 12.3

#4


1  

Yup, it is. It is not recommended though, as this'd mean loading several files (multiple HTTP requests) as opposed to loading one bigger file (but one HTTP request only).

是的,它是。但不推荐这样做,因为这意味着要加载多个文件(多个HTTP请求),而不是加载一个更大的文件(只有一个HTTP请求)。

#1


27  

According to HTML 4.01 Transitional, id, class are document-wide selectors, and thus it is ok to have them in the link element.

根据HTML 4.01 Transitional、id、类都是文档范围的选择器,因此可以将它们放在link元素中。

#2


5  

Yes, you can. The core attributes are allowed on the <link> element, which includes style, class, id, and title. Although, since it's not a rendered element, classes and styles won't have any effect.

是的,你可以。在 元素上允许使用核心属性,包括样式、类、id和标题。虽然,因为它不是呈现的元素,类和样式不会有任何影响。

<!ENTITY % coreattrs
 "id          ID             #IMPLIED  -- document-wide unique id --
  class       CDATA          #IMPLIED  -- space-separated list of classes --
  style       %StyleSheet;   #IMPLIED  -- associated style info --
  title       %Text;         #IMPLIED  -- advisory title --"
  >

#3


2  

Yes. There are certain attributes that may be specified on every html element. id and class are among them.

是的。在每个html元素上都可以指定某些属性。id和class是其中之一。

For a complete list in the html5 spec: http://developers.whatwg.org/elements.html#global-attributes

html5规范中的完整列表:http://developers.whatwg.org/elements.html#global-attributes

The spec for the link element: http://developers.whatwg.org/semantics.html#the-link-element

链接元素的规范:http://developers.whatwg.org/semantics.html# The -link元素

And in html4.1: http://www.w3.org/TR/html401/struct/links.html#h-12.3

在html4.1:http://www.w3.org/TR/html401/struct/links.html h - 12.3

#4


1  

Yup, it is. It is not recommended though, as this'd mean loading several files (multiple HTTP requests) as opposed to loading one bigger file (but one HTTP request only).

是的,它是。但不推荐这样做,因为这意味着要加载多个文件(多个HTTP请求),而不是加载一个更大的文件(只有一个HTTP请求)。