CSS color names + alpha transparency

Is it possible to determine the color in CSS by its name plus the alpha transparency value?

i.e:.

#mytext { color: red 0.5 } 

instead of resorting to rgba as

 #mytext { color: rgba(255,0,0,0.5) } 
+6
source share
2 answers

You can achieve the desired result:

 #mytext{ color: red; opacity: 0.5; } 

Note that opacity will affect the entire element, not just the text, for example, if the #mytext element had a background color, which will also get an opacity of 0.5

However, I agree with Give, using color names instead of hex or rgb codes is not something you should rely too much on. This is an ugly color palette for work.

+1
source

Not. The CSS specification allows you to specify colors only by name, hexadecimal representation of RGB, or using the functions rgb(r,g,b) and rgba(r,g,b,a) . Each use is mutually exclusive.

Link: http://www.w3.org/TR/CSS2/syndata.html#value-def-color

Color names are now less useful than they were in the days of CSS1.x because named colors (with the exception of orange ) are members of the old "16-color" display palette and usually look ugly today.

If you want to use color names to improve readability, use comments, for example:

 color: rgb(0,0,0); /* black */ 

(put a comment after the decimal point, because many CSS editors only save comments if they are outside the property declarations).

CSS3 adds more named colors, including the 24-bit X11 color set, as well as the hsl(h,s,l) function, but still doesn't allow you to mix named colors and opacity values: http://www.w3.org/TR/ css3-color /

+8
source

All Articles