83
Views
14
Comments
CSS Opacity Problem
Question
Application Type
Reactive
Service Studio Version
11.54.46 (Build 63163)
Platform Version
11.26.0 (Build 41987)

this may be simple problem for you but it takes me whole day to try different approach to this problem-- the problem is when im trying to change the opacity of the container all the object and element changes the opacity i just want the container to be opacity changed., is there a way or any different approach to this problem?

2024-12-10 04-40-04
Gitansh Anand

Hi, @budang haba, Just create a new class, set the opacity in that class, and then apply the new class only to the container for which you want to set the opacity. If required, you might need to set CSS Specificity. Please read this article for a better understanding of specificity.

If your issue is that when you set the opacity on main container, the contents inside that container also change, in that case you can try to set background color to you main container in RGBA instead of opacity.

Thanks
Gitansh Anand

UserImage.jpg
budang haba

IVE actually tried it but did not work for me though, rgb didnt too bcause im using a picture

2024-12-10 04-40-04
Gitansh Anand

@budang habaThen try to do this: using Specificity, set opacity only on the image tag with a custom class; it will work.

I am attaching an OML; check the CSS and widget tree.

Opacity.oml
2023-02-26 23-17-33
Kshitij Raheja
UserImage.jpg
budang haba

still the same problem same elements get changed the opacity too

2024-12-10 04-40-04
Gitansh Anand

Hi, @budang haba, I looked at your OML, but it is very confusing. From what I could understand, you want to keep the opacity of your image at 0.5 initially, and when you hover on the image, the opacity should be 1. If I am correct, please refer to the updated OML; if not, please specify exactly what you want to achieve.

Thanks
Gitansh Anand 

Testings.oml
UserImage.jpg
Mafalda Oliveira

Hi! 

When you change the opacity of a container in CSS the opacity property in CSS is inherited by all child elements. Here are two things you can try if you want to change the opacity of the container itself without affecting the child elements:

1. Using RGBA for the background color

2. Using a pseudo-element for background with the ::before or ::after selectors that covers the entire container, and applying the oppacity to this element.

UserImage.jpg
budang haba

thanks for the recommendation tried it but doesnt work to me.

2023-02-19 05-11-08
Faais

Hi @budang haba could you please share the OML or URL?

UserImage.jpg
budang haba

Here it is sir

Testings.oml
2023-02-19 05-11-08
Faais



Instead of you giving the opacity property to that container, you can apply the background-color property using rgba, which includes opacity 


For example,
background-color: rgba(240, 240, 240, 0.2); 





You can adjust the highlighted value from the above image for opacity. 

UserImage.jpg
budang haba

sorry for the confusion sir, i dont use the background color in a reason of im using photo i just want the background image photo to be opacity changed without affecting the image in the center

2023-02-19 05-11-08
Faais



Does this container need to have opacity?

UserImage.jpg
budang haba

yes that waht im experimenting sir

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.