使用没有相应的CSS规则的CLASS属性是不好的形式吗? [英] Is it poor form to use CLASS attributes with no corresponding CSS rule?

查看:255
本文介绍了使用没有相应的CSS规则的CLASS属性是不好的形式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我想使用jQuery选择一些特定类的元素,并且仅仅因为这个原因,是否总是期望那些类应该在css中定义。

For example if I wanted to select some elements with a certain class using jQuery, and for that reason only, is it always expected that those classes SHOULD be defined in the css?.

<div class="xyz">
something
</div>

<div class="xyz">
something else
</div>

//with example jQuery
$(".xyz").hide();

//is it wrong no element 'xyz' is defined in css?


推荐答案

使用CSS类和 - (unique !!)是完全正常的,通常是保持您的HTML代码有效,同时给予脚本使用的其他属性的唯一解决方案。

Using CSS classes and - depending on the case - IDs (unique!!) is perfectly fine and often the only solution to keep your HTML code valid while giving additional attributes used by scripts.

使用非标准属性通常工作也很好,它会阻止你的html代码验证,并可能会导致未来的问题。

While using non-standard attributes often works fine, too, it will prevent your html code from validating and might cause issues in the future.

然而,在某些情况下,可能会有attriutes可以使用 - 例如通常用于修改链接行为的脚本的链接上的 rel

However, for some cases there might be attriutes which can be used, too - like rel on links which is often used for scripts which modify link behaviour.

http://www.w3.org/TR/html401/struct/global。 html#h-7.5.2 也提到类是通用的:


类属性, b $ b hand,为一个元素赋予一个或多个类名
;该元素可以说是
属于这些类。类
名称可以由多个元素
实例共享。类属性在HTML中有
个几个角色:

The class attribute, on the other hand, assigns one or more class names to an element; the element may be said to belong to these classes. A class name may be shared by several element instances. The class attribute has several roles in HTML:


  • 作为样式表选择器(当作者希望将样式信息一组元素)。

  • 用于用户代理的一般用途处理。

这篇关于使用没有相应的CSS规则的CLASS属性是不好的形式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆