ID和类名的命名
名称应与意义相关而不是表现。
比如,某些元素你希望他们显示为红色,然后分配类名red。
不要这样做。应该根据“它们是什么”来为元素命名,而不是根据“它们的外观如何”来命名。
有意义的类名的优点是可以在整个网站中重用它们。
| 不好的命名 | 好的命名 |
|---|---|
| red | error |
| leftColumn | esecondaryContent |
| topNav | emainNav |
| firstPara | intro |
(一个疑问:是用驼峰命名法还是用hyphens来连接单词?比如main-nav。精通CSS中是用了hyphens的方式。)
命名规范:
http://www.w3.org/TR/html401/types.html#type-cdata中的规范规定是如下:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

浙公网安备 33010602011771号