开发者

It is recommendable to type the color's name instead of its hex value in CSS?

I always forget what colors I'm dealing with in CSS when I see it hex value. I would like to use the name instead (e.g color: lightgreen). Is it开发者_运维技巧 supported by all browsers? (or only the basic 16 colors)?


CSS uses 17 standard colors. These are all safe to use. There are also system colors whose values is system and browser dependent but might be useful for integrating into system defaults but this is deprecated by CSS3 Color (for whatever that is worth).


I'll prefer the hex value since it is supported by all browsers and I can specify wide range of colors than the named colors.


Now every popular browsers support the 17 base colors plus 130 more color name http://www.w3.org/TR/2003/CR-css3-color-20030514/#svg-color and http://www.w3schools.com/css/css_colornames.asp

So not only you can safely use those 17 base colors name but you can also use the 130 SVG 1.0 color keyword names


All colors in rgb.txt are supported by the big browsers, but some may have slightly different definitions. Use the hex code to be safe.


A detailed reading on this from wikipedia

Web colors


Use classes then

<style>.lightorange {color: #FE7A15 !important}</style>

<div class="lightorange info"></div>

This has the benefit you can refine your colors just by updating your CSS. Be aware though it isn't a great idea to name a class after how it appears, since you may want to change all your orange text to red and you'll end up with the class .lightorange {color:red} which is just odd.


You could always add comments to your CSS file so instead of:

.my_class {
    color: orange;
}

You could write:

.my_class {
    color: #ffa500; /* Orange */
}

This way you know for sure the colour will be exactly the same in every browser and you see the name as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜