9

How to make semi-transparent background using css in element? but the content in not transparent too? sorry for bad english. Thank you.

Reporter
  • 3,897
  • 5
  • 33
  • 47
Agi Maulana
  • 497
  • 1
  • 6
  • 16

1 Answers1

18

use rgba background.

background: rgba(0, 0, 0, 0.5);

values are in order red intensity, green intensity, blue intensity

the decimal value is the opacity, and it runs from 0 to 1.

if you need to customize it without too many difficulties, check out: css3 maker

Morrisda
  • 1,380
  • 1
  • 11
  • 25
  • 1
    If the element you're talking about isn't the `body` of the document, you can also use `opacity:(decimal from 0 to 1)` – cbr Sep 03 '13 at 14:22
  • @jCuber: If it doesn't contain anything other than the image, you mean. If you set `opacity: 50%` on a container, though, it fades out all of the element's contents as well. – cHao Sep 03 '13 at 14:26
  • @cHao Ah, good point. Anyways, the opacity attribute is also useful in cases :) – cbr Sep 03 '13 at 14:28
  • @jCuber: That it is. Even in this case, you could probably have a `:before` pseudo-element absolutely positioned and z-indexed, and set *its* opacity rather than the container's. But that is probably overthinking things. :P – cHao Sep 03 '13 at 14:37