用于ID,类和包含元素类型前缀的HTML命名约定? [英] HTML naming conventions for ID, class and to include element type prefix?

查看:174
本文介绍了用于ID,类和包含元素类型前缀的HTML命名约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道一个好的资源来解释HTML ID和类的良好的命名约定,以及是否使用元素类型,即btn或按钮或类似的前缀?

Does anyone know of a good resource to explain good naming conventions for HTML ID and classes and whether to prefix with IDs with an element type i.e. btn or button or similar?

应该是复数还是单数?我得到的ID应该是奇异的,因为他们是唯一的,但关于类?

Should classes be plural or singular? I get that IDs should be singular due to them being unique, but what about classes?

ID和类应该使用名词,对吗?

IDs and classes should use nouns, right?

我使用页面注入现有页面中的其他页面,类似部分页面...因此...我想知道是否有人在ID和/或类前面加上一个名称。类似命名空间或类似的?

I am using pages that inject other pages in the existing pages, kind of like partial pages ... hence... I was wondering if anybody as prefixed a name in front of IDs and/or classes .. kind of like a namespace or similar?

任何意见或见解都非常感激。

Any comments or insights really appreciated.

推荐答案

我不会在类型前缀,因为你可以推断这在选择器中如果你必须

I wouldn't prefix with the type, as you can infer this in the selector if you must

form#contact {
    property: value;

}

您所描述的方法称为匈牙利符号,isn非常受欢迎。

The method you described is known as Hungarian notation, and isn't very popular.

对于你提到的内容,你可以将注入的HTML放在一个div中,其中有一个唯一的类/ id,它有一个本地化的重置。查找CSS选择器特定性,以确保您的规则将影响主机页面的CSS中的其他规则,而不是其他规则。 请参阅类似的关于在父页面中设置元素样式的问题。

For what you mention, you could place your injected HTML inside one div with one unique class/id, which has a sort of localised reset. Look up CSS selector specificty to ensure your rules will take affect and not other rules in the host page's CSS. See this answer to a similar question regarding styling an element within a parent page.

这篇关于用于ID,类和包含元素类型前缀的HTML命名约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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