@chriscodesthings/rgba-color-to-css-hex
v1.1.4
Published
Converts an RGB or RGBA color to a CSS hex color code
Downloads
37
Readme
rgba-color-to-css-hex
Converts an RGB or RGBA color to a CSS hex color code
Description
Converts a color given as red, green and blue values to a CSS hex color code.
See...
Install
npm install --save @chriscodesthings/rgba-color-to-css-hex
Usage
import rgbaColorToCSSHex from '@chriscodesthings/rgba-color-to-css-hex';
console.log(rgbaColorToCSSHex([100, 149, 237, 0.5])); // cornflowerblue with 50% transparency
// => #6495ed7f
Types
This package uses types from:
Syntax
rgbaColorToCSSHex([r, g, b, (a)]);
Parameters
- r, g, b: red, green and blue values in the range 0-255
- a (optional): alpha value in the range 0-1
Return Value
Returns a string containing a CSS hex color code converted from the RGBA values.
Examples
// from user input
function setBackground(r, g, b) {
document.body.style.background = rgbaColorToCSSHex([r, g, b]);
}