CSS Colours
This module defines helpers for dealing with CSS colour strings.
The following constants are available:
- PREDEFINED: Tuple of the predefined colour literals available in most web
browsers
- HEX_MATCHCompiled regular expression for HEX CSS colour values such as
#F1A or #AB4CD9
- RGB_MATCHCompiled regular expression for rgb function calls such as
rgb(0, 12, 255)
- RGBA_MATCH: Compiled regular expression for rgba function calls such as
rgba(0, 12, 255, 0.3)
- HSL_MATCH: Compiled regular expression for hsl function calls such as
hsl(120, 5%, 200%)
- HSLA_MATCH: Compiled regular expression for hsla function calls such as
hsla(120, 5%, 200%, 0.3)
- awl.css_colours.colour_to_rgb(colour)
Takes a web colour name or hex value and returns a tuple containing the corresponding decimal RGB values
- Parameters:
colour – web colour name (e.g. “pink”) or hex colur (e.g. “#f0f”, “#f2d5e3”
- Returns:
tuple with decimal RGB values
- awl.css_colours.colour_to_rgb_string(colour)
Takes a web colour name or hex value and returns an rgb() string that can be used in a CSS file.
- Parameters:
colour – web colour name (e.g. “pink”) or hex colur (e.g. “#f0f”, “#f2d5e3”
- Returns:
CSS rgb() function string (e.g. rgb(102, 51, 153) )
- awl.css_colours.is_colour(value)
Returns True if the value given is a valid CSS colour, i.e. matches one of the regular expressions in the module or is in the list of predetefined values by the browser.