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

后端 未结 7 1334
南笙
南笙 2020-12-11 02:38

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?

相关标签:
7条回答
  • 2020-12-11 02:52

    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.

    0 讨论(0)
  • 2020-12-11 02:53

    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

    0 讨论(0)
  • 2020-12-11 02:54

    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).

    0 讨论(0)
  • 2020-12-11 02:58

    A detailed reading on this from wikipedia

    Web colors

    0 讨论(0)
  • 2020-12-11 03:00

    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.

    0 讨论(0)
  • 2020-12-11 03:06

    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.

    0 讨论(0)
提交回复
热议问题