+ 7

how to change opacity of background without affecting the opacity of elements inside it?

I have inserted an image for background but it makes it difficult to read the text. so I want to put a semi-opaque background for that division. But if I change the opacity using css then the button, text, input field, everything inside the 'div' becomes blurry how do i solve this problem?

30th May 2018, 1:44 AM
Code Ninja
Code Ninja - avatar
5 Answers
+ 4
Style the image independently (by wrapping it in it's own div) and apply the opacity property to it, then attempt to overlay your text on the div. https://stackoverflow.com/questions/10422949/css-background-opacity Code Ninja Added the reference ^
30th May 2018, 1:52 AM
Fermi
Fermi - avatar
+ 4
You can use rgba() values (where "a" stands for "alpha") instead of normal hexadecimal code ;) For example: some_element { background: rgba(32, 32, 32, 0.3); /* 0.3 defines low opacity */ color: rgba(225, 255, 255, 1); /* opacity: 1 i.e., opaque white color */ }
31st May 2018, 7:04 AM
777
777 - avatar
+ 3
Rahul thank you, that worked perfectly.
31st May 2018, 9:23 AM
Code Ninja
Code Ninja - avatar
+ 1
Fermi thank you
30th May 2018, 2:41 AM
Code Ninja
Code Ninja - avatar
+ 1
I was looking for this, Thanks
22nd Oct 2019, 8:25 AM
Manash
Manash - avatar