0

Is it possible in CSS to make the background of a text transparent but the text remains the same (non transparent)?

I tried this:

p {
  position: absolute;
  background-color: blue;
  filter: alpha(opacity=60);
  opacity: 0.6;
}

span {
  color: black;
  filter: alpha(opacity=100);
  opacity: 1;
}
<p>
  <span>Earth is a planet</span>
</p>
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Finn Balor
  • 19
  • 4

1 Answers1

0

yes, it is possible and you don't need that extra <span>to get it.

With the rgba notation you can set an alpha value for the background color

HTML

<p>Earth is a planet</p>

CSS

p {
  position: absolute;
  background-color: rgba(0,0,255,0.6); /* r=0 g=0 b=255 alpha=60% */
  color: black;
}
thetont
  • 810
  • 5
  • 10