Users can set the background-color of a button through a textbox that accept RGB hexadecimal notation: ff00ff, ccaa22, etc. So I need to set the text color to the opposite. Not sure about the terminology (opposite color) but the idea is assure readability.
Users can set the background-color of a button through a textbox that accept RGB
Share
You can invert the background color and use it as foreground color. The following algorithm produces results identical to the “Image > Adjustments > Invert” color command in Photoshop:
Note that this is not a bullet-proof solution. Colors that are close to 50% brightness and/or saturation will not produce sufficient contrast.
Demo on jsFiddle