简体   繁体   English

此HTML代码是什么意思?

[英]What this HTML code means?

I've viewed in some source code and found something like this: 我查看了一些源代码,发现了以下内容:

<div class="classname {height: 300px; width: 200px}"></div>

I know that element styling is available by using the style="" attribute. 我知道可以使用style=""属性来提供元素样式。

Can you please tell me what this code means? 您能告诉我这段代码是什么意思吗?

It means nothing per se in the HTML specification. 在HTML规范中,它本身没有任何意义。 The website you were looking at was probably using some javascript code which interprets this class attribute and performs some actions based on the values it has parsed. 你在看该网站很可能使用一些JavaScript代码解释这个class属性和执行基于它已解析的值的一些行动。 Without javascript this does nothing. 没有javascript,它什么也不做。 In HTML the class attribute is used to specify a CSS classname to be associated to this element. 在HTML中, class属性用于指定要与此元素关联的CSS类名。

For example the jQuery.validate plugin uses similar technique allowing you to specify inline validation rules. 例如, jQuery.validate插件使用类似的技术,允许您指定内联验证规则。 Actually the plugin uses data-* attributes instead of class which is semantically more correct for those kind of tasks. 实际上,该插件使用data-*属性而不是class ,这在语义上对于此类任务更正确。

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

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