是否有任何缺点使用颜色名称代替CSS中的颜色代码? [英] Are there any cons to using color names in place of color codes in CSS?

查看:197
本文介绍了是否有任何缺点使用颜色名称代替CSS中的颜色代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,写 red #cc0000 更有效。

使用颜色名称超过十六进制代码或RGB值?

Are there any down sides to using color names over hex codes or RGB values? This includes programming in a multi-developer environment.

推荐答案

不同的浏览器可能不同意某些颜色名称的含义。没有名称为所有1600万24位颜色。事实上,只有17个W3C标准颜色名称。

Different browsers may not agree on what some color names mean. There are not names for all 16 million 24-bit colors. In fact there are only 17 W3C-standard color names. It's probably OK to use those.

我个人在构建时使用模板系统预处理我的CSS文件,这样我可以保留一套标准的网站颜色并通过名称引用它们。这样我得到了两个世界的最好的:我知道我的RGB颜色值是什么,但我可以在CSS中使用更简单的名称。

Personally I use a templating system at build time to pre-process my CSS files, so that I can keep a standard set of site colors and refer to them by name. That way I get the best of both worlds: I know exactly what my RGB color values are, but I can use simpler names in the CSS.

(当然,仍然无法准确地知道在给定用户的浏览器上颜色的外观。)

(Of course, it's still not possible to know exactly how a color will look on a given user's browser.)

编辑—在写这个答案的5年里,像Less和Sass这样的预处理器变得非常普遍。这些提供了一些非常复杂的工具来管理CSS源中的颜色(和许多其他东西)。

edit — in the 5 years since this answer was written, preprocessors like Less and Sass have become pretty common. Those provide some very sophisticated tools for managing colors (and many other things) in CSS sources.

这篇关于是否有任何缺点使用颜色名称代替CSS中的颜色代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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