Languages

CSS - give text or image transparent background

0 points
Asked by:
Saim-Mccullough
688

Is it possible to set the background of an element to partly transparent but have the content (text & images) of the element fully visible?

I was trying opacity: 50% but I don't want the text to be affected by it:

1 answer
0 points
Answered by:
Admin Dirask Community
4380

You can use rgba colors, which works like rgb but the fourth parameter a (alpha) is a number between 0 and 1 (or a percentage value) that sets the opacity. The number 1 corresponds to 100% (full opacity) and 0 makes the element invisible.

Quick solution:

 

Practical example

1. Using HTML style attribute

2. Using CSS

Working with images

Analogically, when you are working with images, you need to set the image container background to rgba color with some opacity.

1. Using HTML style attribute

2. Using CSS

 

References

  1. rgba() - CSS: Cascading Style Sheets | MDN
0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join