如何为CSS定义一个好的约定?
我现在负责公司网站的 HTML 和 CSS 重构。正如我所看到的当前 CSS 代码,它遵循 ID 和类的命名约定(驼峰表示法)。但是,上周我向办公室里的每个人做了演示;然后,一个人表达了在包含多个单词的名称之间使用下划线或破折号的想法,因为他提到了 SEO 对页面的可访问性。在这种情况下,我不确定他的想法是否有用。有人对此有想法吗?
I am now in charge of refactoring HTML and CSS for the site of my company. As I have seen the current CSS code, it is following naming convention for IDs and Classes (camel Notation). But, last week I did the demo to everyone in the office; then one guy expressed an idea about using underscore or dash between the names that contain more than one word because he mentioned about the accessibility of SEO to the page. In this case, I don't know for sure if his idea is useful. Does anyone have idea around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
此人本人 (Eric Meyer) 多年前对它们的使用表示皱眉 。就我个人而言,我倾向于采用初始上限方法。我不明白这对可访问性有什么帮助。
我确信只要你保持一致(当然只要它是有效的),你的选择就没有什么区别。
The man himself (Eric Meyer) frowned upon their use years ago. Personally I'd favour a initial cap approach. I don't see how this could help accessibility.
I'm sure it makes little difference what you choose as long as you are consistent (as long as it is valid of course).
我更喜欢
全小写连字符分隔
方法。这与 CSS 属性 的命名方式一致:
font-size、border -top、vertical-align
等I prefer the
all-lowercase-hyphen-separated
approach.This is consistent with how CSS properties are named:
font-size, border-top, vertical-align
, etc.就我个人而言,我倾向于在开头使用小写字母,然后使用大写字母,例如 .userImage
我不记得何时采用这种方法或为什么!就像上面的 Richard 一样,我不明白 CSS id 和类的命名与可访问性有什么关系。
Personally I tend to use a small letter at the start and then capitals, e.g. .userImage
I can't remember when I adopted this approach or why though! Like Richard above, I don't see how the naming of CSS ids and classes has anything to do with accessibility.
好吧,当你看到有关 SEO 的所有炒作时,甚至类和 id 名称也算在 SEO 优化中,因此我选择连字符/下划线而不是驼峰式大小写
Well, when you see all the hype about SEO, even class and id names do count in the SEO optimization, therefore i choose hyphen/underscore over camel case
这是一个有趣的问题。
如果它有任何用处,似乎微格式建议使用
小写连字符方法
http://microformats.org/wiki/naming-principles-faq
this is an interesting issue.
is if it's of any use, seems that microformats suggests the
lowercase-hyphen approach
http://microformats.org/wiki/naming-principles-faq