简体   繁体   English

命名 css 颜色变量的最佳实践

[英]best practice for naming css color variables

It's a basic question but I want to know when defining main colors for an application, should the color classes be named by their color:这是一个基本问题,但我想知道在为应用程序定义主要颜色时,颜色类是否应按颜色命名:

pumpkin-orange , topaz , sky-blue , gray-color pumpkin-orangetopazsky-bluegray-color

Or by their meaning/function :或者通过它们的含义/功能:

main-color , main-color-hover , secondary-color , link-color , disabled-color ... main-color , main-color-hover , secondary-color , link-color , disabled-color ...

You should avoid naming css classes by color.您应该避免按颜色命名 css 类。 Use a functional name instead.改用功能名称。 I will advise you to have a look to BEM naming convention .我建议您查看BEM 命名约定 I think it is a good start to have a structured approach of css.我认为采用结构化的 css 方法是一个好的开始。

Select the names by meaning.按含义选择名称。
Colors could change, bud the meaning stays.颜色会变,花蕾的意思不变。

It would be nice if the community could agree on common names.如果社区能够就通用名称达成一致,那就太好了。 That way, you could use third-party code and their design would already be harmonised.这样,您就可以使用第三方代码,并且它们的设计已经协调一致。

Here is an attempt:这是一个尝试:
https://github.com/nuxodin/css-variables-name-conventions https://github.com/nuxodin/css-variables-name-conventions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM