Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 839
  • Last Modified:

Set font color based upon background color

I have a table that allows users to set the background of cell to a certain color of their choosing. The problem I have is if they choose a dark color then it is hard to see the text in the cell. Is there a function or css style that I can use to display the text dynamically based upon the background color?
0
dssisupport
Asked:
dssisupport
  • 2
  • 2
2 Solutions
 
Chris StanyonCommented:
Not with just CSS.

How are you offering the user the option of changing the background? Can you not use the same process for setting the foreground colour?
0
 
dssisupportAuthor Commented:
Yes, I could do that. I have a color picker where they select the color and then their color choice is saved into a sql table so I would have to add a field for the font color. I was just thinking there might be a way to do it dynamically.
0
 
Chris StanyonCommented:
You could kind of hack it to do it with CSS along with your database. Instead of storing a background colour in the database, store a class name, and then define your background colour and colour in the CSS. Apply the data-stored class to your elements and the CSS will apply

.black { background-color:black; color:white; }
.white { background-color:white; color:black; }

Just an idea :)
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
I think your easiest is going to be where you have pre set color schemes as already suggested.  If you want to get a bit geekier, then perhaps using Kuler and their api to create on the fly schemes.   http://learn.adobe.com/wiki/display/kulerdev/A.+Kuler+API+Documentation   And even geekier would be implementing a js like http://stackoverflow.com/questions/1664140/js-function-to-calculate-complementary-colour.

I would go for the easy route and make your own color schemes unless you just like good puzzles and have a few days to kill.
0
 
dssisupportAuthor Commented:
Thanks for the suggestions.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now