3

Let's suppose I apply a CSS opacity rule on some HTML element

opacity: .5;

is there a formula that helps me figure out how a color will change ?

For instance I'd guess that in my example a div background color of white #FFFFFF would become #808080

but peraphs I am wrong ?

Zo72
  • 14,593
  • 17
  • 71
  • 103
  • 2
    Surely this would depend on whatever color is displayed behind your div? – Curtis Mar 29 '12 at 11:21
  • Are you assuming that it's black underneath everything? – thirtydot Mar 29 '12 at 11:21
  • @thirtydot Yes, I am assuming that it's either all black or all white. – Zo72 Mar 29 '12 at 11:37
  • @Curt if you have a red div and you apply opacity of 0.5 the question becomes: what is going to be the red div ? surely no longer FF0000 so what number ? thanks – Zo72 Mar 29 '12 at 11:38
  • This is a tricky one and it all depends what you want to do, but there is a way but it is a bucket load of algebra. I would suggest looking at rgba which might solve some off your problems as it includes the alpha transparency in it. – Dominic Green Mar 29 '12 at 11:51
  • 1
    Almost a duplicate of [Convert RGBA color to RGB](http://stackoverflow.com/questions/2049230/convert-rgba-color-to-rgb) except this question 1) uses hex color notation and 2) talks about `opacity` on a solid background color rather than an `rgba()` color. The formula is still applicable, though. – BoltClock Mar 29 '12 at 12:12
  • This won't take you all the way, but it might help a little bit. http://codepen.io/AntonNiklasson/pen/bfDtl – AntonNiklasson Aug 14 '12 at 11:16

1 Answers1

0

If you have a color picker utility, you could try this type of thing with multiple color arrangements, and then use the color picker to see what they come out to be, and see if you can find any relations.

-Brian

OneChillDude
  • 7,856
  • 10
  • 40
  • 79