Why is “lower-case with dashes” the standard for HTML classes? [duplicate]

拥有回忆 提交于 2019-12-07 14:37:24

问题


Possible Duplicate:
Why are dashes preferred for CSS selectors / HTML attributes?

Personally I use "lower-case with dashes" to format my HTML classes, which seems to be the standard these days. Using something like camel case seems more reserved for JavaScript in my eyes, but I realise that's just my opinion.

I'm trying to improve front-end code consistency at my workplace and part of that will be coding guidelines. Rather than just saying "we should do it this way" I'm keen to hear some valid reasons behind this common trend.

So the question in summary, what are some valid technical reasons for the "lower-case with dashes" trend for HTML classes?


回答1:


Just like you mentioned in your own question but I realise that's just my opinion.

Coding-conventions are:

  • guidelines for making code more readable (amount of spaces for identation, naming of variables, ..)
  • in no way a limit in your coding
  • different for every language

In short, it's only a proposed way of coding which you don't need to follow but it's more readable for other people if you do.

If you come across one set of conventions, it means a lot of people agree with that set and adopt it for themselves (with or without some modifications =) )

Some languages restrict conventions a bit (like class names having to start with an uppercase letter, ..), that's why it's different for every language.




回答2:


There are none. It's an acceptable naming convention, to help the author from confusing between his different languages. You can name your class names in any way you'd like.




回答3:


Coding Conventions are just that: conventions.

What is a convention? It's some rule how to do things?

Why is it like that? Because someone said so.



来源:https://stackoverflow.com/questions/9735650/why-is-lower-case-with-dashes-the-standard-for-html-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!