Skip to content

Instantly share code, notes, and snippets.

@emirikol
Created January 6, 2014 09:41
Show Gist options
  • Select an option

  • Save emirikol/8280403 to your computer and use it in GitHub Desktop.

Select an option

Save emirikol/8280403 to your computer and use it in GitHub Desktop.

Revisions

  1. emirikol created this gist Jan 6, 2014.
    5 changes: 5 additions & 0 deletions choose_text_color.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    def back_and_fore_color(color)
    rgb = color.sub('#','').scan(/../).map {|c| c.to_i(16)}
    fore_color = rgb.sum > 384 ? 'black' : 'white'
    "background-color:#{color};color:#{fore_color};"
    end