为什么是“带破折号的小写"?HTML 类的标准? [英] Why is "lower-case with dashes" the standard for HTML classes?

查看:53
本文介绍了为什么是“带破折号的小写"?HTML 类的标准?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
为什么 CSS 选择器/HTML 属性首选破折号?

我个人使用带破折号的小写"来格式化我的 HTML 类,这似乎是当今的标准.使用像 camel case 之类的东西在我看来更适合 JavaScript,但我意识到这只是我的意见.

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.

总结一下问题,HTML 类的带破折号的小写"趋势有哪些有效的技术原因?

推荐答案

就像你在自己的问题中提到的但我意识到这只是我的意见.

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

编码约定是:

  • 使代码更具可读性的准则(用于标识的空格量、变量命名等)
  • 绝不会限制您的编码
  • 每种语言都不同

简而言之,这只是一种建议的编码方式,您不需要遵循,但如果您这样做,对其他人来说更具可读性.

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.

这篇关于为什么是“带破折号的小写"?HTML 类的标准?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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